Przeglądaj źródła

支付宝小程序兼容性修改

ylong 7 miesięcy temu
rodzic
commit
322c5c513a

+ 1 - 0
App.vue

@@ -26,6 +26,7 @@ export default {
 	},
 	onLaunch(options) {
 		console.log(options, "onLaunch系统信息");
+		let that = this;
 		let params = {};
 		if (options.query) {
 			if (options.query.scene) {

+ 1 - 1
pages-mine/pages/customer-service.vue

@@ -8,7 +8,7 @@
 export default {
     data() {
         return {
-            serviceUrl: 'http://xkf.zhimakf.com/s/132094qkhm'
+            serviceUrl: 'https://testweb.shuhi.com/chat.html'
         }
     }
 }

+ 105 - 77
pages-mine/pages/partner/partner-home.vue

@@ -2,7 +2,8 @@
     <view class="partner-home">
         <!-- 头部信息 -->
         <view class="header">
-            <image class="avatar" src="https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/logo.png" mode="aspectFit"></image>
+            <image class="avatar" src="https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/logo.png" mode="aspectFit">
+            </image>
             <view class="header-text">
                 <text class="title">您好,合伙人</text>
                 <text class="subtitle">这里是合伙人数据中心</text>
@@ -63,20 +64,14 @@
             <button class="generate-poster" @click="generatePoster" :loading="loading">生成专属二维码海报</button>
 
             <!-- 添加canvas元素 -->
-            <canvas
-                canvas-id="posterCanvas"
-                style="width: 750px; height: 1334px; position: fixed; left: -9999px"
-            ></canvas>
+            <canvas canvas-id="posterCanvas" id="posterCanvas"
+                style="width: 750px; height: 1334px; position: fixed; left: -9999px"></canvas>
 
             <!-- 添加海报弹窗 -->
             <u-popup v-model="showPoster" mode="center" border-radius="16" :custom-style="posterStyle">
                 <view class="poster-container">
-                    <image
-                        class="poster-image"
-                        :src="posterInfo.tempFilePath || posterInfo.background"
-                        mode="aspectFit"
-                        @longpress="saveImage"
-                    ></image>
+                    <image class="poster-image" :src="posterInfo.tempFilePath || posterInfo.background" mode="aspectFit"
+                        @longpress="saveImage"></image>
                     <view class="poster-tip">长按图片保存至相册分享</view>
                 </view>
             </u-popup>
@@ -176,89 +171,95 @@ export default {
                                             adjustSize(30)
                                         );
                                         ctx.restore();
-                                        ctx.draw(true);
-                                    },
-                                });
 
