Parcourir la source

开发生成海报并保存到相册

bayi il y a 1 an
Parent
commit
253ae42f52

+ 22 - 6
components/createPoster/index.js

@@ -1,7 +1,7 @@
 Component({
     properties: {},
     data: {
-        state: true,
+        state: false,
         img: ''
     },
     methods: {
@@ -17,28 +17,44 @@ Component({
         },
         savePoster() {
             const query = wx.createSelectorQuery().in(this);
+            let canvas
             query
                 .select('#cavansId')
                 .fields({
                     node: true,
                     size: true
                 }).exec(async (res) => {
-                    const canvas = res[0].node;
+                    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;
+                    canvas.width = 646;
+                    canvas.height = 959;
                     let pic = canvas.createImage();
                     pic.src = 'https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg'
                     pic.onload = () => {
                         ctx.drawImage(pic, 0, 0, 646, 959);
                         let pl = canvas.createImage();
                         pl.src = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEs8TwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyZzR0ZTE2T2M5N1UxYURaYU5CY1QAAgSHoQplAwQgHAAA'
-                        pl.onload = () => {
-                            ctx.drawImage(pl, 25, 747, 173, 173)
+                        pl.onload = async () => {
+                            ctx.drawImage(pl, 29, 756, 170, 170)
+                            let {
+                                tempFilePath
+                            } = await wx.canvasToTempFilePath({
+                                canvas
+                            })
+                            wx.saveImageToPhotosAlbum({
+                                filePath: tempFilePath,
+                                success() {
+                                    wx.showToast({
+                                        title: '保存成功',
+                                        icon: 'none'
+                                    })
+                                }
+                            })
                         }
                     }
                 })
+
         }
     }
 })

+ 2 - 4
components/createPoster/index.less

@@ -62,10 +62,8 @@
         width: 646rpx;
         height: 959rpx;
         position: absolute;
-        left: 10rpx;
-        top: 10rpx;
-        /* left: -9999rpx;
-        top: -9999rpx; */
+        left: -9999rpx;
+        top: -9999rpx;
     }
 }
 

+ 2 - 3
components/createPoster/index.wxml

@@ -1,8 +1,8 @@
 <view class="mediaBox" wx:if="{{state}}">
-    <!-- <view class="poster">
+    <view class="poster">
         <image src="/static/lollipop.png" class="close" catchtap="closeMediaBox" />
         <image src="https://reader-wx.ai160.com/images/reader/pay/shareBg.jpg" class="img" />
-    </view> -->
+    </view>
     <view class="btns">
         <view class="btn">立即分享</view>
         <view class="btn" bindtap="savePoster" style="background: linear-gradient(180deg, #FFB382 0%, #FFA45D 100%);">
@@ -10,5 +10,4 @@
         </view>
     </view>
     <canvas class="canvas" type="2d" id="cavansId" />
-
 </view>

+ 2 - 4
components/createPoster/index.wxss

@@ -55,10 +55,8 @@
   width: 646rpx;
   height: 959rpx;
   position: absolute;
-  left: 10rpx;
-  top: 10rpx;
-  /* left: -9999rpx;
-        top: -9999rpx; */
+  left: -9999rpx;
+  top: -9999rpx;
 }
 /* 转圈动画 */
 @keyframes falsh-identifier {

+ 1 - 1
salesperson/pages/lxDetail/index.js

@@ -26,7 +26,7 @@ Page({
     },
     async onShow() {
         let allIncome = await getSaleData()
-        let data = await getIncomeList({pageSize:1000})
+        let data = await getIncomeList({pageSize:1000,type:this.data.currentIndex})
         console.log(allIncome,data);
         this.setData({
             allIncome,