Browse Source

feat:添加每日签到功能对接

wangsisi 1 tháng trước cách đây
mục cha
commit
28d4b15229

+ 16 - 0
api/tree.js

@@ -13,5 +13,21 @@ export default {
 	//获取果树海报
 	getPoster(data) {
 		return http.get('mini/z_farm_buy/getPoster', data)
+	},
+	//随机抽取指定数量话术
+	randomPick(data) {
+		return http.get('mini/buy_clockin_text_lib/random_pick', data)
+	},
+	//打卡
+	clockin(data) {
+		return http.post('mini/z_farm_buy/clockin', data)
+	},
+	//获取订阅模板
+	getSubscribeTemplate(data) {
+		return http.get('mini/z_farm_buy/getSubscribeTemplate', data)
+	},
+	//添加订阅
+	addSubscribe(data) {
+		return http.get('mini/z_farm_buy/addSubscribe', data)
 	},
 }

+ 1 - 1
components/levelSuccessPopup/levelSuccessPopup.vue

@@ -23,7 +23,7 @@
 				</view>
 			</view>
 		</view>
-	</up-popup>>
+	</up-popup>
 </template>
 
 <script setup>

+ 9 - 7
components/posterPopup/posterPopup.vue

@@ -21,9 +21,9 @@
 				<view class="address common-bg">{{ treeObj.pz }}-{{ treeObj.countyName }}</view>
 				<view class="tag-image">
 					<view class="tag-content">
-						<view class="tag-name">【{{ treeName || '茜茜荔' }}】</view>
+						<view class="tag-name">【{{ treeName }}】</view>
 						<view class="tag-user">
-							<text>{{ treeObj.nickname || treeObj.name || '12' }}</text>
+							<text>{{ userInfo.nickname || userInfo.name }}</text>
 							<text class="date">{{ treeObj.year }}.{{
 	                                    treeObj.monthNumber >= 10 ? treeObj.monthNumber : "0" + treeObj.monthNumber
 	                                }}.{{ treeObj.day }}</text>
@@ -33,7 +33,7 @@
 			</view>
 			<view class="info-wrap">
 				<view class="text">
-					<!-- <el-viewider class="viewider" /> -->
+					<up-divider lineColor="#000" :hairline="false"></up-divider>
 					<view v-for="(text, textI) in treeObj.watermarkArr" :key="textI">{{ text }}</view>
 				</view>
 				<view class="nickname">
@@ -46,8 +46,10 @@
 			<view @click="handleDownload">保存图片</view>
 			<view class="share" @click="handleShare">去分享</view>
 		</view>
-		<up-icon class="close" name="close-circle-fill" size="30" @click="showPopup = false"
-			color="rgba(255, 255, 255, 0.7)"></up-icon>
+		<view class="close">
+			<up-icon name="close-circle-fill" size="30" @click="showPopup = false"
+				color="rgba(255, 255, 255, 0.7)"></up-icon>
+		</view>
 	</up-popup>
 	<!-- 保存弹窗 -->
 	<!-- <save-photo-popup ref="savePhotoDom" height="480"></save-photo-popup> -->
@@ -148,7 +150,6 @@
 
 	const closePopup = () => {
 		showPopup.value = false;
-		// VE_API.lj_home.posterRead({ posterId: treeObj.value.posterId });
 	};
 </script>
 
@@ -326,7 +327,8 @@
 	}
 
 	.close {
-		margin-top: 36rpx;
+		margin-top: 36rpx;
+		display: flex;
 		justify-content: center;
 	}
 </style>

+ 67 - 71
pages/tabBar/tree/components/blessingsPopup.vue

@@ -31,12 +31,17 @@
 	<!-- 祝福成功弹窗 -->
 	<up-popup :show="sucessPopup" mode="center" @close="handleCancelSucess" bgColor="transparent">
 		<view class="sucess-popup" @click="handleCancelSucess">
-			<view class="sucess-bg">
-				<image class="img" :src="`${config.BASIC_IMG}img/subTreePage/blessing-sucess.png`"></image>
-			</view>
-			<view class="button-group" @click="handlePage">
-				<view class="btn">开心收下</view>
-				<up-icon class="close" name="close-circle-fill" size="30" color="rgba(255, 255, 255, 0.7)"></up-icon>
+			<template v-if="isFriend">
+				<view class="sucess-bg">
+					<image class="img" :src="`${config.BASIC_IMG}img/subTreePage/blessing-sucess.png`"></image>
+				</view>
+				<view class="button-group">
+					<view class="btn">开心收下</view>
+					<up-icon class="close" name="close-circle-fill" size="30" color="rgba(255, 255, 255, 0.7)"></up-icon>
+				</view>
+			</template>
+			<view v-else  class="sucess-bg">
+				<image class="image" :src="`https://birdseye-img.sysuimars.com/dinggou-mini/sucess-icon-${clockinType}.png`"></image>
 			</view>
 		</view>
 	</up-popup>
