Browse Source

分享好友、复制链接、分享朋友圈(参数传递和接收等、小程序测试环境无法测试:微信认证已过期)

htc 11 hours ago
parent
commit
b01b5b0693
4 changed files with 80 additions and 19 deletions
  1. 12 1
      App.vue
  2. 21 9
      pagesHome/components/createList.vue
  3. 3 3
      pagesHome/questionnaireEdit.vue
  4. 44 6
      pagesPublish/publishResult.vue

+ 12 - 1
App.vue

@@ -8,8 +8,19 @@
 		onLaunch: function() {
 			
 		},
-		onShow: function() {
+		onShow: function(options) {
 			this.autoUpdate();
+			
+			//通过 URL Scheme 唤醒小程序,传递的参数 query
+			if (options.scene === 1065 && options.query) {
+				const shareTQId = options.query.shareTQId;
+				const shareUserId = options.query.shareUserId;
+				if(shareTQId&&shareUserId) {
+					uni.reLaunch({
+						url: `/pages/home?shareTQId=${shareTQId}shareUserId=${shareUserId}&&from=urlScheme`
+					});
+				}
+			}
 		},
 		onHide: function() {
 			if(uni.getStorageSync('channelType')) uni.removeStorageSync('channelType')

+ 21 - 9
pagesHome/components/createList.vue

@@ -134,10 +134,10 @@ export default {
 					img:this.$imgBase+'questionnaire_info.png',
 					text:'团队信息'
 				},
-				// {
-				// 	img:this.$imgBase+'questionnaire_copy.png',
-				// 	text:'复制链接'
-				// },
+				{
+					img:this.$imgBase+'questionnaire_copy.png',
+					text:'复制链接'
+				},
 				{
 					img:this.$imgBase+'questionnaire_users.png',
 					text:'团队人员'
@@ -164,7 +164,7 @@ export default {
 		onShareAppMessage(res) {
 		    // res.from === 'button' // 来自页面内分享按钮
 		    // res.from === 'menu'   // 来自右上角菜单分享
-		    const sharerId = JSON.parse(uni.getStorageSync('userInfo')).id;
+		    const sharerId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
 		    console.log(`准备分享,团队问卷ID: ${this.dto.teamQuestionnaireId}, 分享者ID: ${sharerId}`);
 		    return {
 		      title: this.dto.title || '发现一个好物,分享给你!',
@@ -233,11 +233,23 @@ export default {
 					this.$refs.teamRef.teamLevelText = this.teamLevelData.find(d=>d.id==res.data.hierarchy).name;
 				})
 			}
-			else if(item.text==='复制链接') {
-				uni.setClipboardData({
-
+			else if(item.text==='复制链接') {
+				let shareUserId = JSON.parse(uni.getStorageSync('userInfo')).id;
+				let res = await this.$api.post('/wx/genInviteLink',{
+					'path': '',
+					'query': `shareTQId=${this.dto.teamQuestionnaireId}&shareUserId=${shareUserId}`,
+					'env_version': 'develop'//默认"release",正式版"release",体验版"trial",开发版"develop"
+				});
+				if(res.data.code!==0) return this.$showToast(res.data.msg)
+				uni.setClipboardData({
+					data:res.data.data.openlink,
+					success: () => {
+						this.$showToast('复制成功')
+					},
+					fail: () => {
+						this.$showToast('复制失败')
+					}
 				})
-				this.$showToast('复制成功')
 			}
 			else if(item.text==='团队人员'){
 				await this.getUserCategoryData()

+ 3 - 3
pagesHome/questionnaireEdit.vue

@@ -47,7 +47,7 @@
 				</view>
 			</view>
 		</view>
-		<!-- <view class="box" style="padding: 30rpx 24rpx 0;" v-if="type==2">
+		<view class="box" style="padding: 30rpx 24rpx 0;" v-if="type==2&&!isEdit">
 			<view class="box-title adfacjb" style="margin-bottom: 21rpx;">
 				<text>团队人员</text>
 				<view class="box-add" @click="addTeamUser">+ 添加</view>
@@ -64,7 +64,7 @@
 					<image class="box-user-item-right" :src="imgBase+'icon_delete.png'" @click="deleteTeamUser(item,index)"></image>
 				</view>
 			</view>
-		</view> -->
+		</view>
 		<view class="bottom">
 			<view class="zt_btn" @click="confirmPublish">{{confirmText}}</view>
 		</view>
@@ -236,7 +236,7 @@
 					setTimeout(()=>{
 						if(this.type==2){
 							if(this.isEdit) return uni.navigateBack()
-							uni.navigateTo({ url:'/pagesPublish/publishResult?title='+this.questionnaireName })
+							uni.navigateTo({ url:'/pagesPublish/publishResult?title='+this.questionnaireName+'&teamQuestionnaireId='+res.data })
 						}else uni.navigateBack()
 					},1500)
 				})

+ 44 - 6
pagesPublish/publishResult.vue

@@ -23,14 +23,16 @@
 			<view class="share-title">分享到</view>
 			<view class="share-menu adf">
 				<view class="share-menu-pre adffcac">
-					<image :src="imgBase+'publish_result_wx.png'"></image>
-					<text>微信好友</text>
+					<button class="share-btn" open-type="share">
+						<image :src="imgBase+'publish_result_wx.png'"></image>
+						<text>微信好友</text>
+					</button>
 				</view>
-				<view class="share-menu-pre adffcac">
+				<view class="share-menu-pre adffcac" @click="sharePyq">
 					<image :src="imgBase+'publish_result_pyq.png'"></image>
 					<text>朋友圈</text>
 				</view>
-				<view class="share-menu-pre adffcac">
+				<view class="share-menu-pre adffcac" @click="copyLink">
 					<image :src="imgBase+'publish_result_copy.png'"></image>
 					<text>复制链接</text>
 				</view>
@@ -43,19 +45,55 @@
 	export default {
 		data(){
 			return {
-				title:''
+				title:'',
+				teamQuestionnaireId:''
 			}
 		},
+		onShareTimeline() {
+		    const sharerId = JSON.parse(uni.getStorageSync('userInfo')).id;
+			return {
+				title: this.title,
+				query: `shareUserId=${sharerId}&shareTQId=${this.teamQuestionnaireId}&from=timeline`,
+		      // imageUrl: this.$imgBase+''
+			};
+		},
+		onShareAppMessage(res) {
+		    const sharerId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
+		    return {
+		      title: this.title,
+		      path: `/pages/home?shareTQId=${this.teamQuestionnaireId}&shareUserId=${sharerId}`,
+		      // imageUrl: this.$imgBase+''
+		    };
+		},
 		onLoad(options){
 			this.title = options.title;
+			this.teamQuestionnaireId = options.teamQuestionnaireId;
 		},
 		methods:{
-			
+			async copyLink(){
+				let res = await this.$api.get('/wx/getStableAccessToken');
+				console.log(res);
+			}
 		}
 	}
 </script>
 
 <style scoped lang="scss">
+	.share-btn {
+		background-color: transparent;
+		border: none;
+		padding: 0;
+		margin: 0;
+		line-height: 1;
+		display: flex;
+		flex-direction: column;
+		justify-content: center;
+		align-items: center;
+		&::after {
+			border: none;
+		}
+	}
+
 	.default_page{
 		box-sizing: border-box;
 		.xcx{