wangguoyu 3 napja
szülő
commit
6a994abc4b
2 módosított fájl, 170 hozzáadás és 45 törlés
  1. 156 0
      components/sharePopUp/index.vue
  2. 14 45
      pages/admin/mianshi/index.vue

+ 156 - 0
components/sharePopUp/index.vue

@@ -0,0 +1,156 @@
+<template>
+	<!-- 分享弹窗 -->
+	<uni-popup ref="popupRef" type="bottom" background-color="#fff" :mask-click="false">
+		<view class="share-popup-container">
+			<!-- 标题 -->
+			<view class="share-header">
+				<text class="share-title">分享到</text>
+			</view>
+			<!-- 分享选项 -->
+			<scroll-view scroll-x class="share-scroll" :show-scrollbar="false">
+				<view class="share-list">
+					<!-- 微信好友 -->
+					<view class="share-item" @click="select('session')">
+						<view class="share-icon wechat-icon"></view>
+						<text class="share-text">微信好友</text>
+					</view>
+					<!-- 朋友圈 -->
+					<view class="share-item" @click="select('timeline')">
+						<view class="share-icon timeline-icon"></view>
+						<text class="share-text">朋友圈</text>
+					</view>
+				</view>
+				<view class="share-close" @click="close">取消</view>
+			</scroll-view>
+		</view>
+	</uni-popup>
+</template>
+
+<script setup>
+	import {
+		ref
+	} from 'vue'
+
+	// 定义props
+	const props = defineProps({
+		// 分享标题
+		title: {
+			type: String,
+			default: '分享标题'
+		},
+		// type=0: 图文分享(需要 title + summary + imageUrl)
+		// type=1: 纯图片分享(只需要 imageUrl)
+		// type=2: 链接分享(需要 title + summary + href + imageUrl)
+		type: {
+			type: String,
+			default: "0" // 0:图文
+		},
+		// 分享描述
+		desc: {
+			type: String,
+			default: '分享描述'
+		},
+		// 分享链接
+		link: {
+			type: String,
+			default: ''
+		},
+		// 分享图片
+		image: {
+			type: String,
+			default: ''
+		},
+
+	})
+
+	const emit = defineEmits(['close', 'select', 'success', 'error'])
+
+	const popupRef = ref(null)
+
+	// 打开弹窗
+	const open = () => {
+		popupRef.value.open()
+	}
+
+	// 关闭弹窗
+	const close = () => {
+		popupRef.value.close()
+		emit('close')
+	}
+
+	// 选择分享方式
+	const select = (scene) => {
+		//emit('select', scene)
+
+		try {
+			shareToWeChat(scene)
+			close()
+		} catch (error) {
+			emit('error', error)
+			handleShareError(error)
+		}
+	}
+
+
+
+
+	// 分享到微信
+	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)
+
+		const errCode = error.errCode || error.code
+		const errMsg = error.errMsg || error.message
+
+		// 微信未安装
+		if (errCode === 1004 || errCode === -4004) {
+			uni.showModal({
+				title: '提示',
+				content: '请先安装微信',
+				showCancel: false
+			})
+			return
+		}
+
+		// 用户取消不提示
+		if (errCode === 1001 || errCode === -4001) {
+			return
+		}
+
+		// 其他错误
+		uni.showToast({
+			title: errMsg || '分享失败,请重试',
+			icon: 'none',
+			duration: 3000
+		})
+	}
+
+	// 暴露方法给父组件
+	defineExpose({
+		open,
+		close
+	})
+</script>

+ 14 - 45
pages/admin/mianshi/index.vue

@@ -39,22 +39,14 @@
 					<view class="tip-text">2. 关闭房间后,面试人员将无法再进入房间,需要重新创建房间。</view>
 				</view>
 			</view>
-			<uni-popup ref="popupShareRef" type="bottom">
-				<view class="share-options">
-					<!-- 微信好友 -->
-					<view class="share-item" @click="selectShare('weixinHaoyou')">
-
-						<text class="share-text">微信好友1231231231231231231231231</text>
-					</view>
-					<!-- 微信朋友圈 -->
-					<view class="share-item" @click="selectShare('pengyouquan')">
-
-						<text class="share-text">朋友圈</text>
-					</view>
-					<text class="share-text" @click="closePopup">取消</text>
-				</view>
-			</uni-popup>
-
+			 <share-popup 
+			      ref="sharePopupRef"
+			      title="远程面试邀请"
+			      desc="请点击链接参加面试"
+			      :link=roomUrl
+			      type="0"
+			      @success="onShareSuccess"
+			    />
 		</view>
 	</view>
 </template>
@@ -69,42 +61,19 @@
 		onLoad
 	} from "@dcloudio/uni-app";
 	import config from "../../../config"
-
+	import SharePopup from '@/components/sharePopUp/index.vue'
 	const data = reactive({
 		room: '',
 	})
 	const roomUrl = ref('')
-	const popupShareRef = ref(null)
 
+	const sharePopupRef = ref(null)
 	function closePopup() {
-		popupShareRef.value.close()
+		sharePopupRef.value.close()
 	}
-
-	function selectShare(data) {
-		let sceneType
-		if (data == 'weixinhaoyou') {
-			sceneType = 'WXSceneSession'
-		} else {
-			sceneType = 'WXSceneTimeline'
-		}
-		console.log('sceneType', sceneType);
-		uni.share({
-			provider: "weixin",
-			scene: sceneType,
-			type: 0,
-			href: roomUrl.value,
-			title: "uni-app分享",
-			summary: "我正在使用HBuilderX开发uni-app,赶紧跟我一起来体验!",
-			imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png",
-			success: function(res) {
-				console.log("success:" + JSON.stringify(res));
-			},
-			fail: function(err) {
-				console.log("fail:" + JSON.stringify(err));
-			}
-		});
+	function onShareSuccess(e){
+		 console.log('分享成功', e.scene)
 	}
-
 	function goUpPage() {
 		uni.redirectTo({
 			url: `/pages/admin/ShouYe/shouye`
@@ -136,7 +105,7 @@
 
 	function yqBtn(code) {
 		roomUrl.value = `${config.mianshiUrl}?roomId=900803&index=${code}`
-		popupShareRef.value.open()
+		sharePopupRef.value.open()
 		// 分享地址
 		//const url = `${config.mianshiUrl}?roomId=900803&index=${code}`
 	}