Browse Source

生成卡片保存到相册

bayi 2 years ago
parent
commit
aa9aeed322
3 changed files with 53 additions and 4 deletions
  1. 7 0
      app.wxss
  2. 45 4
      pages/my/index.js
  3. 1 0
      pages/my/index.wxml

+ 7 - 0
app.wxss

@@ -29,6 +29,13 @@ text {
   top: -9999rpx;
   top: -9999rpx;
 }
 }
 
 
+#vip {
+  width: 375px;
+  height: 201px;
+  left: 0px;
+  position: absolute;
+}
+
 .textOver {
 .textOver {
   white-space: nowrap;
   white-space: nowrap;
   overflow: hidden;
   overflow: hidden;

+ 45 - 4
pages/my/index.js

@@ -20,10 +20,10 @@ Page({
     vipTime: '',
     vipTime: '',
     tasks: [],
     tasks: [],
     isIos: app.globalData.isIOS,
     isIos: app.globalData.isIOS,
-    activationModal: true,
-    isPay: true,
-    // activationModal: false,
-    // isPay: false,
+    /*     activationModal: true,
+        isPay: true, */
+    activationModal: false,
+    isPay: false,
     activationRes: {},
     activationRes: {},
     products: []
     products: []
   },
   },
@@ -36,6 +36,7 @@ Page({
       }
       }
     })
     })
     this.getProducts()
     this.getProducts()
+    this.creatShare()
   },
   },
   async onShow() {
   async onShow() {
     if (typeof this.getTabBar === 'function') {
     if (typeof this.getTabBar === 'function') {
@@ -201,6 +202,46 @@ Page({
       })
       })
     }
     }
   },
   },
+  creatShare() {
+    let context = wx.createSelectorQuery();
+    context
+      .select('#vip')
+      .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 = '20px PingFang';
+        let pic = canvas.createImage();
+        pic.src = 'http://reader-wx.ai160.com/images/reader/v3/learn/vip1.png'
+        pic.onload = () => {
+          ctx.drawImage(pic, 0, 0, 375, 201);
+          ctx.fillText('终身使用', 144, 135)
+          // ctx.fillStyle("#39029B");
+          ctx.fillStyle = 'red'
+          console.log(ctx);
+          setTimeout(() => {
+            wx.canvasToTempFilePath({
+              canvas: canvas,
+              success(res) {
+                /*    wx.saveImageToPhotosAlbum({
+                     filePath: res.tempFilePath,
+                     success(res) {}
+                   }) */
+              },
+              fail(res) {
+                console.log('fail', res);
+              }
+            }, this)
+          }, 500)
+        }
+      })
+  },
   // 分享配置
   // 分享配置
   onShareAppMessage: function (res) {
   onShareAppMessage: function (res) {
     return {
     return {

+ 1 - 0
pages/my/index.wxml

@@ -101,4 +101,5 @@
       <image src="/static/lollipop.png" class="close" catchtap="closeModal" />
       <image src="/static/lollipop.png" class="close" catchtap="closeModal" />
     </view>
     </view>
   </view>
   </view>
+  <canvas id='vip' type="2d"> </canvas>
 </view>
 </view>