Browse Source

fengxiang

邹能昇 2 months ago
parent
commit
f43079cc7e
1 changed files with 85 additions and 77 deletions
  1. 85 77
      nova-werun/pages/home/share/index.js

+ 85 - 77
nova-werun/pages/home/share/index.js

@@ -30,7 +30,7 @@ Page({
 
         uptokenURL: '',
         domain: '',
-        uploadURL:''
+        uploadURL: ''
 
     },
 
@@ -194,18 +194,26 @@ Page({
         // console.log(width, height);
         canvas.width = this.rpxToPx(670);
         canvas.height = this.rpxToPx(1100);
+        const backgroundImage2 = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/bt19fm050427168.png');
 
+        // 绘制背景图片
+        canvas.drawImage(backgroundImage2, 0, 0, width, height);
+        // 加载背景图片
+        const backgroundImage1 = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1r3o3q045323287.png');
+
+        // 绘制背景图片
+        canvas.drawImage(backgroundImage1, 0, 0, width, height);
         // 绘制背景
-        canvas.setFillStyle('#CAE1FD'); // 背景色
-        canvas.fillRect(0, 0, width, height);
+        // canvas.setFillStyle('#CAE1FD'); // 背景色
+        // canvas.fillRect(0, 0, width, height);
         canvas.setFillStyle('#0178EE');
-        let mainimage = await this.getImageInfo(this.data.randomImage)
+        // let mainimage = await this.getImageInfo(this.data.randomImage)
         let avatar = Parse.User.current()?.get('avatar')
         console.log('avatar', avatar);
         let userAvatar = await this.getImageInfo(avatar)
         console.log('userAvatar', userAvatar);
         //主图片
-        canvas.drawImage(mainimage, 0, 0, width, this.rpxToPx(500)); // 调整图片高度
+        // canvas.drawImage(mainimage, 0, 0, width, this.rpxToPx(500)); // 调整图片高度
         //头像
         if (userAvatar) {
             // 绘制带圆角的头像
@@ -257,25 +265,26 @@ Page({
         // console.log('汗水加载成功');
 
         // 绘制排名、步数和公里数
-        canvas.setFontSize(this.rpxToPx(28));
+        canvas.setFontSize(this.rpxToPx(22));
         // canvas.fillText('今日排名: ' + rank, 20, 400);
         canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
         // console.log('排名加载成功');
         // canvas.fillText('今日步数: ' + steps, 20, 420);
-        canvas.fillText('今日步数', this.rpxToPx(240), this.rpxToPx(840));
+        canvas.fillText('今日步数', this.rpxToPx(180), this.rpxToPx(840));
         // console.log('步数加载成功');
         // canvas.fillText('公里数: ' + distance + 'km', 20, 430);
-        canvas.fillText('公里数', this.rpxToPx(440), this.rpxToPx(840));
+        canvas.fillText('公里数', this.rpxToPx(320), this.rpxToPx(840));
         // console.log('公里数加载成功');
-        canvas.setFontSize(this.rpxToPx(40));
-        canvas.fillText(rank, this.rpxToPx(80), this.rpxToPx(900));
-        canvas.fillText(steps, this.rpxToPx(240), this.rpxToPx(900));
-        canvas.fillText(distance + 'km', this.rpxToPx(444), this.rpxToPx(900));
+        canvas.setFontSize(this.rpxToPx(34));
+        canvas.fillText(rank, this.rpxToPx(70), this.rpxToPx(900));
+        canvas.fillText(steps, this.rpxToPx(180), this.rpxToPx(900));
+        canvas.fillText(distance + 'km', this.rpxToPx(320), this.rpxToPx(900));
 
-        // 绘制二维码(如果有)
-        canvas.setFillStyle('#0178EE'); // 示例二维码
-        canvas.fillRect(width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120)); // QR 位置
-        // console.log('二维码绘制');
+        // 加载二维码图片
+        const qrCodeImage = await this.getImageInfo('https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/t2vst6051431547.png');
+
+        // 绘制二维码
+        canvas.drawImage(qrCodeImage, width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120));
 
         canvas.setFillStyle('#0178EE');
         canvas.setFontSize(this.rpxToPx(28));
@@ -305,7 +314,7 @@ Page({
     uploadImageToServer() {
         const that = this;
         const tempFilePath = this.data.saveimage; // 获取本地临时文件路径
-    
+
         qiniuUploader.upload(
             tempFilePath, // 本地文件路径
             (res) => {
@@ -317,15 +326,14 @@ Page({
             },
             (error) => {
                 console.error('上传失败:', error);
-            },
-            {
+            }, {
                 region: "SCN", // 七牛云区域
                 uploadURL: that.data.uploadURL, // 上传地址
                 domain: that.data.domain, // 域名
                 uptoken: that.data.uptokenURL, // 上传凭证
             }
         );
-        console.log('saveimage',this.data.saveimage);
+        console.log('saveimage', this.data.saveimage);
     },
     async getUptoken() {
         let res = await Parse.Cloud.run('qiniu_uptoken', {
@@ -500,65 +508,65 @@ Page({
     savepic2: function () {
         let that = this;
         wx.canvasToTempFilePath({
-          x: 0,
-          y: 0,
-          width: 670,
-          height: 1100,
-          destWidth: 670,
-          destHeight: 1100,
-          canvasId: 'myCanvas',
-          success: function (result) {
-            wx.getSetting({
-              success(res) {
-                if (!res.authSetting['scope.writePhotosAlbum']) {
-                  wx.authorize({
-                    scope: 'scope.writePhotosAlbum',
-                    success() {
-                      //这里是用户同意授权后的回调
-                      // that.saveImgToLocal();
-                      wx.saveImageToPhotosAlbum({
-                        filePath: result.tempFilePath,
-                        success(res) {
-                            wx.showToast({
-                                title: '图片已保存到相册',
-                                icon: 'success'
-                            });
-                        }
-                      })
-                    },
-                    fail() { //这里是用户拒绝授权后的回调
-                      wx.showToast({
-                        title: '打开相册授权,才能保存图片哦~',
-                        icon: 'none',
-                        duration: 2000
-                      })
-                      that.setData({
-                        openSettingBtnHidden: false
-                      })
-                    }
-                  })
-                } else {
-                  //调取小程序当中获取图片
-                  console.log(result.tempFilePath);
-                  wx.saveImageToPhotosAlbum({
-                    filePath: result.tempFilePath,
+            x: 0,
+            y: 0,
+            width: 670,
+            height: 1100,
+            destWidth: 670,
+            destHeight: 1100,
+            canvasId: 'myCanvas',
+            success: function (result) {
+                wx.getSetting({
                     success(res) {
-                        wx.showToast({
-                            title: '图片已保存到相册',
-                            icon: 'success'
-                        });
+                        if (!res.authSetting['scope.writePhotosAlbum']) {
+                            wx.authorize({
+                                scope: 'scope.writePhotosAlbum',
+                                success() {
+                                    //这里是用户同意授权后的回调
+                                    // that.saveImgToLocal();
+                                    wx.saveImageToPhotosAlbum({
+                                        filePath: result.tempFilePath,
+                                        success(res) {
+                                            wx.showToast({
+                                                title: '图片已保存到相册',
+                                                icon: 'success'
+                                            });
+                                        }
+                                    })
+                                },
+                                fail() { //这里是用户拒绝授权后的回调
+                                    wx.showToast({
+                                        title: '打开相册授权,才能保存图片哦~',
+                                        icon: 'none',
+                                        duration: 2000
+                                    })
+                                    that.setData({
+                                        openSettingBtnHidden: false
+                                    })
+                                }
+                            })
+                        } else {
+                            //调取小程序当中获取图片
+                            console.log(result.tempFilePath);
+                            wx.saveImageToPhotosAlbum({
+                                filePath: result.tempFilePath,
+                                success(res) {
+                                    wx.showToast({
+                                        title: '图片已保存到相册',
+                                        icon: 'success'
+                                    });
+                                }
+                            })
+                        }
                     }
-                  })
-                }
-              }
-            })
-    
-          },
-          fail: function (res) {
-            console.log(res)
-          }
+                })
+
+            },
+            fail: function (res) {
+                console.log(res)
+            }
         })
-      },
+    },
     shar() {
         wx.downloadFile({
             url: this.data.saveimage, //图片服务器地址
@@ -578,7 +586,7 @@ Page({
         });
     },
     sharecircle() {
-        console.log('this.data.saveimage',this.data.saveimage);
+        console.log('this.data.saveimage', this.data.saveimage);
         wx.navigateTo({
             url: '../../circle/send-circle/index?image=' + this.data.saveimage // 目标页面的路径
         });