wangguoyu 2 days ago
parent
commit
21181d6c68
2 changed files with 52 additions and 26 deletions
  1. 47 12
      components/sharePopUp/index.vue
  2. 5 14
      pages/admin/haibao/haibaoInfo.vue

+ 47 - 12
components/sharePopUp/index.vue

@@ -38,11 +38,10 @@
 			default: '分享标题'
 		},
 		// type=0: 图文分享(需要 title + summary + imageUrl)
-		// type=1: 纯图片分享(只需要 imageUrl)
-		// type=2: 链接分享(需要 title + summary + href + imageUrl)
+		// type=2: 纯图片分享(只需要 imageUrl)
 		type: {
-			type: String,
-			default: "0" // 0:图文
+			type: [String, Number],
+			default: 0 // 0:图文
 		},
 		// 分享描述
 		desc: {
@@ -95,15 +94,14 @@
 
 	// 分享到微信
 	const shareToWeChat = (scene) => {
-		console.log('props.link',props.link);
-		uni.share({
+		// 获取分享类型,确保是数字类型
+		const shareType = Number(props.type)
+
+		// 构建基础分享配置
+		const shareConfig = {
 			provider: 'weixin',
 			scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
-			type: Number(props.type),
-			title: props.title,
-			summary: props.desc,
-			href: props.link,
-			imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
+			type: shareType,
 			success: function(res) {
 				emit('success', {
 					scene
@@ -113,10 +111,47 @@
 				emit('error', err)
 				handleShareError(err)
 			}
-		})
+		}
+		// 根据类型添加不同的参数
+		if (shareType == 2) {
+			// 纯图片分享
+			shareConfig.imageUrl = props.image
+		} else {
+			// 图文或链接分享(兼容原有逻辑)
+			shareConfig.title = props.title
+			shareConfig.summary = props.desc
+			shareConfig.imageUrl = props.image
+			shareConfig.href = props.link
+		}
+
+		console.log('分享配置:', shareConfig)
+		uni.share(shareConfig)
 	}
 
 
+	// const shareToWeChat = (scene) => {
+	// 	console.log('props.link',props.link);
+	// 	uni.share({
+	// 		provider: 'weixin',
+	// 		scene: scene === 'timeline' ? 'WXSceneTimeline' : 'WXSceneSession',
+	// 		type: Number(props.type),
+	// 		title: props.title,
+	// 		summary: props.desc,
+	// 		href: props.link,
+	// 		imageUrl: props.image || 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
+	// 		success: function(res) {
+	// 			emit('success', {
+	// 				scene
+	// 			})
+	// 		},
+	// 		fail: function(err) {
+	// 			emit('error', err)
+	// 			handleShareError(err)
+	// 		}
+	// 	})
+	// }
+
+
 	// 错误处理
 	const handleShareError = (error) => {
 		console.error('分享失败:', error)

+ 5 - 14
pages/admin/haibao/haibaoInfo.vue

@@ -21,7 +21,7 @@
 			<view v-else class="loading-text">暂无数据</view>
 		</view>
 	</view>
-	<share-popup ref="sharePopupRef" title="海报" desc="请点击查看海报详情" :link=haibaoUrl type="0" @success="onShareSuccess" />
+	<share-popup ref="sharePopupRef" title="海报" :image="haibaoImage" type="2" @success="onShareSuccess" />
 </template>
 
 <script setup>
@@ -46,6 +46,7 @@
 	})
 	const haibaoUrl = ref('')
 	const sharePopupRef = ref(null)
+	const haibaoImage = ref(null)
 
 	function onShareSuccess(e) {
 		console.log('分享成功', e.scene)
@@ -78,20 +79,10 @@
 		httpApi.haibaoShare({
 			id: data.id
 		}).then(res => {
-			console.log(res,'res');
+			console.log(res, 'res');
 			if (res.code == 0) {
-				uni.share({
-					provider: "weixin",
-					scene: "WXSceneTimeline",
-					type: 2,
-					imageUrl: res.data,
-					success: function(res) {
-						console.log("success:" + JSON.stringify(res));
-					},
-					fail: function(err) {
-						console.log("fail:" + JSON.stringify(err));
-					}
-				});
+				haibaoImage.value = res.data
+				sharePopupRef.value.open()
 			}
 		}).catch(err => {
 			uni.showToast({