Kaynağa Gözat

feat: 首页和逛一逛跳转

lxf 3 hafta önce
ebeveyn
işleme
2545a957b9

+ 35 - 10
pages/tabBar/discover/discover.vue

@@ -8,16 +8,16 @@
 			</view>
 
 			<view class="type-wrap">
-				<up-scroll-list :indicator="typeList.length>5" indicatorColor="#FF770033" indicatorActiveColor="#FF7700" :indicatorWidth="30"
+				<up-scroll-list :indicator="typeList && typeList.length>5" indicatorColor="#FF770033" indicatorActiveColor="#FF7700" :indicatorWidth="30"
 					:indicatorBarWidth="15">
-					<view class="item-type" :class="{'active': activeType === 0}" @click="handleSelectType(null, 0)">
+					<view class="item-type" :class="{'active': activeType === 0}" @click="handleSelectType(0)">
 						<image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
 						<view class="type-text">
 							全部
 						</view>
 					</view>
 					<view class="item-type" v-for="(item, index) in typeList"
-						:class="{'active': activeType === index+1}" :key="index" @click="handleSelectType(item.id, index+1)">
+						:class="{'active': activeType === item.id}" :key="index" @click="handleSelectType(item.id)">
 						<image class="type-img" :src="item.image" alt="" />
 						<view class="type-text">
 							{{item.name}}
@@ -77,6 +77,10 @@
 					</view>
 				</view>
 			</view>
+			
+			<view class="no-data" v-if="!discoverData||!discoverData.length">
+				暂未上架商品,请耐心等候
+			</view>
 		</view>
 	</view>
 </template>
@@ -88,6 +92,7 @@
 	} from "vue";
 	import config from "@/api/config.js"
 	import HOME from "@/api/home.js"
+	import { onShow } from "@dcloudio/uni-app"
 
 	const typeSearch = ref(null)
 
@@ -111,8 +116,18 @@
 		orderType.value = !orderType.value
 		getGoodsList()
 	}
+	
+	onShow(() => {
+		 const selectedType = uni.getStorageSync('selectedCategoryType');
+			if (selectedType) {
+				activeType.value = selectedType
+				uni.setStorageSync('selectedCategoryType', 0);
+				handleSelectType(selectedType||0)
+			}
+	})
 
 	onMounted(() => {
+		console.log('onMounted')
 		getTypeList()
 		getGoodsList()
 	})
@@ -124,7 +139,7 @@
 		HOME.fetchTypeList().then(({
 			data
 		}) => {
-			typeList.value = [...data, ...data]
+			typeList.value = data
 		})
 	}
 
@@ -140,12 +155,12 @@
 		HOME.fetchGoodsList(params).then(({
 			data
 		}) => {
-			discoverData.value = [...data, ...data]
+			discoverData.value = data
 		})
 	}
 	
