bayi před 1 rokem
rodič
revize
25e943e67a
4 změnil soubory, kde provedl 441 přidání a 425 odebrání
  1. 1 2
      app.js
  2. 303 291
      components/videoPreview/index.js
  3. 6 1
      components/videoPreview/index.wxml
  4. 131 131
      mixins/share.js

+ 1 - 2
app.js

@@ -27,7 +27,6 @@ App({
             })
         }
         let shareUid = options.query.uid || ''
-        console.log(shareUid, 'shareUid');
         let uid = wx.getStorageSync('uid')
         if (uid) {
             let userInfo = await getMyInfo()
@@ -108,7 +107,7 @@ App({
         // 1047	扫描小程序码	1048长按图片识别小程序码
         if (query.scene && types.includes(scene)) {
             let params = decodeURIComponent(query.scene).split('&')
-            console.log('eee', params, gradeObj[params[2]]);
+            console.log('音箱端参数', params, gradeObj[params[2]]);
             bindDevice({
                 deviceCode: params[0],
                 channelCode: params[1],

+ 303 - 291
components/videoPreview/index.js

@@ -1,316 +1,328 @@
 import {
-  storeBindingsBehavior
+    storeBindingsBehavior
 } from 'mobx-miniprogram-bindings'
 import {
-  store
+    store
 } from '~/store/index'
 import {
-  setVideoStatus,
-  likeVideo,
-  collectVideo,
-  submitPlayLog
+    setVideoStatus,
+    likeVideo,
+    collectVideo,
+    submitPlayLog
 } from '~/api/video'
 import {
-  setFans
+    setFans
 } from '~/api/user'
 import {
-  setDuration
+    setDuration
 } from '~/utils/util'
 Component({
-  behaviors: [storeBindingsBehavior],
-  storeBindings: {
-    store,
-    fields: {
-      pkData: 'pkData',
-    },
-    actions: {
-      setPkData: 'setPkData'
-    }
-  },
-  /**
-   * 组件的属性列表
-   */
-  properties: {
-    videoInfo: {
-      type: Object,
-      value: {},
-      observer(newVal) {
-        if (newVal.userReadExtend && newVal.userReadExtend.resourcesType == 1) {
-          newVal.userRead.title = newVal.userRead.title.split('\n')
+    behaviors: [storeBindingsBehavior],
+    storeBindings: {
+        store,
+        fields: {
+            pkData: 'pkData',
+        },
+        actions: {
+            setPkData: 'setPkData'
         }
-        this.setData({
-          videoInfoCopy: newVal,
-          videoPath: newVal.userRead.videoPath,
-          selfWork: this.data.selfUid == newVal.user.uid,
-          isOfficial: newVal.userRead.type != 'APP_EXAMPLE'
-        })
-      }
-    },
-    videoType: {
-      type: String,
-      // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,
-      value: 'public',
-    },
-    currentId: {
-      type: Number
-    },
-    sliderValue: {
-      type: Number,
-      value: 0,
-    },
-    currentTime: {
-      type: String,
-      value: '00:00',
-    }
-  },
-  data: {
-    selfUid: wx.getStorageSync('uid'),
-    videoInfoCopy: {},
-    videoPath: '',
-    //userRead.videoPath 和 example.videoPath,
-    workType: 'videoPath',
-    // 是否官方作品
-    isOfficial: false,
-    // 是否作者本人
-    selfWork: false
-  },
-  lifetimes: {
-    attached() {
-      let {
-        userReadExtend,
-        userRead
-      } = this.data.videoInfoCopy
-      if (userReadExtend && userReadExtend.resourcesType == 1) {
-        this.setData({
-          endTime: setDuration(userRead.duration)
-        })
-      }
-    }
-  },
-  methods: {
-    // 播放视频
-    playVideo() {
-      this.triggerEvent('playVideo', this.data.videoInfoCopy.userRead.id)
-      this.submitPlayLog(this.data.videoInfoCopy.userRead.id)
     },
-    // 设置进度条
-    slider({
-      detail
-    }) {
-      this.triggerEvent('setSeek', detail.value / 100 * this.data.videoInfoCopy.userRead.duration)
+    /**
+     * 组件的属性列表
+     */
+    properties: {
+        videoInfo: {
+            type: Object,
+            value: {},
+            observer(newVal) {
+                if (newVal.userReadExtend && newVal.userReadExtend.resourcesType == 1) {
+                    newVal.userRead.title = newVal.userRead.title.split('\n')
+                }
+                this.setData({
+                    videoInfoCopy: newVal,
+                    videoPath: newVal.userRead.videoPath,
+                    selfWork: this.data.selfUid == newVal.user.uid,
+                    isOfficial: newVal.userRead.type != 'APP_EXAMPLE'
+                })
+            }
+        },
+        videoType: {
+            type: String,
+            // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,
+            value: 'public',
+        },
+        currentId: {
+            type: Number
+        },
+        sliderValue: {
+            type: Number,
+            value: 0,
+        },
+        currentTime: {
+            type: String,
+            value: '00:00',
+        }
     },
-    // 设置视频公开还是隐私
-    async setVideoPublic() {
-      let info = this.data.videoInfoCopy.userRead
-      let data = {
-        id: info.id,
-        status: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
-      }
-      let res = await setVideoStatus(data)
-      if (res.status == 'DISABLE') {
-        wx.showToast({
-          title: '该作品仅自己可见',
-          icon: 'none',
-          duration: 2000
-        })
-      }
-      this.setData({
-        ['videoInfoCopy.userRead.status']: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
-      })
+    data: {
+        selfUid: wx.getStorageSync('uid'),
+        videoInfoCopy: {},
+        videoPath: '',
+        //userRead.videoPath 和 example.videoPath,
+        workType: 'videoPath',
+        // 是否官方作品
+        isOfficial: false,
+        // 是否作者本人
+        selfWork: false,
+        // 是否显示真实分享按钮
+        shareBtn: true
     },
-    // 点赞
-    async likeVideo() {
-      let {
-        id
-      } = this.data.videoInfoCopy.userRead
-      if (this.data.videoInfoCopy.isLike) {
-        return
-      }
-      await likeVideo(id)
-      this.setData({
-        ['videoInfoCopy.isLike']: true,
-        ['videoInfoCopy.userRead.likeAmount']: this.data.videoInfoCopy.userRead.likeAmount + 1
-      })
+    lifetimes: {
+        attached() {
+            let {
+                userReadExtend,
+                userRead
+            } = this.data.videoInfoCopy
+            if (userReadExtend && userReadExtend.resourcesType == 1) {
+                this.setData({
+                    endTime: setDuration(userRead.duration)
+                })
+            }
+        }
     },
-    // 下载视频
-    download() {
-      wx.showLoading({
-        title: '保存到本地',
-        mask: true
-      })
-      const url = this.data.videoInfoCopy.userRead.markPath || ''
-      wx.downloadFile({
-        url,
-        success(res) {
-          if (res.statusCode === 200) {
-            wx.saveVideoToPhotosAlbum({
-              filePath: res.tempFilePath,
-              success(res) {
-                wx.hideLoading()
-                wx.showToast({
-                  title: '成功保存到相册!',
-                  duration: 3000,
-                  icon: 'success',
-                  mask: true
+    methods: {
+        shareVideo() {
+            this.setData({
+                shareBtn: false
+            })
+            setTimeout(() => {
+                this.setData({
+                    shareBtn: true
                 })
-              },
-              fail() {
-                wx.hideLoading()
+            }, 1500)
+        },
+        // 播放视频
+        playVideo() {
+            this.triggerEvent('playVideo', this.data.videoInfoCopy.userRead.id)
+            this.submitPlayLog(this.data.videoInfoCopy.userRead.id)
+        },
+        // 设置进度条
+        slider({
+            detail
+        }) {
+            this.triggerEvent('setSeek', detail.value / 100 * this.data.videoInfoCopy.userRead.duration)
+        },
+        // 设置视频公开还是隐私
+        async setVideoPublic() {
+            let info = this.data.videoInfoCopy.userRead
+            let data = {
+                id: info.id,
+                status: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
+            }
+            let res = await setVideoStatus(data)
+            if (res.status == 'DISABLE') {
                 wx.showToast({
-                  title: '网络不给力',
-                  icon: 'error',
-                  duration: 3000,
-                  mask: true
+                    title: '该作品仅自己可见',
+                    icon: 'none',
+                    duration: 2000
                 })
-              }
+            }
+            this.setData({
+                ['videoInfoCopy.userRead.status']: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
             })
-          }
         },
-        fail() {
-          wx.hideLoading()
-          wx.showToast({
-            title: '网络不给力',
-            icon: 'error',
-            duration: 3000,
-            mask: true
-          })
-        }
-      })
-    },
-    //评论
-    openComment() {
-      this.triggerEvent('openComment')
-      this.setData({
-        ['videoInfoCopy.unReadPostsCount']: 0,
-      })
-    },
-    // 删除
-    delete() {
-      let {
-        id
-      } = this.data.videoInfoCopy.userRead
-      wx.showModal({
-        title: '确认删除吗?',
-        content: '作品将被永久删除,无法找回。',
-        confirmText: '确认',
-        cancelText: '取消',
-        success: async (res) => {
-          if (res.confirm) {
-            let data = {
-              id,
-              status: 'DEL'
+        // 点赞
+        async likeVideo() {
+            let {
+                id
+            } = this.data.videoInfoCopy.userRead
+            if (this.data.videoInfoCopy.isLike) {
+                return
             }
-            await setVideoStatus(data)
-            wx.showToast({
-              title: '删除成功!',
-              icon: "none"
+            await likeVideo(id)
+            this.setData({
+                ['videoInfoCopy.isLike']: true,
+                ['videoInfoCopy.userRead.likeAmount']: this.data.videoInfoCopy.userRead.likeAmount + 1
             })
-            this.triggerEvent('deleteVideo', this.data.videoInfoCopy.userRead.id)
-          }
-        }
-      })
-    },
-    // 收藏课程
-    async collect() {
-      let {
-        id,
-        type,
-        uid
-      } = this.data.videoInfoCopy.userRead
-      if (wx.getStorageSync('uid') == uid) {
-        return wx.showToast({
-          title: '不能收藏自己作品哦!',
-          icon: "none"
-        })
-      }
-      await collectVideo({
-        targetCode: id,
-        favoritesType: type
-      })
-      this.setData({
-        ['videoInfoCopy.isFavorites']: !this.data.videoInfoCopy.isFavorites
-      })
-    },
-    // 关注
-    async setFans() {
-      if (this.data.videoInfoCopy.isFans) {
-        return
-      }
-      await setFans({
-        uid: this.data.videoInfoCopy.user.uid
-      })
-      this.triggerEvent('setListFans', this.data.videoInfoCopy.user.uid)
-    },
-    jumpUserInfo() {
-      wx.navigateTo({
-        url: `/pages/personal/index?uid=${this.data.videoInfoCopy.user.uid}&type=user`,
-      })
-    },
-    // 控制音频播放
-    audioPlay() {
-      this.triggerEvent('playAudio')
-      this.submitPlayLog(this.data.videoInfoCopy.userRead.id)
-    },
-    toPkPage() {
-      let videoInfo = this.data.videoInfoCopy
-      if (this.properties.videoType == 'pk') {
-        if (videoInfo.user.uid == wx.getStorageSync('uid')) {
-          return wx.showToast({
-            title: '不能与自己PK哦~',
-            icon: 'none'
-          })
-        }
-        this.setPkData({
-          nickName: videoInfo.user.nickName || videoInfo.user.eid,
-          uid: videoInfo.user.uid,
-          avatar: videoInfo.user.avatar,
-          score: videoInfo.userRead.score,
-          audioPath: videoInfo.userRead.audioPath,
-          exampleId: videoInfo.userRead.exampleId,
-          id: videoInfo.userRead.id
-        })
-      }
-      let readId = videoInfo.userRead.id
-      let videoType = this.properties.videoType
-      let url = ''
-      if (!this.data.isOfficial || this.data.selfWork) {
-        // autoPlay自动播放
-        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&autoPlay=true`
-      } else if (videoType == 'public' || videoType == 'follow') {
-        url = `/pages/pkPage/index?videoId=${readId}`
-      } else if (videoType == 'pk') {
-        // voluntarily自动录制
-        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=${videoType}&voluntarily=true`
-      } else {
-        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}`
-      }
-      wx.navigateTo({
-        url
-      })
-    },
-    // pkPage页面示范朗读
-    changeRead() {
-      this.setData({
-        workType: this.data.workType == 'videoPath' ? 'example' : 'videoPath',
-      })
-      if (this.data.videoInfo.userReadExtend.resourcesType == 1) {
-        this.triggerEvent('pkPageAudio', {
-          currentTarget: {
-            dataset: {
-              id: this.data.videoInfoCopy.userRead.id,
-              audio: this.data.workType == 'videoPath' ? this.data.videoInfoCopy.userRead.audioPath : this.data.videoInfoCopy.example.audioPath,
-              isPkPage: true
+        },
+        // 下载视频
+        download() {
+            wx.showLoading({
+                title: '保存到本地',
+                mask: true
+            })
+            const url = this.data.videoInfoCopy.userRead.markPath || ''
+            wx.downloadFile({
+                url,
+                success(res) {
+                    if (res.statusCode === 200) {
+                        wx.saveVideoToPhotosAlbum({
+                            filePath: res.tempFilePath,
+                            success(res) {
+                                wx.hideLoading()
+                                wx.showToast({
+                                    title: '成功保存到相册!',
+                                    duration: 3000,
+                                    icon: 'success',
+                                    mask: true
+                                })
+                            },
+                            fail() {
+                                wx.hideLoading()
+                                wx.showToast({
+                                    title: '网络不给力',
+                                    icon: 'error',
+                                    duration: 3000,
+                                    mask: true
+                                })
+                            }
+                        })
+                    }
+                },
+                fail() {
+                    wx.hideLoading()
+                    wx.showToast({
+                        title: '网络不给力',
+                        icon: 'error',
+                        duration: 3000,
+                        mask: true
+                    })
+                }
+            })
+        },
+        //评论
+        openComment() {
+            this.triggerEvent('openComment')
+            this.setData({
+                ['videoInfoCopy.unReadPostsCount']: 0,
+            })
+        },
+        // 删除
+        delete() {
+            let {
+                id
+            } = this.data.videoInfoCopy.userRead
+            wx.showModal({
+                title: '确认删除吗?',
+                content: '作品将被永久删除,无法找回。',
+                confirmText: '确认',
+                cancelText: '取消',
+                success: async (res) => {
+                    if (res.confirm) {
+                        let data = {
+                            id,
+                            status: 'DEL'
+                        }
+                        await setVideoStatus(data)
+                        wx.showToast({
+                            title: '删除成功!',
+                            icon: "none"
+                        })
+                        this.triggerEvent('deleteVideo', this.data.videoInfoCopy.userRead.id)
+                    }
+                }
+            })
+        },
+        // 收藏课程
+        async collect() {
+            let {
+                id,
+                type,
+                uid
+            } = this.data.videoInfoCopy.userRead
+            if (wx.getStorageSync('uid') == uid) {
+                return wx.showToast({
+                    title: '不能收藏自己作品哦!',
+                    icon: "none"
+                })
             }
-          }
-        })
-      }
-    },
-    // 统计作品播放次数
-    async submitPlayLog(userReadId) {
-      await submitPlayLog({
-        userReadId,
-        playStopTime: 1000
-      })
-    },
-  }
+            await collectVideo({
+                targetCode: id,
+                favoritesType: type
+            })
+            this.setData({
+                ['videoInfoCopy.isFavorites']: !this.data.videoInfoCopy.isFavorites
+            })
+        },
+        // 关注
+        async setFans() {
+            if (this.data.videoInfoCopy.isFans) {
+                return
+            }
+            await setFans({
+                uid: this.data.videoInfoCopy.user.uid
+            })
+            this.triggerEvent('setListFans', this.data.videoInfoCopy.user.uid)
+        },
+        jumpUserInfo() {
+            wx.navigateTo({
+                url: `/pages/personal/index?uid=${this.data.videoInfoCopy.user.uid}&type=user`,
+            })
+        },
+        // 控制音频播放
+        audioPlay() {
+            this.triggerEvent('playAudio')
+            this.submitPlayLog(this.data.videoInfoCopy.userRead.id)
+        },
+        toPkPage() {
+            let videoInfo = this.data.videoInfoCopy
+            if (this.properties.videoType == 'pk') {
+                if (videoInfo.user.uid == wx.getStorageSync('uid')) {
+                    return wx.showToast({
+                        title: '不能与自己PK哦~',
+                        icon: 'none'
+                    })
+                }
+                this.setPkData({
+                    nickName: videoInfo.user.nickName || videoInfo.user.eid,
+                    uid: videoInfo.user.uid,
+                    avatar: videoInfo.user.avatar,
+                    score: videoInfo.userRead.score,
+                    audioPath: videoInfo.userRead.audioPath,
+                    exampleId: videoInfo.userRead.exampleId,
+                    id: videoInfo.userRead.id
+                })
+            }
+            let readId = videoInfo.userRead.id
+            let videoType = this.properties.videoType
+            let url = ''
+            if (!this.data.isOfficial || this.data.selfWork) {
+                // autoPlay自动播放
+                url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&autoPlay=true`
+            } else if (videoType == 'public' || videoType == 'follow') {
+                url = `/pages/pkPage/index?videoId=${readId}`
+            } else if (videoType == 'pk') {
+                // voluntarily自动录制
+                url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=${videoType}&voluntarily=true`
+            } else {
+                url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}`
+            }
+            wx.navigateTo({
+                url
+            })
+        },
+        // pkPage页面示范朗读
+        changeRead() {
+            this.setData({
+                workType: this.data.workType == 'videoPath' ? 'example' : 'videoPath',
+            })
+            if (this.data.videoInfo.userReadExtend.resourcesType == 1) {
+                this.triggerEvent('pkPageAudio', {
+                    currentTarget: {
+                        dataset: {
+                            id: this.data.videoInfoCopy.userRead.id,
+                            audio: this.data.workType == 'videoPath' ? this.data.videoInfoCopy.userRead.audioPath : this.data.videoInfoCopy.example.audioPath,
+                            isPkPage: true
+                        }
+                    }
+                })
+            }
+        },
+        // 统计作品播放次数
+        async submitPlayLog(userReadId) {
+            await submitPlayLog({
+                userReadId,
+                playStopTime: 1000
+            })
+        },
+    }
 })

+ 6 - 1
components/videoPreview/index.wxml

@@ -97,10 +97,15 @@
         </view>
     </view>
     <view class="workFooter" wx:if="{{videoInfoCopy.userRead.status!='CHECK'}}">
-        <button class="resetBtn mangeL-box" open-type="share" data-info='{{videoInfo}}'>
+        <button class="resetBtn mangeL-box" open-type="share" data-info='{{videoInfo}}' bindtap="shareVideo"
+            wx:if="{{shareBtn}}">
             <image src="/static/share.png" mode="" class="icon" />
             <view class="icon-name">分享</view>
         </button>
+        <view class="resetBtn mangeL-box" wx:else>
+            <image src="/static/share.png" mode="" class="icon" />
+            <view class="icon-name">分享</view>
+        </view>
         <view class="mangeL-box" bindtap="collect">
             <image src="{{videoInfoCopy.isFavorites ? '/static/star_colored.png' : '/static/star.png'}}" mode=""
                 class="icon" />

+ 131 - 131
mixins/share.js

@@ -1,137 +1,137 @@
 import {
-  isActivityWork
+    isActivityWork
 } from '~/api/works'
 module.exports = Behavior({
-  data: {},
-  methods: {
-    onShareAppMessage({
-      from,
-      target
-    }) {
-      if (from == 'button') {
-        let video = target.dataset.info
-        const promise = new Promise(resolve => {
-          this.creatShare(video).then(res => {
-            resolve(res)
-          })
-        })
-        return {
-          title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
-          path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
-          imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg',
-          promise
-        }
-      } else {
-        return {
-          title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
-          path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
-          imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
-        }
-      }
-    },
-    creatShare(video) {
-      return new Promise(async (resolve, reject) => {
-        let isActivity = await isActivityWork(video.userRead.id)
-        let context = wx.createSelectorQuery(video.id);
-        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.userReadExtend && video.userReadExtend.resourcesType == 1 ? video.userReadExtend.backgroundVirtualImg : 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 fx = canvas.createImage();
-                fx.src = '/static/share.png'
-                fx.onload = () => {
-                  ctx.drawImage(fx, 12, 220, 20, 20)
-                  ctx.fillText('分享', 36, 238)
-                  // 收藏,一个一个渲染
-                  let sc = canvas.createImage();
-                  sc.src = '/static/no_collect.png'
-                  sc.onload = () => {
-                    ctx.drawImage(sc, 110, 220, 19, 19)
-                    ctx.fillText('收藏', 134, 238)
-                    // 评论
-                    let pl = canvas.createImage();
-                    pl.src = '/static/comment.png'
-                    pl.onload = () => {
-                      ctx.drawImage(pl, 228, 222, 22, 22)
-                      ctx.fillText(video.userRead.commentAmount || 0, 340, 238)
-                      //点赞
-                      let dz = canvas.createImage();
-                      dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
-                      dz.onload = () => {
-                        ctx.drawImage(dz, 318, 222, 22, 22)
-                        ctx.fillText(video.userRead.likeAmount || 0, 254, 238)
-                        if (video.userReadExtend.resourcesType == 1) {
-                          let aBg = canvas.createImage();
-                          aBg.src = '/static/shareAudioBg.png';
-                          aBg.onload = () => {
-                            ctx.drawImage(aBg, 127.5, 38, 120, 120);
-                            let rate = 0.5
-                            ctx.arc(
-                              Math.floor(375 * rate),
-                              98,
-                              Math.floor(100 * rate),
-                              0,
-                              2 * Math.PI
-                            );
-                            ctx.clip() //裁剪
-                            let coverImg = canvas.createImage();
-                            coverImg.src = video.userRead.coverImg;
-                            coverImg.onload = () => {
-                              ctx.drawImage( //定位在圆圈范围内便会出现
-                                coverImg, //图片暂存路径
-                                129, 42,
-                                110, 110,
-                              );
-                              ctx.restore()
-                            }
-                          }
-                        }
-                        setTimeout(() => {
-                          wx.canvasToTempFilePath({
-                            canvas: canvas,
-                            success(res) {
-                              let path = video.user.profession == '官方' ? '/pages/reading/index' : '/pages/pkPage/index'
-                              let title = wx.getStorageSync('uid') == video.user.uid ? '我的新作品发布啦,快来捧场点赞!' : video.userRead.type == 'READ' ? '发现一篇宝藏作品,这声音让人爱了!不信你不着迷!' : '我正在听这篇朗读示范,这发音,播音专业水准!你也来听听!'
-                              if(isActivity){
-                                title='点赞、评论、转发三件套,数据今天就过万!'
-                              }
-                              resolve({
-                                title,
-                                path: `${path}?videoId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}&isShare=true`,
-                                imageUrl: res.tempFilePath
-                              })
-                            },
-                            fail(res) {
-                              reject()
-                            }
-                          }, this)
-                        }, 500)
-                      }
-                    }
-                  }
+    data: {},
+    methods: {
+        onShareAppMessage({
+            from,
+            target
+        }) {
+            if (from == 'button') {
+                let video = target.dataset.info
+                const promise = new Promise(resolve => {
+                    this.creatShare(video).then(res => {
+                        resolve(res)
+                    })
+                })
+                return {
+                    title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
+                    path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
+                    imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg',
+                    promise
+                }
+            } else {
+                return {
+                    title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
+                    path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
+                    imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/375-300-1.jpg'
                 }
-              }
             }
-          })
-      })
-    },
-  }
+        },
+        creatShare(video) {
+            return new Promise(async (resolve, reject) => {
+                let isActivity = await isActivityWork(video.userRead.id)
+                let context = wx.createSelectorQuery(video.id);
+                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.userReadExtend && video.userReadExtend.resourcesType == 1 ? video.userReadExtend.backgroundVirtualImg : 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 fx = canvas.createImage();
+                                fx.src = '/static/share.png'
+                                fx.onload = () => {
+                                    ctx.drawImage(fx, 12, 220, 20, 20)
+                                    ctx.fillText('分享', 36, 238)
+                                    // 收藏,一个一个渲染
+                                    let sc = canvas.createImage();
+                                    sc.src = '/static/no_collect.png'
+                                    sc.onload = () => {
+                                        ctx.drawImage(sc, 110, 220, 19, 19)
+                                        ctx.fillText('收藏', 134, 238)
+                                        // 评论
+                                        let pl = canvas.createImage();
+                                        pl.src = '/static/comment.png'
+                                        pl.onload = () => {
+                                            ctx.drawImage(pl, 228, 222, 22, 22)
+                                            ctx.fillText(video.userRead.commentAmount || 0, 340, 238)
+                                            //点赞
+                                            let dz = canvas.createImage();
+                                            dz.src = video.isLike ? '/static/heart_colored.png' : '/static/heart.png'
+                                            dz.onload = () => {
+                                                ctx.drawImage(dz, 318, 222, 22, 22)
+                                                ctx.fillText(video.userRead.likeAmount || 0, 254, 238)
+                                                if (video.userReadExtend.resourcesType == 1) {
+                                                    let aBg = canvas.createImage();
+                                                    aBg.src = '/static/shareAudioBg.png';
+                                                    aBg.onload = () => {
+                                                        ctx.drawImage(aBg, 127.5, 38, 120, 120);
+                                                        let rate = 0.5
+                                                        ctx.arc(
+                                                            Math.floor(375 * rate),
+                                                            98,
+                                                            Math.floor(100 * rate),
+                                                            0,
+                                                            2 * Math.PI
+                                                        );
+                                                        ctx.clip() //裁剪
+                                                        let coverImg = canvas.createImage();
+                                                        coverImg.src = video.userRead.coverImg;
+                                                        coverImg.onload = () => {
+                                                            ctx.drawImage( //定位在圆圈范围内便会出现
+                                                                coverImg, //图片暂存路径
+                                                                129, 42,
+                                                                110, 110,
+                                                            );
+                                                            ctx.restore()
+                                                        }
+                                                    }
+                                                }
+                                                setTimeout(() => {
+                                                    wx.canvasToTempFilePath({
+                                                        canvas: canvas,
+                                                        success(res) {
+                                                            let path = video.user.profession == '官方' ? '/pages/reading/index' : '/pages/pkPage/index'
+                                                            let title = wx.getStorageSync('uid') == video.user.uid ? '我的新作品发布啦,快来捧场点赞!' : video.userRead.type == 'READ' ? '发现一篇宝藏作品,这声音让人爱了!不信你不着迷!' : '我正在听这篇朗读示范,这发音,播音专业水准!你也来听听!'
+                                                            if (isActivity) {
+                                                                title = '点赞、评论、转发三件套,数据今天就过万!'
+                                                            }
+                                                            resolve({
+                                                                title,
+                                                                path: `${path}?videoId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}&isShare=true`,
+                                                                imageUrl: res.tempFilePath
+                                                            })
+                                                        },
+                                                        fail(res) {
+                                                            reject()
+                                                        }
+                                                    }, this)
+                                                }, 500)
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    })
+            })
+        },
+    }
 })