Refactor(登录):登录按钮去掉判断逻辑,一直显示

This commit is contained in:
lifizer
2024-10-17 10:05:39 +08:00
parent ca11455148
commit b0ac014816
2 changed files with 31 additions and 34 deletions
+29 -32
View File
@@ -131,7 +131,7 @@
<view class="v12-mt-3 v12-font-32 v12-dark-text v12-font-weight-600">发现家乡好物</view>
</view>
<view class="btn-box">
<button class="btn-yes v12-primary" type="mini" v-if="canIUseGetUserProfile" @tap="getUserInfoProfile">快捷登录</button>
<button class="btn-yes v12-primary" type="mini" @tap="getUserInfoProfile">快捷登录</button>
<!-- <button class="btn-no" type="default" @tap="back">拒绝</button> -->
</view>
<view class="agree-box v12-align-center">
@@ -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;
+2 -2
View File
@@ -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);