Silent před 7 roky
rodič
revize
34f17b2198
2 změnil soubory, kde provedl 20 přidání a 11 odebrání
  1. 19 10
      wechat/pages/index/index.js
  2. 1 1
      wechat/pages/index/index.wxml

+ 19 - 10
wechat/pages/index/index.js

xqd xqd xqd xqd
@@ -15,6 +15,8 @@ Page({
     clock: '00:00:00', //计时
     shareCanvasWidth: 280,
     shareCanvasHeight: 375,
+    imageWidth: 280,
+    imageHeight: 375,
     shareImage: '',
     shareText: '',
     shareTextPosX: '',
@@ -112,6 +114,8 @@ Page({
           this.setData({
             // shareCanvasWidth: res.data.width,
             // shareCanvasHeight: res.data.height,
+            imageWidth: res.data.width,
+            imageHeight: res.data.height,
             shareImage: res.data.shareImage,
             shareText: res.data.shareText,
             shareTextPosX: res.data.shareTextPosX,
@@ -296,15 +300,20 @@ Page({
                 // let text_y = this.data.shareTextPosY
                 // ctx.fillStyle = "#fff"
                 // ctx.fillRect(0, 0, width, height)
+                // ctx.drawImage(image, 0, 0, 280, 375)
                 ctx.drawImage(image, 0, 0, 280, 375)
                 // ctx.fillStyle = "#fff"
                 // ctx.setFontSize(18)
                 // ctx.textAlign = 'center'
                 // ctx.fillText('我已成功打卡14天', width / 2, height / 2 - 7)
                 // ctx.fillText(text, text_x, text_y)
-                ctx.draw(false, this.getTempFilePath)
+                ctx.draw(false)
+                // var ctx_save = wx.createCanvasContext('saveCanvas')
+                // ctx_save.drawImage(image, 0, 0, width, height)
+                // ctx_save.draw(false, this.getTempFilePath)
                 this.setData({
-                  shareImage: res.tempFilePath
+                  shareImage: res.tempFilePath,
+                  shareTempFilePath: res.tempFilePath
                 })
               }
             })
@@ -320,14 +329,14 @@ Page({
     });
   },
   getTempFilePath: function () {
-    wx.canvasToTempFilePath({
-      canvasId: 'shareCanvas',
-      success: (res) => {
-        this.setData({
-          shareTempFilePath: res.tempFilePath
-        })
-      }
-    })
+    // wx.canvasToTempFilePath({
+    //   canvasId: 'shareCanvas',
+    //   success: (res) => {
+    //     this.setData({
+    //       shareTempFilePath: res.tempFilePath
+    //     })
+    //   }
+    // })
   },
   handleShare() {
     // wx.canvasToTempFilePath({

+ 1 - 1
wechat/pages/index/index.wxml

xqd
@@ -42,7 +42,7 @@
       <view class='hide-popup-btn' bindtap='hidePhotoPopup'>
         <icon type='cancel' color='white'></icon>
       </view>
-      <canvas canvas-id="shareCanvas" style="width: {{shareCanvasWidth}}px; height:{{shareCanvasHeight}}px">
+      <canvas canvas-id="shareCanvas" id='shareCanvas' style='width: {{shareCanvasWidth}}px; height: {{shareCanvasHeight}}px'>
       </canvas>
     </view>
     <button class="share-btn" bindtap="handleShare" type='primary'>生成图片发到朋友圈</button>