瀏覽代碼

地址接入冲突解决

贾宇博 3 周之前
父節點
當前提交
1ca3e6fcc6
共有 1 個文件被更改,包括 37 次插入20 次删除
  1. 37 20
      pages/index.vue

+ 37 - 20
pages/index.vue

@@ -1,9 +1,7 @@
 <template>
 <template>
 	<view class="main-content">
 	<view class="main-content">
 		<view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
 		<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>
 				<up-icon name="map" color="#fff" size="25"></up-icon>
 				<text>{{ data.address }}</text>
 				<text>{{ data.address }}</text>
 			</view>
 			</view>
@@ -65,7 +63,8 @@
 	import {
 	import {
 		onLoad,
 		onLoad,
 		onShow,
 		onShow,
-		onReachBottom
+		onReachBottom,
+		onUnload
 	} from "@dcloudio/uni-app";
 	} from "@dcloudio/uni-app";
 	import RankingList from '@/pages/common/rankingList/index.vue';
 	import RankingList from '@/pages/common/rankingList/index.vue';
 	import ServIces from "@/components/Services/services.vue"
 	import ServIces from "@/components/Services/services.vue"
@@ -113,6 +112,12 @@
 		serviceCategory: '',
 		serviceCategory: '',
 		// appStatus:"2",
 		// appStatus:"2",
 	})
 	})
+	
+const cityClick = () => {
+	console.log('cityClick', data.address);
+	citySelectorNavigateTo(data.address)
+}
+
 
 
 	const loadmoreInfo = ref({
 	const loadmoreInfo = ref({
 		status: 'loadmore',
 		status: 'loadmore',
@@ -207,23 +212,35 @@
 	}
 	}
 
 
 	onShow(() => {
 	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>
 </script>
 
 
 <style scoped lang="scss">
 <style scoped lang="scss">