chengjunhui 1 månad sedan
förälder
incheckning
a590edd670
4 ändrade filer med 85 tillägg och 29 borttagningar
  1. 60 13
      invitationCode/index.js
  2. 3 1
      invitationCode/index.wxml
  3. 6 3
      invitationCode/index.wxss
  4. 16 12
      pages/login.js

+ 60 - 13
invitationCode/index.js

@@ -30,9 +30,15 @@ Page({
 			memberphoto: options.memberphoto ? options.memberphoto : user.memberphoto,
 			user
 		})
-		this.getCode();
+		if (wx.getStorageSync('invitationCodeImg')) {
+			that.setData({
+				invitationCodeImg: wx.getStorageSync('invitationCodeImg'),
+			});
+		} else {
+			this.getCode();
+		}
 		wx.setNavigationBarTitle({
-			title: options.inviteCode ? '他/她的会员码' : '我的会员码'
+			title: options.inviteCode ? '他/她的会员码' : '会员码'
 		});
 	},
 	downloadQR() {
@@ -153,23 +159,23 @@ Page({
 	// 带重试机制的图片绘制方法
 	drawImageWithRetry(ctx, imageUrl, x, y, width, height, isAvatar, callback) {
 		const that = this;
-		
+
 		// 检查是否为base64格式的图片数据
 		if (imageUrl && (imageUrl.startsWith('data:image') || imageUrl.startsWith('/9j/'))) {
 			// 处理base64格式的图片
 			that.drawBase64Image(ctx, imageUrl, x, y, width, height, isAvatar, callback);
 			return;
 		}
-		
+
 		// 如果imageUrl为空或无效,直接回调
 		if (!imageUrl) {
 			callback && callback();
 			return;
 		}
-		
+
 		wx.getImageInfo({
 			src: imageUrl,
-			success: function(res) {
+			success: function (res) {
 				try {
 					// 检查是否为二维码图片,如果是则添加圆角
 					if (!isAvatar && that.data.invitationCodeImg && imageUrl === that.data.invitationCodeImg) {
@@ -193,7 +199,7 @@ Page({
 						// 如果是头像,需要圆形裁剪
 						ctx.save();
 						ctx.beginPath();
-						ctx.arc(x + width/2, y + height/2, width/2, 0, 2 * Math.PI);
+						ctx.arc(x + width / 2, y + height / 2, width / 2, 0, 2 * Math.PI);
 						ctx.clip();
 						ctx.drawImage(res.path, x, y, width, height);
 						ctx.restore();
@@ -207,7 +213,7 @@ Page({
 					callback && callback();
 				}
 			},
-			fail: function(err) {
+			fail: function (err) {
 				console.log('获取图片失败', err, imageUrl);
 				// 如果是头像且获取失败,使用默认头像
 				if (isAvatar) {
@@ -298,12 +304,12 @@ Page({
 		const that = this;
 		wx.canvasToTempFilePath({
 			canvasId: 'myCanvas',
-			success: function(res) {
+			success: function (res) {
 				wx.hideLoading();
 				// 保存图片到相册
 				that.saveImageToPhotosAlbum(res.tempFilePath);
 			},
-			fail: function(err) {
+			fail: function (err) {
 				wx.hideLoading();
 				console.log('生成海报失败', err);
 				wx.showToast({
@@ -313,18 +319,18 @@ Page({
 			}
 		}, that);
 	},
-	
+
 	// 保存图片到相册
 	saveImageToPhotosAlbum(filePath) {
 		wx.saveImageToPhotosAlbum({
 			filePath: filePath,
-			success: function() {
+			success: function () {
 				wx.showToast({
 					title: '已保存到相册',
 					icon: 'success'
 				});
 			},
-			fail: function(err) {
+			fail: function (err) {
 				console.log('保存失败', err);
 				wx.showToast({
 					title: '保存失败',
@@ -445,6 +451,7 @@ Page({
 					that.setData({
 						invitationCodeImg: res.data
 					})
+					wx.setStorageSync('invitationCodeImg', res.data);
 				}
 			})
 	},
@@ -465,5 +472,45 @@ Page({
 				})
 			}
 		})
+	},
+
+	/**
+	 * 将网络图片转换为base64格式
+	 * @param {string} url - 网络图片地址
+	 * @returns {Promise<string>} base64格式字符串
+	 */
+	convertImageToBase64(url) {
+		return new Promise((resolve, reject) => {
+			// 下载网络图片
+			wx.downloadFile({
+				url: url,
+				success: (res) => {
+					if (res.statusCode === 200) {
+						const tempFilePath = res.tempFilePath;
+						// 读取本地文件内容并转换为base64
+						const fs = wx.getFileSystemManager();
+						fs.readFile({
+							filePath: tempFilePath,
+							encoding: 'base64',
+							success: (readRes) => {
+								// 构造完整的base64数据URI
+								const base64Data = 'data:image/png;base64,' + readRes.data;
+								resolve(base64Data);
+							},
+							fail: (error) => {
+								console.error('读取图片文件失败:', error);
+								reject(error);
+							}
+						});
+					} else {
+						reject(new Error('下载图片失败'));
+					}
+				},
+				fail: (error) => {
+					console.error('下载图片失败:', error);
+					reject(error);
+				}
+			});
+		});
 	}
 })

+ 3 - 1
invitationCode/index.wxml

@@ -9,7 +9,9 @@
             </view>
         </view>
         <view class="qrcode-info">
-            <image class="invitationCode" mode="widthFix" src="{{invitationCodeImg}}"></image>
+            <view class="invitationCode_view">
+                <image class="invitationCode" mode="widthFix" src="{{invitationCodeImg}}"></image>
+            </view>
             <view class="text">青雲慧青年服务平台</view>
         </view>
     </view>

+ 6 - 3
invitationCode/index.wxss

@@ -7,11 +7,11 @@ page {
   background-size: cover;
   background-position: center;
   box-sizing: border-box;
-  padding: 46rpx 60rpx 225rpx 60rpx;
+  padding: 46rpx 60rpx 150rpx 60rpx;
 }
 
 .main-content {
-  height: 100%;
+  height: 1110rpx;
   background-size: 100% 100%;
   background-repeat: no-repeat;
   position: relative;
@@ -61,7 +61,10 @@ page {
 	width: 148rpx;
 	border-radius: 10rpx;
 }
-
+.main-content .qrcode-info .invitationCode_view{
+  text-align: center;
+  min-height: 148rpx;
+}
 .bottom {
   position: fixed;
   width: 750rpx;

+ 16 - 12
pages/login.js

@@ -86,24 +86,28 @@ Page({
     //     inviteCode,
     //   });
     // }
-    if (options.scene) {
-      // 解码scene参数
-      const sceneStr = decodeURIComponent(options.scene);
-      console.log('解码后的scene:', sceneStr);
+    try {
+      if (options.scene) {
+        // 解码scene参数
+        const sceneStr = decodeURIComponent(options.scene);
+        console.log('解码后的scene:', sceneStr);
 
-      // 解析参数格式:inviteCode=xxx
-      const params = new URLSearchParams(sceneStr);
-      const inviteCode = params.get('inviteCode');
+        // 解析参数格式:inviteCode=xxx
+        const params = new URLSearchParams(sceneStr);
+        const inviteCode = params.get('inviteCode');
 
-      if (inviteCode) {
-        console.log('获取到邀请码:', inviteCode);
-        // 在这里处理邀请码逻辑
+        if (inviteCode) {
+          console.log('获取到邀请码:', inviteCode);
+          // 在这里处理邀请码逻辑
           this.setData({
             inviteCode,
           });
-      } else {
-        console.log('未找到邀请码参数');
+        } else {
+          console.log('未找到邀请码参数');
+        }
       }
+    } catch (error) {
+      console.log('错误:', error);
     }
 
     // console.log(options, "options");