From a987eccb27891bbfaae334b7fa0e892ee2640271 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期一, 20 四月 2026 17:20:13 +0800
Subject: [PATCH] 调接口加页面
---
small-program/App.vue | 134 ++++++++++++++++++++++++++++++++++++--------
1 files changed, 109 insertions(+), 25 deletions(-)
diff --git a/small-program/App.vue b/small-program/App.vue
index 931fcfe..98f7ec4 100644
--- a/small-program/App.vue
+++ b/small-program/App.vue
@@ -3,49 +3,134 @@
var QQMapWX = require('@/utils/qqmap-wx-jssdk.js')
export default {
computed: {
- ...mapState(['userInfo','openid'])
+ ...mapState(['userInfo','token'])
},
- onLaunch: function() {
+ onLaunch: async function() {
var that = this;
- if (!this.openid || this.openid =='') {
+ 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) {
- that.$store.commit('setToken', res.data.token)
- that.$store.commit('setOpenid', res.data.openid)
- that.$store.commit('setUserInfo', res.data.member)
-
+ // 鍒ゆ柇鏈夋棤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 {
- 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',{})
- }
- })
+ // 缂撳瓨鐢ㄦ埛淇℃伅
+ 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()
}
- uni.showShareMenu({
- withShareTicket: true,
- menus: ['shareAppMessage', 'shareTimeline']
- })
-
},
onShow: function() {
- console.log('App Show')
- this.getLocaltionBiz()
+ // this.getLocaltionBiz()
},
onHide: function() {
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) => {
+ 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({
@@ -55,7 +140,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({
@@ -81,7 +166,6 @@
that.$isResolve()
}
});
- // that.$store.commit('setPosition',locParam)
that.$isResolve()
},
fail: (err) => {
--
Gitblit v1.9.3