zbb 1 tydzień temu
rodzic
commit
d557ec086c
1 zmienionych plików z 58 dodań i 11 usunięć
  1. 58 11
      pages/mine/card.vue

+ 58 - 11
pages/mine/card.vue

@@ -44,7 +44,7 @@
 
 
 			<view class="control-card">
-				<view class="item">
+				<view class="item" @click="shareUserCard">
 					<image src="/static/image/public/card-sharing.png"></image>
 					<button open-type="share" class="text resetButton">分享名片</button>
 				</view>
@@ -121,9 +121,10 @@
 						<uni-icons type="download" size="24" color="#4080FF"></uni-icons>
 						<text class="action-text">保存到相册</text>
 					</view>
-					<view class="action-btn">
+					<view class="action-btn" @click="handleShare">
 						<uni-icons type="paperplane" size="24" color="#4080FF"></uni-icons>
-						<button open-type="share" class="action-text">分享给好友</button>
+						<!-- <button open-type="share" class="action-text">分享给好友</button> -->
+						<text class="action-text">分享给好友</text>
 					</view>
 				</view>
 			</view>
@@ -169,7 +170,6 @@
 	const cardPopup = ref(null)
 
 	const productList = ref([])
-	let shareImage = ref('data:image/png;base64,' + qrInfo.value.image)
 	onShareAppMessage(() => {
 		return {
 			userName: '小程序',
@@ -207,13 +207,10 @@
 		})
 
 		try {
-			// 打印 cardInfo 详细信息
-			console.log('[saveCard] cardInfo:', JSON.stringify(cardInfo.value, null, 2))
-			console.log('[saveCard] avatar:', cardInfo.value.avatar)
 
 			// 生成名片快照
 			const snapshotPath = await generateCardPoster(cardInfo.value)
-
+			console.log(snapshotPath, "snapshotPathsnapshotPathsnapshotPath");
 			// 用属性接收快照路径
 			cardSnapshot.value = snapshotPath
 
@@ -247,7 +244,60 @@
 		cardPopup.value.close()
 	}
 
+	const shareUserCard = async () => {
+		const snapshotPath = await generateCardPoster(cardInfo.value)
+		wx.showShareImageMenu({
+			path: snapshotPath,
+			success: () => {
+				console.log('分享菜单已调起');
+			},
+			fail: (err) => {
+				console.error('调起分享菜单失败', err);
+			}
+		});
+
+	}
 
+
+	const base64ToImage = async (base64Data) => {
+		return new Promise((resolve, reject) => {
+			try {
+				const filePath = `${wx.env.USER_DATA_PATH}/temp_image.png`;
+				let pureBase64Data = base64Data
+				if (pureBase64Data.startsWith('data:image')) {
+					pureBase64Data = pureBase64Data.replace(/^data:image\/\w+;base64,/, '');
+				}
+				const fs = wx.getFileSystemManager();
+				fs.writeFile({
+					filePath: filePath,
+					data: pureBase64Data,
+					encoding: 'base64',
+					success: (res) => {
+						console.log("resresweresresresres", res);
+						resolve(filePath)
+					},
+					fail: (err) => {
+						console.error('写入临时文件失败', err);
+					}
+				});
+			} catch (error) {
+				console.error('base64 转换异常:', error)
+				reject(error)
+			}
+		})
+	}
+	const handleShare = async () => {
+		const qrFilePath = await base64ToTempFile(qrInfo.value.image)
+		wx.showShareImageMenu({
+			path: qrFilePath,
+			success: () => {
+				console.log('分享菜单已调起');
+			},
+			fail: (err) => {
+				console.error('调起分享菜单失败', err);
+			}
+		});
+	}
 	// 保存二维码到相册
 	const saveQRCode = async () => {
 		if (!qrInfo.value.image) {
@@ -261,7 +311,6 @@
 		try {
 			// 将 base64 转换为临时文件
 			const qrFilePath = await base64ToTempFile(qrInfo.value.image)
-
 			// 保存到相册
 			await savePosterToAlbum(qrFilePath)
 			uni.showToast({
@@ -282,7 +331,6 @@
 	const switchTab = (tab) => {
 		currentTab.value = tab
 	}
-
 	// 将 base64 转换为临时文件路径
 	const base64ToTempFile = async (base64Data) => {
 		return new Promise((resolve, reject) => {
@@ -292,7 +340,6 @@
 
 				const fileName = `${Date.now()}_qrcode.png`
 				const filePath = `${wx.env.USER_DATA_PATH}/${fileName}`
-
 				const fs = uni.getFileSystemManager()
 				fs.writeFile({
 					filePath: filePath,