@@ -45,31 +50,35 @@
 <script setup>
 	import config from "@/api/config.js"
 	import {
-		onActivated,
 		onMounted,
 		ref,
 		watch
-	} from "vue";
+	} from "vue";
+	import TREE from '@/api/tree.js'
 
 	const props = defineProps({
 		show: {
 			type: Boolean,
 			defalut: false,
+		},
+		showSuccess: {
+			type: Boolean,
+			defalut: false,
 		},
 		farmBuyId: {
 			type: [Number, String],
-			defalut: "",
+			defalut: '',
+		},
+		isFriend: {
+			type: Boolean,
+			defalut: false,
+		},
+		clockinType: {
+			type: [Number, String],
+			defalut: "1",
 		},
 	});
 
-	const handlePage = () => {
-		// if (userInfo.value.tel) {
-		// 	router.push('/guard_tree')
-		// } else {
-		// 	router.push('/lj_home')
-		// }
-	}
-
 
 	const showPopup = ref(false);
 	const message = ref("");
@@ -83,45 +92,20 @@
 	};
 
 	const handleCancelSucess = () => {
-		sucessPopup.value = false;
+		sucessPopup.value = false;
 	};
 
 	const getRandomPick = () => {
-		list.value = [{
-				id: 1,
-				clockinText: '晨曦微露,阳光洒满大地'
-			},
-			{
-				id: 2,
-				clockinText: '新的一天,新的挑战,新的机会'
-			},
-			{
-				id: 3,
-				clockinText: '记住,每一次挫折都是成功的垫脚石'
-			},
-			{
-				id: 4,
-				clockinText: '道阻且长,行则将至,行而不辍,未来可期。'
-			},
-			{
-				id: 5,
-				clockinText: '每日数据的更替,是日积月累的结果'
-			},
-			{
-				id: 6,
-				clockinText: '不必在意他人目光与期待'
+		TREE.randomPick({
+			count: 6
+		}).then(({
+			data
+		}) => {
+			list.value = data || [];
+			if (activeIndex.value != null) {
+				message.value = data[activeIndex.value].clockinText;
 			}
-		]
-		// VE_API.guard_tree.randomPick({
-		// 	count: 6
-		// }).then(({
-		// 	data
-		// }) => {
-		// 	list.value = data || [];
-		// 	if (activeIndex.value != null) {
-		// 		message.value = data[activeIndex.value].clockinText;
-		// 	}
-		// });
+		});
 	};
 
 	const handleMsg = (index, item) => {
@@ -130,21 +114,21 @@
 	};
 
 	const sucessPopup = ref(false);
-
+	
+	const emit = defineEmits(['clockinCallback'])
 	const handleSend = () => {
 		const params = {
 			farmBuyId: props.farmBuyId,
-			clockinType: 3,
+			clockinType: props.clockinType,
 			msg: message.value,
-		};
-		handleCancel();
-		sucessPopup.value = true;
-		// VE_API.guard_tree.clockin(params).then((res) => {
-		// 	if (res.code === 0) {
-		// 		handleCancel();
-		// 		sucessPopup.value = true;
-		// 	}
-		// });
+		};
+		TREE.clockin(params).then((res) => {
+			if (res.code === 0) {
+				handleCancel();
+				sucessPopup.value = true;
+				emit('clockinCallback')
+			}
+		});
 	};
 
 	onMounted(() => {
@@ -156,6 +140,13 @@
 		() => {
 			showPopup.value = true;
 		}
+	);
+	
+	watch(
+		() => props.showSuccess,
+		() => {
+			handleSend()
+		}
 	);
 </script>
 
@@ -271,7 +262,11 @@
 	.sucess-popup {
 		width: 100vw;
 		height: 100vh;
-		background: rgba(0, 0, 0, 0.6);
+		background: rgba(0, 0, 0, 0.6);
+		.image{
+			width: 570rpx;
+			height: 480rpx;
+	    }
 
 		.sucess-bg {
 			width: 100%;
@@ -289,7 +284,8 @@
 
 		.button-group {
 			margin: 46rpx auto;
-			width: 312rpx;
+			width: 312rpx;
+
 			.btn {
 				font-size: 44rpx;
 				padding: 20rpx 0;
@@ -298,12 +294,12 @@
 				color: #954600;
 				background: linear-gradient(120deg, #FFE6B2, #FFC339);
 				text-align: center;
-			}
-			.close{
-				margin-top: 80rpx;
-				justify-content: center;
 			}
-		}
+
+			.close {
+				margin-top: 80rpx;
+				justify-content: center;
+			}
+		}
 	}
-	
 </style>

+ 23 - 14
pages/tabBar/tree/components/memberLevel.vue

@@ -9,14 +9,15 @@
 					<text class="name">V{{userLevel.id}} {{levelStr[userLevel.id]}}守护</text>
 					<view class="progress-wrap">
 						<view class="progress-value">
-							<view class="total"></view>
+							<view class="total" :style="{ width: calcWidth(userLevel.energy,userLevel.energyMax+1) }"></view>
 						</view>
 						<view class="progress-score">
 							<text class="cur-val">{{ userLevel.energy }}</text>/{{ userLevel.energyMax + 1 }}分
 						</view>
 					</view>
 					<view class="level-desc">
-						再累计能量<text class="level-text"> {{ userLevel.diffLevelEnergy }}分 </text>即可升级到 {{levelStr[Number(userLevel.id) + 1]}}等级
+						再累计能量 <text class="level-text">{{ userLevel.diffLevelEnergy }}分 </text>即可升级到
+						{{levelStr[Number(userLevel.id) + 1]}}等级
 					</view>
 				</view>
 			</view>
@@ -57,23 +58,31 @@
 		},
 	});
 	