-                                // 绘制微信昵称
-                                ctx.setFontSize(adjustSize(14));
-                                ctx.setFillStyle("#333333");
-
-                                let nickName = userInfo.nickName || "书嗨";
-                                let canvasStr = `${nickName}邀请你加入`;
-
-                                let firstLine = canvasStr.slice(0, 16);
-                                let secondLine = canvasStr.slice(16);
-
-                                ctx.fillText(firstLine, adjustX(data.nickNamePosX), adjustY(data.nickNamePosY + 12));
-                                ctx.fillText(secondLine, adjustX(data.nickNamePosX), adjustY(data.nickNamePosY + 30));
-
-                                // 绘制二维码
-                                ctx.save(); // Save the current canvas state
-                                ctx.beginPath();
-                                // Create a circular clipping path for QR code
-                                ctx.arc(
-                                    adjustX(data.qrCodePosX + data.qrCodeWidth / 2),
-                                    adjustY(data.qrCodePosY + data.qrCodeHeight / 2),
-                                    adjustSize(data.qrCodeWidth / 2),
-                                    0,
-                                    2 * Math.PI
-                                );
-                                ctx.clip(); // Apply the clipping path
-                                ctx.drawImage(
-                                    qrRes.tempFilePath,
-                                    adjustX(data.qrCodePosX),
-                                    adjustY(data.qrCodePosY),
-                                    adjustSize(data.qrCodeWidth),
-                                    adjustSize(data.qrCodeHeight)
-                                );
-                                ctx.restore(); // Restore the canvas state
-
-                                // 执行绘制
-                                ctx.draw(false, () => {
-                                    setTimeout(() => {
-                                        // 将画布内容保存为图片
-                                        uni.canvasToTempFilePath({
-                                            canvasId: "posterCanvas",
-                                            width: canvasWidth,
-                                            height: canvasHeight,
-                                            destWidth: canvasWidth * dpr,
-                                            destHeight: canvasHeight * dpr,
-                                            quality: 1,
-                                            success: (res) => {
-                                                this.loading = false;
-                                                this.showPoster = true;
-                                                this.posterInfo.tempFilePath = res.tempFilePath;
-                                            },
-                                            fail: (err) => {
-                                                console.error("生成图片失败:", err);
-                                                uni.showToast({
-                                                    title: "海报生成失败",
-                                                    icon: "none",
+                                        // 绘制微信昵称
+                                        ctx.setFontSize(adjustSize(14));
+                                        ctx.setFillStyle("#333333");
+
+                                        let nickName = userInfo.nickName || "书嗨";
+                                        let canvasStr = `${nickName}邀请你加入`;
+
+                                        let firstLine = canvasStr.slice(0, 16);
+                                        let secondLine = canvasStr.slice(16);
+
+                                        ctx.fillText(firstLine, adjustX(data.nickNamePosX), adjustY(data.nickNamePosY + 12));
+                                        ctx.fillText(secondLine, adjustX(data.nickNamePosX), adjustY(data.nickNamePosY + 30));
+
+                                        // 绘制二维码
+                                        ctx.save();
+                                        ctx.beginPath();
+                                        ctx.arc(
+                                            adjustX(data.qrCodePosX + data.qrCodeWidth / 2),
+                                            adjustY(data.qrCodePosY + data.qrCodeHeight / 2),
+                                            adjustSize(data.qrCodeWidth / 2),
+                                            0,
+                                            2 * Math.PI
+                                        );
+                                        ctx.clip();
+                                        ctx.drawImage(
+                                            qrRes.tempFilePath,
+                                            adjustX(data.qrCodePosX),
+                                            adjustY(data.qrCodePosY),
+                                            adjustSize(data.qrCodeWidth),
+                                            adjustSize(data.qrCodeHeight)
+                                        );
+                                        ctx.restore();
+
+                                        // 执行最终绘制
+                                        ctx.draw(false, () => {
+                                            setTimeout(() => {
+                                                uni.canvasToTempFilePath({
+                                                    canvasId: "posterCanvas",
+                                                    width: canvasWidth,
+                                                    height: canvasHeight,
+                                                    destWidth: canvasWidth * dpr,
+                                                    destHeight: canvasHeight * dpr,
+                                                    quality: 1,
+                                                    success: (res) => {
+                                                        this.loading = false;
+                                                        this.showPoster = true;
+                                                        this.posterInfo.tempFilePath = res.tempFilePath;
+                                                    },
+                                                    fail: (err) => {
+                                                        console.error("生成图片失败:", err);
+                                                        uni.showToast({
+                                                            title: "海报生成失败",
+                                                            icon: "none"
+                                                        });
+                                                        this.loading = false;
+                                                    }
                                                 });
-                                                this.loading = false;
-                                            },
+                                            }, 100);
                                         });
-                                    }, 100);
+                                    },
+                                    fail: (err) => {
+                                        console.error("头像下载失败:", err);
+                                        this.loading = false;
+                                        uni.showToast({
+                                            title: "头像加载失败",
+                                            icon: "none"
+                                        });
+                                    }
                                 });
                             },
                             fail: (err) => {
-                                this.loading = false;
                                 console.error("二维码下载失败:", err);
+                                this.loading = false;
                                 uni.showToast({
                                     title: "二维码加载失败",
-                                    icon: "none",
+                                    icon: "none"
                                 });
-                            },
+                            }
                         });
                     },
                     fail: (err) => {
                         console.error("背景图下载失败:", err);
+                        this.loading = false;
                         uni.showToast({
                             title: "背景图加载失败",
-                            icon: "none",
+                            icon: "none"
                         });
-                    },
+                    }
                 });
             });
         },
@@ -276,6 +277,7 @@ export default {
             });
         },
         saveImage() {
+            // #ifdef MP-WEIXIN
             uni.getSetting({
                 success: (res) => {
                     if (!res.authSetting["scope.writePhotosAlbum"]) {
@@ -296,8 +298,31 @@ export default {
                     }
                 },
             });
+            // #endif
+
+            // #ifdef MP-ALIPAY
+            // 支付宝小程序直接调用保存,会自动触发授权
+            my.saveImage({
+                url: this.posterInfo.tempFilePath,
+                showActionSheet: false,
+                success: () => {
+                    uni.showToast({
+                        title: "保存成功",
+                        icon: "success",
+                    });
+                },
+                fail: (err) => {
+                    console.error("保存失败:", err);
+                    uni.showToast({
+                        title: "保存失败",
+                        icon: "none",
+                    });
+                }
+            });
+            // #endif
         },
         saveImageToAlbum() {
+            // #ifdef MP-WEIXIN
             uni.saveImageToPhotosAlbum({
                 filePath: this.posterInfo.tempFilePath,
                 success: () => {
@@ -313,6 +338,7 @@ export default {
                     });
                 },
             });
+            // #endif
         },
     },
 };
@@ -329,6 +355,7 @@ export default {
         margin-bottom: 20rpx;
         display: block;
     }
+
     .header {
         display: flex;
         align-items: flex-start;
@@ -483,6 +510,7 @@ export default {
             top: -2rpx;
         }
     }
+
     ::v-deep .u-mode-center-box {
         background-color: transparent !important;
     }

+ 2 - 0
pages/home/index.vue

@@ -317,6 +317,7 @@ export default {
                 path: "/pages/home/index?upsellCode=" + upsellCode,
                 imageUrl:
                     "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
             };
         } else {
             return {
@@ -337,6 +338,7 @@ export default {
                 path: "/pages/home/index?upsellCode=" + upsellCode,
                 imageUrl:
                     "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
+                desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
             };
         } else {
             return {