diff --git a/App.vue b/App.vue index 4b22795..6b41c6c 100644 --- a/App.vue +++ b/App.vue @@ -19,32 +19,11 @@ // console.log('App Hide'); }, methods: { - async userlogin() { - uni.login({ - provider: 'weixin', - success: (data) => { - uni.getUserInfo({ - provider: 'weixin', - success: async (infoRes) => { - uni.cache.set('weixincode', data.code); - let res = await this.api.userwxlogin({ - code: uni.cache.get('weixincode'), //临时登录凭证 - rawData: infoRes.rawData, - }) - if (res.code == 0) { - uni.cache.set('token', res.data.token); - uni.cache.set('miniAppOpenId', res.data.userInfo - .miniAppOpenId) - uni.cache.set('userInfo', res.data.userInfo); - } - }, - fail: (err) => {} - }); - } - }); - - }, - + userlogin() { + if (!uni.cache.get('token')) { + this.$store.dispatch("loginEvent"); //获取shapid + } + } } }; diff --git a/framework/11-api.js b/framework/11-api.js index 08d6eb4..c90a6a9 100644 --- a/framework/11-api.js +++ b/framework/11-api.js @@ -1,7 +1,7 @@ import { fill } from "lodash" - +import store from "../store" const preCacheKeyClearFetch = 'storage:clear:fetch:' uni.pro.interceptor('request', { @@ -104,17 +104,14 @@ async function request(options) { if (res.code != 0) { if (res.code == -4) { uni.showToast({ - title: res.message || res.msg, - icon: "none" - // success: () => { - // setTimeout(res => { - // uni.cache.set('token', ''); - // uni.redirectTo({ - // url: '/pages/login/login' - // }); - // }, 1000) - - // } + title: '', + // title: res.message || res.msg, + icon: "none", + success: () => { + setTimeout(res => { + store.dispatch("loginEvent"); //获取shapid + }, 1000) + } }) } else if (res.code == 482) { let nowTime = new Date() / 1000 | 0 diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue index 267d862..0dba44e 100644 --- a/pages/index/indexs.vue +++ b/pages/index/indexs.vue @@ -14,7 +14,7 @@ 会员 - 入会项权益 + 入会享权益 diff --git a/pages/user/information.vue b/pages/user/information.vue index 1e5d78a..7684f85 100644 --- a/pages/user/information.vue +++ b/pages/user/information.vue @@ -170,7 +170,7 @@ let res = await this.api.upUserInfo({ headImg: this.userHeadImg, nickName: this.nickName, - telephone: this.phonetitle + telephone: this.phonetitle == '请授权手机号' ? '' : this.phonetitle }) if (res.code == 0) { uni.navigateBack() diff --git a/store/index.js b/store/index.js index 97d3751..d61ce3f 100644 --- a/store/index.js +++ b/store/index.js @@ -61,6 +61,31 @@ const store = new Vuex.Store({ }, }, actions: { + loginEvent: () => { + uni.login({ + provider: 'weixin', + success: (data) => { + uni.getUserInfo({ + provider: 'weixin', + success: async (infoRes) => { + uni.cache.set('weixincode', data.code); + let res = await Api.userwxlogin({ + code: uni.cache.get('weixincode'), //临时登录凭证 + rawData: infoRes.rawData, + }) + if (res.code == 0) { + uni.cache.set('token', res.data.token); + uni.cache.set('miniAppOpenId', res.data.userInfo + .miniAppOpenId) + uni.cache.set('userInfo', res.data.userInfo); + } + }, + fail: (err) => {} + }); + } + }); + + }, set_shopid: async ({ commit }, data) => {