-	const levelStr = {
-	    0: "平民",
-	    1: "青铜",
-	    2: "白银",
-	    3: "赤金",
-	    4: "星勋",
+	function calcWidth(energy,energyMax){
+	    let total = (energy / energyMax) * 100
+	    if(total>100){
+	        total = 100
+	    }
+	    return total + '%'
+	}
+
+	const levelStr = {
+		0: "平民",
+		1: "青铜",
+		2: "白银",
+		3: "赤金",
+		4: "星勋",
 	};
 
 	const userInfo = uni.getStorageSync('userInfo')
 	const userLevel = ref({})
 	watch(
 		() => props.treeData,
-		(newValue) => {
-			userLevel.value = {
-				...newValue.buyList[0].level,
-				energy:newValue.buyList[0].energy
-			}
+		(newValue) => {
+			userLevel.value = {
+				...newValue.buyList[0].level,
+				energy: newValue.buyList[0].energy
+			}
 		}
 	);
 </script>
@@ -107,7 +116,7 @@
 					width: 54%;
 
 					.name {
-						// color: #fff;
+						color: #fff;
 						font-family: 'PangMenZhengDao';
 					}
 

+ 2 - 2
pages/tabBar/tree/components/treeAlbumPopup.vue

@@ -10,7 +10,7 @@
 			</view>
 			<view class="album-cont">
 				<view class="time-line">
-					<view class="time-item" v-for="item in 6" :key="item">
+					<view class="time-item" v-for="(item,index) in 6" :key="index">
 						<text :style="{color:item==6?'#2199F8':'#777777'}">07/28</text>
 						<view class="dot" :style="{background:item==6?'#2199F8':'#777777'}"></view>
 						<text class="today" v-if="item==6">今</text>
@@ -18,7 +18,7 @@
 				</view>
 				<view class="swiper-wrap">
 					<swiper class="swiper">
-						<swiper-item v-for="(item,index) in list1">
+						<swiper-item v-for="(item,index) in list1" :key="index">
 							<image class="img" :src="item"></image>
 						</swiper-item>
 					</swiper>

+ 105 - 12
pages/tabBar/tree/tree.vue

@@ -24,9 +24,14 @@
 			</view>
 		</view>
 		<view class="tree-footer">
-			<view class="footer-item" v-for="(item,index) in footerList" :key="index">
-				<image class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`"></image>
-				<view class="name">{{item}}</view>
+			<view class="footer-item" v-for="(item,index) in footerList" :key="index" @click="handleItem(index)">
+				<view @click="requestSubscribe">
+					<button class="share-btn" open-type="share" v-if="index === 2">
+						<image class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`"></image>
+					</button>
+					<image v-else class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`"></image>
+					<view class="name">{{item}}</view>
+				</view>
 			</view>
 		</view>
 	</view>
@@ -36,20 +41,23 @@
 	<!-- 编辑树名称 -->
 	<editNamePopup></editNamePopup>
 	<!-- 海报弹窗 -->
-	<posterPopup :showPoster="showPoster" :farmBuyId="farmBuyId"></posterPopup>
+	<posterPopup :showPoster="showPoster" :farmBuyId="farmBuyId" :treeName="treeName"></posterPopup>
 	<!-- 果树成功弹窗 -->
 	<guardSuccessPopup :show="showGuardSuccess"></guardSuccessPopup>
 	<!-- 果树相册弹窗 -->
 	<tree-album-popup :show="showAlbum"></tree-album-popup>
 	<!-- 等级升级成功弹窗 -->
-	<levelSuccessPopup></levelSuccessPopup>
+	<levelSuccessPopup></levelSuccessPopup>
+	<!-- 祝福弹窗 -->
+	<blessingsPopup :show="showBlessingsPopup" :showSuccess="showSuccess" :farmBuyId="farmBuyId" :clockinType="clockinType" @clockinCallback="getBySampleId"></blessingsPopup>
 </template>
 
 <script setup>
 	import config from "@/api/config.js"
-	import { onLoad } from '@dcloudio/uni-app'
+	import { onLoad ,onShareAppMessage} from '@dcloudio/uni-app'
 	import memberLevel from "./components/memberLevel.vue"
 	import treeAlbumPopup from "./components/treeAlbumPopup.vue"
+	import blessingsPopup from "./components/blessingsPopup.vue"
 	import TREE from '@/api/tree.js'
 	import {
 		ref,
@@ -121,11 +129,17 @@
 	
 	const treeData = ref({})
 	const farmBuyId = ref('')
+	const treeName = ref('')
+	const userInfo = uni.getStorageSync('userInfo')
 	const getBySampleId = () =>{
-		//81317  88891
-		TREE.getBySampleId({sampleId:172055}).then(res =>{
-			treeData.value = res.data || {}
-			farmBuyId.value = res.data.buyList[0].id
+		TREE.getBySampleId({sampleId:172055}).then(({data}) =>{
+			treeData.value = data || {}
+			if(userInfo.tel){
+				treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length?data.buyList[0].nickname.slice(0, 3)+"荔": data.buyList[0].owner.slice(0, 3)+"荔")
+			}else{
+				treeName.value = '飞鸟守护'
+			}
+			farmBuyId.value = data.buyList[0].id
 		})
 	}
 	
@@ -144,7 +158,79 @@
 			});
 		}
 	}
-	const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
+	const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
+	const showBlessingsPopup = ref(false)
+	const showSuccess = ref(false)
+	const clockinType = ref('1')
+	const handleItem = (index) =>{
+		if(index === 0){
+			clockinType.value = 1
+			if(treeData.value.buyList[0].level.clockinMap['1']){
+				uni.showToast({
+					title: '今日已守护',
+					icon:'none',
+					duration: 2000
+				});
+			}else{
+				showSuccess.value = !showSuccess.value
+			}
+		}else if(index === 1){
+			clockinType.value = 3
+			if(treeData.value.buyList[0].level.clockinMap['3']){
+				uni.showToast({
+					title: '今日已送过祝福',
+					icon:'none',
+					duration: 2000
+				});
+			}else{
+				showBlessingsPopup.value = !showBlessingsPopup.value
+			}
+		}else if(index === 2){
+			clockinType.value = 2
+			if(!treeData.value.buyList[0].level.clockinMap['2']){
+				showSuccess.value = !showSuccess.value
+			}
+		}else{
+			console.log('123')
+		}
+	}
+	
+	function requestSubscribe() {
+		// #ifdef MP-WEIXIN
+	    //订阅模板
+	    TREE.getSubscribeTemplate({id:1}).then(({data}) =>{
+	      uni.requestSubscribeMessage({
+	        tmplIds: [data.templateId], // 模板ID
+	        success(res) {
+	          if (res[data.templateId] === 'accept') {
+	            TREE.addSubscribe({templateId:1})
+	          } else if (res[data.templateId] === 'reject') {
+	            console.log('用户拒绝订阅模板');
+	          }
+	        },
+	        fail(err) {
+	          uni.openSetting({
+	            withSubscriptions: true, // 显示订阅消息开关
+	          });
+	        },
+	      });
+	    })
+		// #endif
+	}
+	
+	onShareAppMessage((res) => {
+	  if (res.from === 'button') {
+		  const params = {
+		    sampleId:treeData.value.buyList[0].sampleId,
+		    farmId:treeData.value.buyList[0].farmId,
+		  }
+		  return {
+		    title: '我分享了我的果树,快来查看吧~',
+		    path: `/pages/tabBar/tree/subPages/friendTree?params=${JSON.stringify(params)}`, // 分享的小程序页面路径  
+		    imageUrl:`http://birdseye-api.feiniaotech.sysuimars.cn/mini/z_farm_buy/genImage/${farmBuyId.value}?key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9&x1=25&y1=220&fontSize1=40&x2=55&y2=250&fontSize2=16&timestamp=${Date.now()}`,
+		  }
+	  }
+	})
 </script>
 
 <style lang="scss" scoped>
@@ -270,7 +356,14 @@
 
 			.footer-item {
 				width: 18%;
-				text-align: center;
+				text-align: center;
+				.share-btn{
+					background: transparent;
+					display: inline-flex;
+					&::after{
+						border: none;
+					}
+				}
 
 				.icon {
 					width: 96rpx;