ソースを参照

地址接入冲突解决

贾宇博 3 週間 前
コミット
1ca3e6fcc6
共有1 個のファイルを変更した37 個の追加20 個の削除を含む
  1. 37 20
      pages/index.vue

+ 37 - 20
pages/index.vue

@@ -1,9 +1,7 @@
 <template>
 	<view class="main-content">
 		<view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
-			<view class="home-banner-left">
-				<!-- <img src="/static/serverImg/home/address.png" alt=""
-					style="width: 41.67rpx;height:  41.67rpx;margin-right: 8rpx;"> -->
+			<view class="home-banner-left" @click="cityClick">
 				<up-icon name="map" color="#fff" size="25"></up-icon>
 				<text>{{ data.address }}</text>
 			</view>
@@ -65,7 +63,8 @@
 	import {
 		onLoad,
 		onShow,
-		onReachBottom
+		onReachBottom,
+		onUnload
 	} from "@dcloudio/uni-app";
 	import RankingList from '@/pages/common/rankingList/index.vue';
 	import ServIces from "@/components/Services/services.vue"
@@ -113,6 +112,12 @@
 		serviceCategory: '',
 		// appStatus:"2",
 	})
+	
+const cityClick = () => {
+	console.log('cityClick', data.address);
+	citySelectorNavigateTo(data.address)
+}
+
 
 	const loadmoreInfo = ref({
 		status: 'loadmore',
@@ -207,23 +212,35 @@
 	}
 
 	onShow(() => {
-		getList()
-		getBanners();
-		// getListData()
-		// 在 App.vue  中初始化 
-		uni.getSystemInfo({
-			success: (res) => {
-				const statusBarHeight = res.statusBarHeight;
-				const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
-				globalData.value = {
-					statusBarHeight,
-					navBarHeight
-				};
-				console.log('statusBarHeight', statusBarHeight, navBarHeight);
+	getList()
+	getBanners();
 
-			}
-		});
-	})
+	// 在 App.vue  中初始化 
+	uni.getSystemInfo({
+		success: (res) => {
+			const statusBarHeight = res.statusBarHeight;
+			const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
+			globalData.value = { statusBarHeight, navBarHeight };
+			console.log('statusBarHeight', statusBarHeight, navBarHeight);
+
+		}
+	});
+
+	if (citySelector) {
+		const selectedCity = citySelector.getCity(); // 如果点击确认选点按钮,则返回选点结果对象,否则返回null
+		console.log('citySelector', selectedCity,selectedCity.name)
+		data.address = selectedCity.name;
+	}
+
+})
+
+onUnload(() => {
+	if (citySelector) {
+		// 页面卸载时设置插件选点数据为null,防止再次进入页面,geLocation返回的是上次选点结果
+		citySelector.setLocation(null);
+	}
+
+})
 </script>
 
 <style scoped lang="scss">