bayi 1 vuosi sitten
vanhempi
commit
6a56e8e1b2
3 muutettua tiedostoa jossa 79 lisäystä ja 16 poistoa
  1. 67 15
      mixins/share.js
  2. 7 1
      pages/works/index.less
  3. 5 0
      pages/works/index.wxss

+ 67 - 15
mixins/share.js

@@ -9,7 +9,6 @@ module.exports = Behavior({
             from,
             target
         }) {
-            console.log('顶顶顶顶顶');
             if (from == 'button') {
                 let video = target.dataset.info
                 const promise = new Promise(resolve => {
@@ -31,23 +30,55 @@ module.exports = Behavior({
                 }
             }
         },
-        // elif ANDROID
+        // 大佬,我又来了,wx.miniapp.shareMiniProgramMessage支持fail打印报错,但是不支持promise,onShareAppMessage支持promise,但是不抛出报错,不好调试
+        // 
+        // #elif ANDROID
         onShareAppMessage({
             from,
             target
         }) {
-            console.log('灌灌灌灌灌');
+            /*       wx.miniapp.shareMiniProgramMessage({
+                      title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
+                      userName: 'gh_50f61361ad1d',
+                      path: 'pages/index/index',
+                      imagePath: '/static/uploadTips.png',
+                      webpageUrl: 'http://www.efunbox.cn',
+                      withShareTicket: true,
+                      miniprogramType: 1,
+                      scene: 0,
+                      success(res) {
+                          wx.showToast({
+                              title: '成功:分享小程序',
+                          })
+                          console.log(res)
+                      },
+                      fail() {
+                          wx.showToast({
+                              title: '失败:分享小程序',
+                          })
+                      }
+                  }) */
             if (from == 'button') {
+                let video = target.dataset.info
+                const promise = new Promise(resolve => {
+                    this.creatShare(video).then(res => {
+                        console.log(res, 'rrr');
+                        resolve(res)
+                    })
+                })
                 return {
-                    title: "你干啥啊",
+                    title: '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
                     userName: 'gh_50f61361ad1d',
                     path: 'pages/index/index',
-                    imagePath: '/pages/thumb.png',
-                    webpageUrl: 'www.qq.com',
+                    imagePath: '/static/uploadTips.png',
+                    webpageUrl: 'http://www.efunbox.cn',
                     withShareTicket: true,
-                    miniprogramType: 0,
+                    miniprogramType: 1,
                     scene: 0,
+                    promise
                 }
+            } else {
+                console.log('暂不处理');
             }
         },
         // #endif
@@ -63,25 +94,24 @@ module.exports = Behavior({
                     }).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);
+                        // const dpr = wx.getSystemInfoSync().pixelRatio;
+                        canvas.width = 300;
+                        canvas.height = 240;
                         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);
+                            ctx.drawImage(pic, 0, 0, 300, 169);
                             let peiyin = canvas.createImage();
                             peiyin.src = '/static/peiyin.jpg';
                             peiyin.onload = () => {
-                                ctx.drawImage(peiyin, 0, 211, 375, 89);
+                                ctx.drawImage(peiyin, 0, 169, 300, 71.2);
                                 //分享
                                 let fx = canvas.createImage();
                                 fx.src = '/static/share.png'
                                 fx.onload = () => {
-                                    ctx.drawImage(fx, 12, 220, 20, 20)
-                                    ctx.fillText('分享', 36, 238)
+                                    ctx.drawImage(fx, 9.6, 176, 16, 16)
+                                    ctx.fillText('分享', 28.8, 190)
                                     // 收藏,一个一个渲染
                                     let sc = canvas.createImage();
                                     sc.src = '/static/no_collect.png'
@@ -135,11 +165,33 @@ module.exports = Behavior({
                                                             if (isActivity) {
                                                                 title = '点赞、评论、转发三件套,数据今天就过万!'
                                                             }
+                                                            // #if MP
                                                             resolve({
                                                                 title,
                                                                 path: `${path}?videoId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}&isShare=true`,
                                                                 imageUrl: res.tempFilePath
                                                             })
+                                                            // #elif ANDROID
+                                                            wx.saveImageToPhotosAlbum({
+                                                                filePath: res.tempFilePath,
+                                                                success() {
+                                                                    wx.showToast({
+                                                                        title: '保存成功',
+                                                                        icon: 'none'
+                                                                    })
+                                                                }
+                                                            })
+                                                            resolve({
+                                                                title,
+                                                                userName: 'gh_50f61361ad1d',
+                                                                path: `${path}?videoId=${video.userRead.id}&uid=${wx.getStorageSync('uid')}&isShare=true`,
+                                                                imagePath: res.tempFilePath,
+                                                                webpageUrl: 'http://www.efunbox.cn',
+                                                                withShareTicket: true,
+                                                                miniprogramType: 1,
+                                                                scene: 0,
+                                                            })
+                                                            // #endif
                                                         },
                                                         fail(res) {
                                                             reject()

+ 7 - 1
pages/works/index.less

@@ -36,7 +36,7 @@
         justify-content: center;
         font-size: 36rpx;
         color: #000000;
-    /*     .icon {
+        /*     .icon {
             width: 50rpx;
             height: 50rpx;
             margin-right: 12rpx;
@@ -47,4 +47,10 @@
         margin: 0 auto;
         width: 750rpx;
     }
+}
+
+#share {
+    top: 0;
+    left: 0;
+    background-color: skyblue;
 }

+ 5 - 0
pages/works/index.wxss

@@ -41,3 +41,8 @@
   margin: 0 auto;
   width: 750rpx;
 }
+#share {
+  top: 0;
+  left: 0;
+  background-color: skyblue;
+}