diff --git a/pages/authorization/index.vue b/pages/authorization/index.vue index 3e20c40..8c85273 100644 --- a/pages/authorization/index.vue +++ b/pages/authorization/index.vue @@ -131,7 +131,7 @@ 发现家乡好物 - + @@ -171,7 +171,6 @@ export default { return { webUrl: this.$VUE_APP_RESOURCES_URL, authorize: false, - canIUseGetUserProfile: false, agreeInfo: {}, isAgree: [], show: false, @@ -188,9 +187,6 @@ export default { ...mapState(['isAuthorization', '$deviceType', 'token']), }, onLoad() { - if (wx.getUserProfile) { - this.canIUseGetUserProfile = true - } // 先校验用户是否授权,如果没有授权,显示授权按钮 getAgree().then(({data}) => this.agreeInfo = data); }, @@ -227,18 +223,19 @@ export default { }) }, doneRedirect() { - let redirectUrl = cookie.get('redirect') || ""; - redirectUrl = redirectUrl.replace(/\ /g, ''); - //如果已经是授权页,跳转主页 + let redirectUrl = cookie.get('redirect') || '' + redirectUrl = redirectUrl.replace(/\ /g, '') + // 如果已经是授权页,跳转主页 if (redirectUrl == '/pages/authorization/index' || redirectUrl.length === 0) { - redirectUrl = '/pages/home/index'; + redirectUrl = '/pages/home/index' } this.$yrouter.reLaunch({ - path: redirectUrl, + path: redirectUrl }) }, getUserInfoProfile() { - if (!this.isAgree[0]) { + const _this = this + if (!_this.isAgree[0]) { uni.showToast({ title: "请先阅读并同意《用户服务协议及隐私政策》", icon: "none", @@ -246,33 +243,33 @@ export default { }) return } - wx.getUserProfile({ lang: 'zh_CN', desc: '需要获取您的信息用来展示', success: res => { - uni.showLoading({ - title: '登录中', - }) - login(res).then(e => { - let db_nickname = e.data.nickname; - - if (db_nickname === null || db_nickname === undefined || db_nickname === "" || db_nickname === "微信用户") { - this.showFillOut = true; - } else { - this.doneRedirect(); - } - }).catch(error => { - uni.showToast({ - title: error, - icon: 'none', - duration: 2000, - }) - }) - }, + _this.loginReq(res) + } + }) + }, + loginReq(res) { + uni.showLoading({ + title: '登录中' + }) + login(res).then(e => { + const db_nickname = e.data.nickname + if (db_nickname === null || db_nickname === undefined || db_nickname === '' || db_nickname === '微信用户') { + this.showFillOut = true + } else { + this.doneRedirect() + } + }).catch(error => { + uni.showToast({ + title: error, + icon: 'none', + duration: 2000 + }) }) }, - onChooseAvatar(e) { const {avatarUrl} = e.detail; this.avatarUrl = avatarUrl; diff --git a/utils/index.js b/utils/index.js index 19ce8a4..dab02a6 100644 --- a/utils/index.js +++ b/utils/index.js @@ -924,10 +924,10 @@ export const handleLoginFailure = () => { store.commit("logout"); store.commit("updateAuthorization", false); - let currentPageUrl = getCurrentPageUrl() + const currentPageUrl = getCurrentPageUrl() // token 失效 // 判断当前是不是已经在登录页面或者授权页,防止二次跳转 - if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') { + if (store.getters.isAuthorizationPage || currentPageUrl == '/pages/user/Login/index' || currentPageUrl === '/pages/authorization/index') { return } store.commit("updateAuthorizationPage", true);