From f39ca3c49d26abd10f76fc67506b9c603a13547c Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 17 四月 2026 20:20:30 +0800
Subject: [PATCH] 调接口加页面

---
 small-program/App.vue |  157 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 122 insertions(+), 35 deletions(-)

diff --git a/small-program/App.vue b/small-program/App.vue
index 8224997..91b4fc3 100644
--- a/small-program/App.vue
+++ b/small-program/App.vue
@@ -3,40 +3,45 @@
 	var QQMapWX = require('@/utils/qqmap-wx-jssdk.js')
 	export default {
 		computed: {
-			...mapState(['userInfo','openid'])
+			...mapState(['userInfo','token'])
 		},
-		onLaunch: function() {  
-			// var that = this;
-			// if (!this.openid || this.openid =='') {
-			// 	uni.login({
-			// 		provider: 'weixin',
-			// 		success: async function (loginRes) {
-			// 			let { code } = loginRes;
-			// 			let res = await that.$u.api.wxLogin({ code })
-			// 			if (res && res.code === 200) {
-			// 				that.$store.commit('setToken', res.data.token)
-			// 				that.$store.commit('setOpenid', res.data.openid)
-			// 				that.$store.commit('setUserInfo', res.data.member)
-							
-			// 			}
-			// 		}
-			// 	});
-			// } else {
-			// 	var that = this
-			// 	let res = this.$u.api.getMemberInfo({}).then(res =>{ 
-			// 		if (res && res.code === 200) { 
-			// 			that.$store.commit('setUserInfo', res.data) 
-			// 		} else {
-			// 			that.$store.commit('setToken','')
-			// 			that.$store.commit('setUserInfo',{}) 
-			// 		}
-			// 	})
-			// }
-			// uni.showShareMenu({
-			//   withShareTicket: true,
-			//   menus: ['shareAppMessage', 'shareTimeline']
-			// })
-
+		onLaunch: async function() {
+			var that = this;
+			if (!this.token) {
+				uni.login({
+					provider: 'weixin',
+					success: async function (loginRes) {
+						let { code } = loginRes;
+						let res = await that.$u.api.wxLogin({ code })
+						if (res && res.code === 200) {
+							// 鍒ゆ柇鏈夋棤openid
+							if (res.data.openid) {
+								await that.$store.commit('setOpenId', res.data.openid)
+							}
+							// 鍒ゆ柇鏈夋棤token
+							if (res.data.token) {
+								await that.$store.commit('setToken', res.data.token)
+							}
+							// 鍒ゆ柇鏈夋棤鐢ㄦ埛淇℃伅
+							if (res.data.member) {
+								await that.$store.commit('setUserInfo', res.data.member)
+								await that.$store.commit('setOpenId', res.data.member.openId)
+							}
+							// 璁剧疆瀹氫綅
+							await that.checkLocationAuth()
+						}
+					}
+				});
+			} else {
+				// 缂撳瓨鐢ㄦ埛淇℃伅
+				let res = await that.$u.api.getMemberInfo({})
+				if (res.code === 200) {
+					await that.$store.commit('setUserInfo', res.data)
+					await that.$store.commit('setOpenId', res.data.openId)
+				}
+				// 璁剧疆瀹氫綅
+				await that.checkLocationAuth()
+			}
 		},
 		onShow: function() {
 			// this.getLocaltionBiz() 
@@ -45,6 +50,89 @@
 			console.log('App Hide')
 		},
 		methods:{
+			// 瀹氫綅
+			positioning() {
+				var that = this;
+				uni.getLocation({
+					type: 'gcj02',
+					highAccuracyExpireTime: 3000,
+					isHighAccuracy: true,
+					success: function (addr) {
+						const locParam = { latitude: addr.latitude, longitude: addr.longitude };
+						const qqmapsdk = new QQMapWX({
+							key: 'WE3BZ-HN6WS-ONDOH-62QCV-MNL6F-5NFNE'
+						});
+						qqmapsdk.reverseGeocoder({
+							locParam,
+							success: async function(res) {
+								console.log(res, '==================鑾峰彇鍦板潃');
+								let info = res.result;
+								locParam.province = info.address_component.province;
+								locParam.city = info.address_component.city;
+								locParam.area = info.address_component.district;
+								locParam.street = info.address_component.street;
+								var ta = info.address  || '鍦板潃鑾峰彇澶辫触' ;
+								if(info.formatted_addresses  && info.formatted_addresses.recommend){
+									ta =info.formatted_addresses.recommend
+								}
+								locParam.address =ta	
+								const resCity = await that.$u.api.getCityByName({ cityName: locParam.city })
+								if (resCity.code === 200) {
+									locParam.cityId = resCity.data.id
+								}										
+								that.$store.commit('setPosition',locParam)
+								that.$isResolve()
+							},
+							fail: (err) => {
+								console.error('鑾峰彇浣嶇疆澶辫触===========', err);
+								that.$store.commit('setPosition',locParam)
+								that.$isResolve()
+							}
+						});
+					}
+				});
+			},
+			goToAppSetting() {
+				var that = this;
+			    uni.openSetting({
+			        success: (res) => {
+						if (res.authSetting['scope.userLocation']) {
+							that.positioning()
+						}
+						that.$isResolve()
+			        }
+			    });
+			},
+			checkLocationAuth() {
+			    uni.getSetting({
+			        success: (res) => {
+			            if (!res.authSetting['scope.userLocation']) {
+			                uni.authorize({
+			                    scope: 'scope.userLocation',
+			                    success: () => {
+			                        this.positioning()
+			                    },
+			                    fail: () => {
+			                        uni.showModal({
+			                            title: '鎻愮ず',
+			                            content: '闇�瑕佽幏鍙栨偍鐨勪綅缃俊鎭紝璇峰湪璁剧疆涓紑鍚綅缃潈闄�',
+			                            confirmText: '鍘昏缃�',
+			                            success: (res) => {
+			                                if (res.confirm) {
+			                                    this.goToAppSetting();
+			                                } else {
+												this.$isResolve()
+											}
+			                            }
+			                        });
+			                    }
+			                });
+			            } else {
+			                this.positioning()
+			            }
+			        }
+			    });
+			},
 			getLocaltionBiz(){
 				var that =this
 				uni.getLocation({
@@ -54,7 +142,7 @@
 						uni.setStorageSync('address', locParam);
 						var address =null
 						const qqmapsdk = new QQMapWX({
-							 key: '4PXBZ-JLBC7-LCLXG-P2SZX-C4HYE-LDBLQ' //鑵捐鍦板浘鐢宠鐨刱ey锛堝悗缁渶瑕佸叕鍙告彁渚涳紝涓汉寮�鍙戣�呴搴︽湁闄愶級
+							 key: 'WE3BZ-HN6WS-ONDOH-62QCV-MNL6F-5NFNE' //鑵捐鍦板浘鐢宠鐨刱ey锛堝悗缁渶瑕佸叕鍙告彁渚涳紝涓汉寮�鍙戣�呴搴︽湁闄愶級
 						 });  
 						  // 鑵捐鍦板浘閫嗗湴鐞嗙紪鐮�
 						qqmapsdk.reverseGeocoder({
@@ -80,7 +168,6 @@
 								that.$isResolve()
 							}
 						});
-						// that.$store.commit('setPosition',locParam)
 						that.$isResolve()
 					},
 					fail: (err) => {

--
Gitblit v1.9.3