Browse Source

测试修改

bayi 2 years ago
parent
commit
97d7869e59
4 changed files with 334 additions and 334 deletions
  1. 0 1
      components/videoPreview/index.js
  2. 77 75
      components/worksList/index.js
  3. 128 132
      mixins/video.js
  4. 129 126
      pages/index/index.js

+ 0 - 1
components/videoPreview/index.js

@@ -34,7 +34,6 @@ Component({
             observer(newVal) {
                 if (newVal.userReadExtend && newVal.userReadExtend.resourcesType == 1) {
                     newVal.userRead.title = newVal.userRead.title.split('\n')
-                    console.log(newVal);
                 }
                 this.setData({
                     videoInfoCopy: newVal

+ 77 - 75
components/worksList/index.js

@@ -1,85 +1,87 @@
 import behavior from '~/mixins/video'
 let _observer
 Component({
-  behaviors: [behavior],
-  properties: {
-    worksList: {
-      type: Array,
-      value: [],
-      observer(newVal) {
-        this.setData({
-          worksListCopy: newVal
-        })
-        if (this.properties.autoPlay) {
-          // 自动播放
-          this._observer = this.createIntersectionObserver({
-            observeAll: true
-          })
-          this._observer.relativeTo('.playLine')
-            .observe('.videoPreview', (res) => {
-              let intersectionRatio = res.intersectionRatio
-              if (intersectionRatio > 0) {
-                if (res.dataset.type == 0) {
-                  this.setData({
-                    currentId: res.dataset.id
-                  })
-                } else {
-                  this.playAudio({
-                    currentTarget: {
-                      dataset: res.dataset
-                    }
-                  })
+    behaviors: [behavior],
+    properties: {
+        worksList: {
+            type: Array,
+            value: [],
+            observer(newVal) {
+                this.setData({
+                    worksListCopy: newVal
+                })
+                if (this.properties.autoPlay) {
+                    // 自动播放
+                    this._observer = this.createIntersectionObserver({
+                        observeAll: true
+                    })
+                    this._observer.relativeTo('.playLine')
+                        .observe('.videoPreview', (res) => {
+                            let intersectionRatio = res.intersectionRatio
+                            if (intersectionRatio > 0) {
+                                if (res.dataset.type == 0) {
+                                    console.log(res);
+                                    this.resetAudio();
+                                    this.setData({
+                                        currentId: res.dataset.id
+                                    })
+                                } else {
+                                    this.playAudio({
+                                        currentTarget: {
+                                            dataset: res.dataset
+                                        }
+                                    })
+                                }
+                            }
+                        })
                 }
-              }
-            })
+            }
+        },
+        // 是否自动播放
+        autoPlay: {
+            type: Boolean,
+            value: true
+        },
+        videoType: {
+            type: String,
+            // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,excellent优秀作品展播
+            value: 'public'
+        },
+        // 是否在tabbar页面使用
+        tabBarPadding: {
+            type: Boolean,
+            value: false
         }
-      }
-    },
-    // 是否自动播放
-    autoPlay: {
-      type: Boolean,
-      value: true
     },
-    videoType: {
-      type: String,
-      // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,excellent优秀作品展播
-      value: 'public'
+    data: {
+        worksListCopy: {}
     },
-    // 是否在tabbar页面使用
-    tabBarPadding: {
-      type: Boolean,
-      value: false
-    }
-  },
-  data: {
-    worksListCopy: {}
-  },
-  methods: {
-    setListFans({
-      detail
-    }) {
-      let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
-      worksListCopy.forEach(item => {
-        if (item.user.uid == detail) {
-          item.isFans = true
+    methods: {
+        setListFans({
+            detail
+        }) {
+            let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
+            worksListCopy.forEach(item => {
+                if (item.user.uid == detail) {
+                    item.isFans = true
+                }
+            })
+            this.setData({
+                worksListCopy
+            })
+        },
+        addCommentNum({
+            detail
+        }) {
+            let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
+            worksListCopy.forEach(item => {
+                if (item.userRead.id == detail) {
+                    item.userRead.commentAmount = ++item.userRead.commentAmount
+                }
+            })
+            this.setData({
+                worksListCopy
+            })
         }
-      })
-      this.setData({
-        worksListCopy
-      })
     },
-    addCommentNum({
-      detail
-    }) {
-      let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
-      worksListCopy.forEach(item => {
-        if (item.userRead.id == detail) {
-          item.userRead.commentAmount = ++item.userRead.commentAmount
-        }
-      })
-      this.setData({
-        worksListCopy
-      })
-    }
-  },
 })

+ 128 - 132
mixins/video.js

@@ -1,138 +1,134 @@
 module.exports = Behavior({
-  data: {
-    currentId: '',
-  },
-  properties: {},
-  pageLifetimes: {
-    hide() {
-      this.resetAudio()
+    data: {
+        currentId: '',
     },
-  },
-  methods: {
-    // 开始播放
-    playVideo({
-      currentTarget
-    }) {
-      this.setData({
-        currentId: currentTarget.dataset.id
-      })
+    properties: {},
+    pageLifetimes: {
+        hide() {
+            this.resetAudio()
+        },
     },
-    // 播放音频
-    playAudio({
-      currentTarget
-    }) {
-      if (this.data.currentId == currentTarget.dataset.id) {
-        return this.innerAudioContext.stop();
-      }
-      if (this.innerAudioContext) {
-        this.innerAudioContext.stop();
-      } else {
-        this.innerAudioContext = wx.createInnerAudioContext()
-        this.innerAudioContext.onEnded(res => {
-          this.setData({
-            currentId: ''
-          })
-        })
-        this.innerAudioContext.onStop((res) => {
-          this.setData({
-            currentId: ''
-          })
-        });
-      }
-      this.innerAudioContext.src = currentTarget.dataset.audio
-      this.innerAudioContext.play();
-      this.setData({
-        currentId: currentTarget.dataset.id
-      })
-    },
-    // 重置音频
-    resetAudio() {
-      if (this.innerAudioContext) {
-        this.innerAudioContext.stop();
-      }
-      this.setData({
-        currentId: ''
-      })
-    },
-    // 打开评论
-    openComment({
-      target
-    }) {
-      this.selectComponent('#comment').open(target.dataset.id)
-    },
-    // 分享
-    creatShare(video) {
-      console.log(video);
-      return new Promise((resolve, reject) => {
-        let context = wx.createSelectorQuery();
-        context
-          .select('#share')
-          .fields({
-            node: true,
-            size: true
-          }).exec((res) => {
-            const canvas = res[0].node;
-            const ctx = canvas.getContext('2d');
-            const dpr = wx.getSystemInfoSync().pixelRatio;
-            canvas.width = res[0].width * dpr;
-            canvas.height = res[0].height * dpr;
-            ctx.scale(dpr, dpr);
-            ctx.font = '14px PingFang';
-            let pic = canvas.createImage();
-            pic.src = video.userRead.coverImg; //可以是本地,也可以是网络图片
-            pic.onload = () => {
-              ctx.drawImage(pic, 0, 0, 375, 211);
+    methods: {
+        // 开始播放
+        playVideo({
+            currentTarget
+        }) {
+            this.setData({
+                currentId: currentTarget.dataset.id
+            })
+        },
+        // 播放音频
+        playAudio({
+            currentTarget
+        }) {
+            if (this.data.currentId == currentTarget.dataset.id) {
+                console.log('相同');
+                return this.resetAudio()
             }
-            let peiyin = canvas.createImage();
-            peiyin.src = '/static/peiyin.jpg';
-            peiyin.onload = () => {
-              ctx.drawImage(peiyin, 0, 211, 375, 89);
-              // 收藏,一个一个渲染
-              let sc = canvas.createImage();
-              sc.src = '/static/no_collect.png'
-              sc.onload = () => {
-                ctx.drawImage(sc, 12, 220, 20, 20)
-                ctx.fillText('收藏', 36, 238)
-                //分享
-                let fx = canvas.createImage();
-                fx.src = '/static/share.png'
-                fx.onload = () => {
-                  ctx.drawImage(fx, 78, 220, 22, 22)
-                  ctx.fillText('分享', 104, 238)
-                  //点赞
-                  let dz = canvas.createImage();
-                  dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
-                  dz.onload = () => {
-                    ctx.drawImage(dz, 258, 222, 22, 22)
-                    ctx.fillText(video.likes, 284, 238)
-                    //评论
-                    let pl = canvas.createImage();
-                    pl.src = '/static/comment.png'
-                    pl.onload = () => {
-                      ctx.drawImage(pl, 318, 222, 22, 22)
-                      ctx.fillText(video.commentAmount, 340, 238)
-                      setTimeout(() => {
-                        wx.canvasToTempFilePath({
-                          canvas: canvas,
-                          success(res) {
-                            resolve({
-                              title: '请欣赏我的课文朗读作品,点赞+评论。',
-                              path: `/pages/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
-                              imageUrl: res.tempFilePath
-                            })
-                          },
-                          fail(res) {
-                            reject()
-                          }
-                        }, this)
-                      }, 500)
-                    }
-                  }
-                }
-              }
+            if (this.innerAudioContext) {
+                this.resetAudio()
+            } else {
+                this.innerAudioContext = wx.createInnerAudioContext()
+                this.innerAudioContext.onEnded(res => {
+                    this.resetAudio()
+                })
+                /* this.innerAudioContext.onStop((res) => {
+                }); */
             }
-          })
-      })
-    },
-  }
+            this.innerAudioContext.src = currentTarget.dataset.audio
+            this.innerAudioContext.play();
+            this.setData({
+                currentId: currentTarget.dataset.id
+            })
+        },
+        // 重置音频
+        resetAudio() {
+            if (this.innerAudioContext) {
+                this.innerAudioContext.stop();
+            }
+            this.setData({
+                currentId: ''
+            })
+        },
+        // 打开评论
+        openComment({
+            target
+        }) {
+            this.selectComponent('#comment').open(target.dataset.id)
+        },
+        // 分享
+        creatShare(video) {
+            console.log(video);
+            return new Promise((resolve, reject) => {
+                let context = wx.createSelectorQuery();
+                context
+                    .select('#share')
+                    .fields({
+                        node: true,
+                        size: true
+                    }).exec((res) => {
+                        const canvas = res[0].node;
+                        const ctx = canvas.getContext('2d');
+                        const dpr = wx.getSystemInfoSync().pixelRatio;
+                        canvas.width = res[0].width * dpr;
+                        canvas.height = res[0].height * dpr;
+                        ctx.scale(dpr, dpr);
+                        ctx.font = '14px PingFang';
+                        let pic = canvas.createImage();
+                        pic.src = video.userRead.coverImg; //可以是本地,也可以是网络图片
+                        pic.onload = () => {
+                            ctx.drawImage(pic, 0, 0, 375, 211);
+                        }
+                        let peiyin = canvas.createImage();
+                        peiyin.src = '/static/peiyin.jpg';
+                        peiyin.onload = () => {
+                            ctx.drawImage(peiyin, 0, 211, 375, 89);
+                            // 收藏,一个一个渲染
+                            let sc = canvas.createImage();
+                            sc.src = '/static/no_collect.png'
+                            sc.onload = () => {
+                                ctx.drawImage(sc, 12, 220, 20, 20)
+                                ctx.fillText('收藏', 36, 238)
+                                //分享
+                                let fx = canvas.createImage();
+                                fx.src = '/static/share.png'
+                                fx.onload = () => {
+                                    ctx.drawImage(fx, 78, 220, 22, 22)
+                                    ctx.fillText('分享', 104, 238)
+                                    //点赞
+                                    let dz = canvas.createImage();
+                                    dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
+                                    dz.onload = () => {
+                                        ctx.drawImage(dz, 258, 222, 22, 22)
+                                        ctx.fillText(video.likes, 284, 238)
+                                        //评论
+                                        let pl = canvas.createImage();
+                                        pl.src = '/static/comment.png'
+                                        pl.onload = () => {
+                                            ctx.drawImage(pl, 318, 222, 22, 22)
+                                            ctx.fillText(video.commentAmount, 340, 238)
+                                            setTimeout(() => {
+                                                wx.canvasToTempFilePath({
+                                                    canvas: canvas,
+                                                    success(res) {
+                                                        resolve({
+                                                            title: '请欣赏我的课文朗读作品,点赞+评论。',
+                                                            path: `/pages/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
+                                                            imageUrl: res.tempFilePath
+                                                        })
+                                                    },
+                                                    fail(res) {
+                                                        reject()
+                                                    }
+                                                }, this)
+                                            }, 500)
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    })
+            })
+        },
+    }
 })

+ 129 - 126
pages/index/index.js

@@ -1,142 +1,145 @@
 const app = getApp()
 import {
-  getHotrecommendList,
-  getAuthorityList,
-  getCategoryList
+    getHotrecommendList,
+    getAuthorityList,
+    getCategoryList
 } from "~/api/works"
 import reachBottom from '~/mixins/reachBottom'
 import share from '~/mixins/share'
 import {
-  createStoreBindings
+    createStoreBindings
 } from 'mobx-miniprogram-bindings'
 import {
-  store
+    store
 } from '~/store/index'
 Page({
-  behaviors: [reachBottom, share],
-  /**
-   * 页面的初始数据
-   */
-  data: {
-    navBarHeight: app.globalData.navBarHeight,
-    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
-    currentType: '1',
-    // 控制一级分类是否固定
-    isFixed: false,
-    desktopTips: app.globalData.desktopTips,
-    isIOS: app.globalData.isIOS,
-    categoryList: []
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onShow() {
-    if (typeof this.getTabBar === 'function') {
-      this.getTabBar().setData({
-        selected: 1
-      })
-    }
-    this.getLocUserInfo()
-    if (Object.keys(this.data.userInfo).length > 0) {
-      this.resetData()
-    } else {
-      getApp().callBack = (res) => {
+    behaviors: [reachBottom, share],
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        navBarHeight: app.globalData.navBarHeight,
+        background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
+        currentType: '1',
+        // 控制一级分类是否固定
+        isFixed: false,
+        desktopTips: app.globalData.desktopTips,
+        isIOS: app.globalData.isIOS,
+        categoryList: []
+    },
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onShow() {
+        if (typeof this.getTabBar === 'function') {
+            this.getTabBar().setData({
+                selected: 1
+            })
+        }
         this.getLocUserInfo()
-        this.resetData()
-      }
-    }
-    let {
-      desktopTips
-    } = app.globalData
-    if (desktopTips) {
-      setTimeout(() => {
+        if (Object.keys(this.data.userInfo).length > 0) {
+            this.resetData()
+        } else {
+            getApp().callBack = (res) => {
+                this.getLocUserInfo()
+                this.resetData()
+            }
+        }
+        let {
+            desktopTips
+        } = app.globalData
+        if (desktopTips) {
+            setTimeout(() => {
+                this.setData({
+                    desktopTips: false
+                })
+            }, 6000)
+        }
+
+    },
+    onUnload() {
+        this.storeBindings.destroyStoreBindings()
+    },
+    async getLocUserInfo() {
+        this.storeBindings = createStoreBindings(this, {
+            store,
+            fields: {
+                userInfo: 'userInfo'
+            },
+        })
+        this.storeBindings.updateStoreBindings()
+    },
+    loadMore() {
+        if (this.data.currentType == '1') {
+            this.getData(getHotrecommendList, {
+                grade: this.data.userInfo.grade
+            })
+        } else if (this.data.currentType == '2') {
+            this.getData(getAuthorityList, {
+                grade: this.data.userInfo.grade
+            })
+        }
+        this.getCategoryList()
+    },
+    jumpChildClassify({
+        currentTarget
+    }) {
+        let firstInfo = currentTarget.dataset.item
+        let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
+        wx.navigateTo({
+            url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
+        })
+    },
+    jumpSearch() {
+        wx.navigateTo({
+            url: '/pages/childClassify/index?type=search',
+        })
+    },
+    /**
+     * 监听页面滚动事件
+     */
+    onPageScroll(e) {
+        if (e.scrollTop >= 103 && !this.data.isFixed) {
+            this.setData({
+                isFixed: true
+            })
+        } else if (e.scrollTop < 103 && this.data.isFixed) {
+            this.setData({
+                isFixed: false
+            })
+        }
+    },
+    onReachBottom() {
+        this.loadMore()
+    },
+    async getCategoryList() {
+        let grade = this.data.userInfo.grade
+        let categoryList = await getCategoryList({
+            grade
+        })
         this.setData({
-          desktopTips: false
+            categoryList
         })
-      }, 6000)
-    }
+    },
+    selectType({
+        target
+    }) {
+        if (target.dataset.type) {
+            if (target.dataset.type == '3') {
+                this.selectComponent('#worksList').resetAudio()
+            }
+            this.setData({
+                currentType: target.dataset.type
+            })
+            if (target.dataset.type != '3') {
+                this.resetData()
+            }
 
-  },
-  onUnload() {
-    this.storeBindings.destroyStoreBindings()
-  },
-  async getLocUserInfo() {
-    this.storeBindings = createStoreBindings(this, {
-      store,
-      fields: {
-        userInfo: 'userInfo'
-      },
-    })
-    this.storeBindings.updateStoreBindings()
-  },
-  loadMore() {
-    if (this.data.currentType == '1') {
-      this.getData(getHotrecommendList, {
-        grade: this.data.userInfo.grade
-      })
-    } else if (this.data.currentType == '2') {
-      this.getData(getAuthorityList, {
-        grade: this.data.userInfo.grade
-      })
-    }
-    this.getCategoryList()
-  },
-  jumpChildClassify({
-    currentTarget
-  }) {
-    let firstInfo = currentTarget.dataset.item
-    let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
-    wx.navigateTo({
-      url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
-    })
-  },
-  jumpSearch() {
-    wx.navigateTo({
-      url: '/pages/childClassify/index?type=search',
-    })
-  },
-  /**
-   * 监听页面滚动事件
-   */
-  onPageScroll(e) {
-    if (e.scrollTop >= 103 && !this.data.isFixed) {
-      this.setData({
-        isFixed: true
-      })
-    } else if (e.scrollTop < 103 && this.data.isFixed) {
-      this.setData({
-        isFixed: false
-      })
-    }
-  },
-  onReachBottom() {
-    this.loadMore()
-  },
-  async getCategoryList() {
-    let grade = this.data.userInfo.grade
-    let categoryList = await getCategoryList({
-      grade
-    })
-    this.setData({
-      categoryList
-    })
-  },
-  selectType({
-    target
-  }) {
-    if (target.dataset.type) {
-      this.setData({
-        currentType: target.dataset.type
-      })
-      if (target.dataset.type != '3') {
-        this.resetData()
-        this.selectComponent('#worksList').resetAudio()
-      }
+        }
+    },
+    closeDesktop() {
+        this.setData({
+            desktopTips: false
+        })
     }
-  },
-  closeDesktop() {
-    this.setData({
-      desktopTips: false
-    })
-  }
 })