Limengbo 6 years ago
parent
commit
65a6e7d72b

+ 4 - 0
compontents/chat/chat.js

@@ -37,6 +37,10 @@ Component({
     more: {
       type: String,
       value: ''
+    },
+    ind: {
+      type: String,
+      value: ''
     }
   },
 

+ 55 - 42
compontents/share/share.js

@@ -1,4 +1,5 @@
 // compontents/share/share.js
+const APIClient = require('../../utils/APIClient.js');
 Component({
   /**
    * 组件的属性列表
@@ -17,7 +18,8 @@ Component({
     imgUrl: [],
     featureMap: {},
     title: '',
-    ratio: ''
+    ratio: '',
+    codeImage: ''
   },
 
   /**
@@ -43,6 +45,21 @@ Component({
     },
     //保存图片 
     saveImage (e) {
+      const postsId = this.data.postId;
+      APIClient.getqrCode({
+        postsId,
+        ind: '7'
+      }).success((res) => {
+        console.log(res.data.data)
+        wx.downloadFile({
+          url: res.data.data,
+          success: (res) => {
+            this.setData({
+              codeImage: res.tempFilePath
+            })
+          }
+        })
+      })
       const imgUrl = this.data.imgUrl;
       const ratio = this.data.ratio;
       const featureMap = this.data.featureMap;
@@ -53,48 +70,44 @@ Component({
       const imgHeight = windowWidth*ratio;
       //先绘制图片
       for (let item of imgUrl) {
-        // wx.downloadFile({
-        //   url: item,
-        //   success: function (res) {
-        //     console.log(res);
-        //   }
-        // })
-        //canvas绘制文字和图片
-        const ctx = wx.createCanvasContext('myCanvas');
-        var imgPath = item;
-        ctx.setFillStyle('white')
-        ctx.fillRect(0, 0, windowWidth, imgHeight + 300)
-        //绘制用户上传的图片
-        ctx.drawImage(imgPath, 0, 0, windowWidth, imgHeight);
-        //绘制用户发表的内容和名字
-        ctx.setFontSize(16)
-        ctx.setFillStyle('black')
-        ctx.fillText(title, 135, imgHeight + 55)
-        ctx.setFontSize(18)
-        ctx.fillText(featureMap.wechatName, 135, imgHeight + 35);
-        //横线
-        ctx.moveTo(20, imgHeight + 140)
-        ctx.lineTo(windowWidth - 40, imgHeight + 140)
-        ctx.stroke()
-        //绘制用户头像圆形切割-开始
-        ctx.save();
-        ctx.beginPath();
-        ctx.arc(70, imgHeight + 70, 50, 0, Math.PI * 2, false);
-        ctx.fill();
-        ctx.clip();
-        //圆形切割-结束
-        ctx.drawImage(featureMap.headImgUrl, 20, imgHeight + 20, 100, 100);
-        ctx.restore();
-        //二维码和文字
-        ctx.setFontSize(16)
-        ctx.setFillStyle('black')
-        ctx.fillText('长按二维码', 50, imgHeight + 180)
-        ctx.fillText('进入小程序查看更多', 50, imgHeight + 210)
-        ctx.draw()
+        wx.downloadFile({
+          url: item,
+          success: (res) => {
+            console.log(res.tempFilePath);
+            const codeImage = this.data.codeImage;
+            //canvas绘制文字和图片
+            const ctx = wx.createCanvasContext('myCanvas');
+            var imgPath = res.tempFilePath;
+            ctx.setFillStyle('white')
+            ctx.fillRect(0, 0, windowWidth, imgHeight + 300)
+            //绘制用户上传的图片
+            ctx.drawImage(imgPath, 0, 0, windowWidth, imgHeight);
+            //绘制用户发表的内容和名字
+            ctx.setFontSize(18)
+            ctx.setFillStyle('black')
+            ctx.fillText(title, 25, imgHeight + 90)
+            ctx.setFontSize(12)
+            ctx.fillText('在勋章战士上学会了这些,分享给大家', 25, imgHeight + 60)
+            ctx.setFontSize(22)
+            ctx.fillText(featureMap.wechatName, 25, imgHeight + 35);
+            //横线
+            ctx.moveTo(20, imgHeight + 140)
+            ctx.lineTo(windowWidth - 40, imgHeight + 140)
+            ctx.stroke()
+            //二维码和文字
+            ctx.drawImage(codeImage, 20, imgHeight + 150, 100, 100);
+            ctx.setFontSize(16)
+            ctx.setFillStyle('black')
+            ctx.fillText('长按二维码', 150, imgHeight + 180)
+            ctx.fillText('进入小程序查看更多', 150, imgHeight + 210)
+            ctx.draw()
+            setTimeout(() => {
+              this.canvasToImage()
+            }, 500)
+          }
+        })
       }
-      setTimeout(() => {
-        this.canvasToImage()
-      }, 200)
+     
     },
     canvasToImage () {
         let that = this;

+ 1 - 0
pages/art/art.js

@@ -227,6 +227,7 @@ Page({
       // 来自页面内转发按钮
       console.log(ops.target)
     }
+    debugger;
     const postId = ops.target.dataset.postid;
     return {
       title: '小学王者班',

+ 1 - 0
pages/art/art.wxml

@@ -18,6 +18,7 @@
             height="{{previewHeight}}"/>
 
             <chat id="upload"
+                ind="7"
                 id="chat"
                 productionData="{{productionData}}" 
                 title="作品展示"

+ 1 - 1
pages/art/art.wxss

@@ -310,7 +310,7 @@
 /*canvas样式*/
 .canvas-box {
     position: absolute;
-    left: 0;
+    left: 9999px;
     top: 0;
     width: 100%;
     z-index: -2;

+ 21 - 0
pages/index/index.js

@@ -233,4 +233,25 @@ Page({
       }
     });
   },
+    /* 转发*/
+  onShareAppMessage: function (ops) {
+    if (ops.from === 'button') {
+      // 来自页面内转发按钮
+      console.log(ops.target)
+    }
+    debugger;
+    const postId = ops.target.dataset.postid;
+    return {
+      title: '小学王者班',
+      path: `pages/transmit/transmit?ind=7&postId=${postId}`,
+      success: function (res) {
+        // 转发成功
+        console.log("转发成功:" + JSON.stringify(res));
+      },
+      fail: function (res) {
+        // 转发失败
+        console.log("转发失败:" + JSON.stringify(res));
+      }
+    }
+  }
 })

+ 1 - 1
pages/index/index.wxss

@@ -232,7 +232,7 @@
 
 .canvas-box {
     position: absolute;
-    left: 0;
+    left: 999px;
     top: 0;
     width: 100%;
     z-index: -2;

+ 1 - 1
pages/science/science.wxss

@@ -310,7 +310,7 @@
 
 .canvas-box {
     position: absolute;
-    left: 0;
+    left: 9999px;
     top: 0;
     width: 100%;
     z-index: -2;

+ 2 - 0
pages/transmit/transmit.js

@@ -80,6 +80,7 @@ Page({
    */
   onLoad: function (options) {
     const postsId = options.postId || '';
+    const shareKey = options.shareKey || '';
     //判断分享过来的参数是否有postId查询单挑显示
     
     if(postsId) {
@@ -88,6 +89,7 @@ Page({
           uid: res.data.data.uid
         }, {
           postsId, 
+          shareKey
         }).success(res => {
           console.log(res.data)
           if(res.data.success) {