浏览代码

Merge branch 'master' of https://git.citupro.com/zhengnaiwen_citu/menduner-uniapp

Xiao_123 7 月之前
父节点
当前提交
9926e9dd43
共有 2 个文件被更改,包括 70 次插入31 次删除
  1. 45 8
      pages/index/my.vue
  2. 25 23
      utils/base64src.js

+ 45 - 8
pages/index/my.vue

@@ -46,9 +46,14 @@
 				<view class="shareQrCodePopupContent">
 				<view class="shareQrCodePopupContent">
 					<view class="color-primary text">邀请用户注册领50积分</view>
 					<view class="color-primary text">邀请用户注册领50积分</view>
 					<view class="qrCode">
 					<view class="qrCode">
-						<image :src="shareUrl" style="width: 200px;height: 200px;"></image>
+						<image
+            	v-if="!!shareUrl"
+							:src="shareUrl"
+							:show-menu-by-longpress="true"
+							style="width: 200px;height: 200px; padding: 20rpx;"
+						></image>
 					</view>
 					</view>
-					<!-- <button v-if="shareUrl" class="send-button ss-m-b-30" @tap="handleSaveShareUrl">保存</button> -->
+					<view v-if="shareUrl" class="saveImg">长按二维码保存图片</view>
 				</view>
 				</view>
 			</uni-popup>
 			</uni-popup>
 		</view>
 		</view>
@@ -134,12 +139,16 @@ const shareUrl = ref()
 // 生成分享二维码
 // 生成分享二维码
 const handleShareCode = async () => {
 const handleShareCode = async () => {
 	const userId = useUserStore?.accountInfo?.userId || ''
 	const userId = useUserStore?.accountInfo?.userId || ''
+	console.log(1, 'userId', userId)
 	if (!userId) {
 	if (!userId) {
 		uni.showToast({
 		uni.showToast({
 			title: '请先登录',
 			title: '请先登录',
 			icon: 'none'
 			icon: 'none'
 		})
 		})
+		showAuthModal()
+		return
 	}
 	}
+  // if (!getAccessToken())
 	const query = {
 	const query = {
 		scene: 'shareId=' + userId,
 		scene: 'shareId=' + userId,
 		path: 'pages/login/index',
 		path: 'pages/login/index',
@@ -155,7 +164,32 @@ const handleShareCode = async () => {
 
 
 // 保存到本地
 // 保存到本地
 const handleSaveShareUrl = async () => {
 const handleSaveShareUrl = async () => {
-	const convertData = await base64src(shareUrl.value, '我的分享码')
+	// base64src(shareUrl.value, '我的分享码')
+	const fsm = wx.getFileSystemManager()
+	const data = shareUrl.value
+	// console.log('data:', data)
+	if (!data) return
+	fsm.writeFile({
+		filePath:wx.env.USER_DATA_PATH+'/MySharingCode.png',
+		data: data.slice(22),
+		encoding:'base64',
+		success: res => {
+			wx.saveImageToPhotosAlbum({
+				filePath: wx.env.USER_DATA_PATH + '/MySharingCode.png',
+				success: function (res) {
+					wx.showToast({
+						title: '保存成功',
+					})
+				},
+				fail: function (err) {
+					console.log(err)
+				}
+			})
+			// console.log(res)
+		}, fail: err => {
+			console.log(err)
+		}
+	})
 }
 }
 
 
 // 登录
 // 登录
@@ -223,11 +257,9 @@ const handleLogoutConfirm = () => {
 	margin: 0 0 20rpx 30rpx;
 	margin: 0 0 20rpx 30rpx;
 }
 }
 .shareQrCodePopupContent {
 .shareQrCodePopupContent {
-	// width: 80vw;
-	// display: flex;
-	// flex-direction: column;
-	margin: 50rpx;
-	padding: 50rpx;
+	width: 80vw;
+	padding: 30rpx;
+	margin-bottom: 20rpx;
 	text-align: center;
 	text-align: center;
 	background-color: #fff;
 	background-color: #fff;
 	.text {
 	.text {
@@ -236,5 +268,10 @@ const handleLogoutConfirm = () => {
 	.qrCode {
 	.qrCode {
 		margin-left: 4px;
 		margin-left: 4px;
 	}
 	}
+	.saveImg {
+		text-align: center;
+		margin-top: 10px;
+		color: #999;
+	}
 }
 }
 </style>
 </style>

+ 25 - 23
utils/base64src.js

@@ -1,26 +1,28 @@
-const fsm = wx.getFileSystemManager();
 
 
-function base64src(base64data, fileName) {
-  fileName = fileName || 'file_base64src'; //自定义文件名
-  const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
-  if (!format) {
-    return (new Error('ERROR_BASE64SRC_PARSE'));
-  }
-  const filePath = `${wx.env.USER_DATA_PATH}/${fileName}.${format}`;
-  const buffer = wx.base64ToArrayBuffer(bodyData);
-  return new Promise((resolve, reject) =>{
-    fsm.writeFile({
-        filePath,
-        data: buffer,
-        encoding: 'binary',
-        success() {
-            resolve(filePath);
-        },
-        fail() {
-            reject(new Error('ERROR_BASE64SRC_WRITE'));
-        },
-    });
-  })
-};
+function base64src(data, fileName) {
+	const fsm = wx.getFileSystemManager()
+	if (!data) return
+	fsm.writeFile({
+		filePath: `wx.env.USER_DATA_PATH+'/${fileName}.png'`,
+		data: data.slice(22),
+		encoding:'base64',
+		success: res => {
+			wx.saveImageToPhotosAlbum({
+				filePath: `wx.env.USER_DATA_PATH + '/${fileName}.png'`,
+				success: function (res) {
+					wx.showToast({
+						title: '保存成功',
+					})
+				},
+				fail: function (err) {
+					console.log(err)
+				}
+			})
+			// console.log(res)
+		}, fail: err => {
+			console.log(err)
+		}
+	})
+}
 
 
 export { base64src };
 export { base64src };