-	function handleSelectType(id, index) {
-		activeType.value = index
+	function handleSelectType(id) {
+		activeType.value = id
 		let params = {}
 		if (id) {
 			params = {
@@ -216,10 +231,10 @@
 			}
 
 			.type-wrap {
-				padding: 0 20rpx 20rpx;
+				padding: 0 20rpx 0 20rpx;
 				background-color: #fff;
 				border-radius: 16rpx;
-				height: 200rpx;
+				height: 186rpx;
 				box-sizing: border-box;
 				
 				// 覆盖 up-scroll-list 的默认样式,实现两端对齐
@@ -230,6 +245,11 @@
 					width: 100%;
 					min-width: 100%;
 				}
+				::v-deep {
+					.u-scroll-list__indicator {
+						margin-top: 16rpx;
+					}
+				}
 
 				.item-type {
 					text-align: center;
@@ -262,11 +282,16 @@
 
 		.discover-content {
 			padding: 0rpx 24rpx 24rpx;
-			height: calc(100% - 352rpx);
+			height: calc(100% - 320rpx);
 			overflow: auto;
 			background: #F2F3F5;
 			box-sizing: border-box;
 
+			.no-data {
+				text-align: center;
+				color: rgba(0, 0, 0, 0.6);
+				font-size: 28rpx;
+			}
 			.discover-filter {
 				color: #A6A6A6;
 				font-size: 28rpx;

+ 10 - 13
pages/tabBar/home/home.vue

@@ -3,7 +3,7 @@
 		<view class="home-top">
 			<view class="home-search">
 				<view class="search-wrap">
-					<up-search placeholder="搜索农场名称" v-model="typeSearch"></up-search>
+					<up-search placeholder="搜索品种" v-model="typeSearch"></up-search>
 				</view>
 			</view>
 			<div class="home-box" @click="toPage('allGardenMap')">
@@ -19,13 +19,13 @@
 		<view class="type-wrap">
 			<up-scroll-list :indicator="typeList && typeList.length>5" indicatorColor="#F3C11D33" indicatorActiveColor="#F3C11D"
 				:indicatorWidth="30" :indicatorBarWidth="13" ref="scrollListRef">
-				<view class="item-type">
+				<view class="item-type" @click="toTabBar(0)">
 					<image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
 					<view class="type-text">
 						全部
 					</view>
 				</view>
-				<view class="item-type" v-for="(item, index) in typeList" :key="index">
+				<view class="item-type" v-for="(item, index) in typeList" :key="index" @click="toTabBar(item.id)">
 					<image class="type-img" :src="item.image" alt="" />
 					<view class="type-text">
 						{{item.name}}
@@ -241,12 +241,6 @@
 		console.log('onLoad')
 		
 		try {
-			// 显示全局加载状态
-			uni.showLoading({
-				title: '加载中...',
-				mask: true
-			})
-			
 			// 【核心修改】等待token准备就绪
 			await userStore.getTokenSafe()
 			console.log('登录成功,token已就绪')
@@ -255,12 +249,8 @@
 			await getTypeList()
 			await getFarmData()
 			
-			// 隐藏加载状态
-			uni.hideLoading()
 		} catch (error) {
 			console.error('初始化失败:', error)
-			// 隐藏加载状态
-			uni.hideLoading()
 			// 登录失败处理,可以跳转到登录页或显示提示
 			uni.showToast({
 				title: '请先登录',
@@ -277,6 +267,13 @@
 			console.error('获取类型列表失败:', error)
 		}
 	}
+	
+	function toTabBar(typeId) {
+		uni.setStorageSync('selectedCategoryType', typeId);
+		 uni.switchTab({
+			url: '/pages/tabBar/discover/discover',
+		});
+	}
 
 	async function getFarmData() {
 		try {

+ 4 - 4
pages/tabBar/home/subPages/allGardenMap.vue

@@ -14,10 +14,10 @@
 	const webViewUrl = ref('')
 
 	onMounted(() => {
-		webViewUrl.value =
-			`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/allGardenMap?userId=${userInfo.id}&token=${userInfo.token}`
-		// webViewUrl.value = "http://localhost:8081/#/allGardenMap?userId=91754&token=034d7cf5-25fc-42d3-993e-460120419e5a"
 		// webViewUrl.value =
-		// 	`http://localhost:8081/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isFromScan=true`
+		// 	`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/allGardenMap?userId=${userInfo.id}&token=${userInfo.token}`
+		// webViewUrl.value = "http://localhost:8081/#/allGardenMap?userId=91754&token=034d7cf5-25fc-42d3-993e-460120419e5a"
+		webViewUrl.value =
+			`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isFromScan=true`
 	})
 </script>

+ 3 - 3
pages/tabBar/home/subPages/gardenMap.vue

@@ -20,9 +20,9 @@
 				`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&enterSelectTree=true`
 			// webViewUrl.value = "http://localhost:8081/#/gardenMap?userId=91754&token=034d7cf5-25fc-42d3-993e-460120419e5a&enterSelectTree=true"
 		} else if (isScanAuthSuccess) {
-			// webViewUrl.value =
-			// 	`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isScanAuthSuccess=true`
-				webViewUrl.value = `http://localhost:8081/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isScanAuthSuccess=true`
+			webViewUrl.value =
+				`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isScanAuthSuccess=true`
+				// webViewUrl.value = `http://localhost:8081/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}&isScanAuthSuccess=true`
 		} else {
 			webViewUrl.value =
 				`https://feiniao-mini-h5-dev.sysuimars.cn/youwei/#/gardenMap?userId=${userInfo.id}&token=${userInfo.token}`

+ 1 - 0
store/user.js

@@ -39,6 +39,7 @@ export const useUserStore = defineStore('user', () => {
       loginData = data
       // #endif
 		uni.setStorageSync('userInfo', loginData);
+		uni.setStorageSync('token', loginData.token);
       if (loginData) {
         const { token: newToken, ...userData } = loginData