整合应用进入判断

This commit is contained in:
aixianling
2022-06-29 17:59:29 +08:00
parent 4f1592540e
commit 2655a44573
3 changed files with 34 additions and 26 deletions

View File

@@ -11,6 +11,7 @@
<script>
import tools from '../utils/util'
import {mapActions} from "vuex"
export default {
name: 'AiLogin',
@@ -22,6 +23,7 @@ export default {
}
},
methods: {
...mapActions(['autoLogin']),
show() {
tools.$getUserProfile().then(data => {
this.userData = data.userInfo;
@@ -45,7 +47,7 @@ export default {
}, {withoutToken: true}).then(d => {
if (d.data) {
let data = {...this.userData, phone: d.data};
this.$autoLogin(data, this.$store).then(res => {
this.autoLogin(data, this.$store).then(res => {
this.$emit("success", res);
});
}

View File

@@ -61,6 +61,37 @@ export const user = {
if (count <= 3) {
return dispatch("getCode").then(code => dispatch("getToken", code).catch(() => dispatch("autoLogin", ++count)))
} else return Promise.reject("登录失败,请联系管理员")
},
authCheck({state, dispatch}, {checkType, modulePath}) {
//用于进入应用的权限判断
//checkType 1、登录认证 2、居民认证 3、党员认证
//判断是否需要校验认证信息
let {token, user: userInfo} = state
if (!checkType) {
//如果需要校验认证信息,必定要先验证是否登录
uni.navigateTo({url: modulePath});
} else if (checkType == 1) {
if (!token) {
return dispatch('autoLogin');
}
uni.navigateTo({url: modulePath});
} else if (checkType == 2) {
if (!token) {
return dispatch('autoLogin');
}
if (!(userInfo.residentId && userInfo.status == 2)) {
return uni.navigateTo({url: '/mods/AppAuth/AppAuth'});
}
uni.navigateTo({url: modulePath});
} else if (checkType == 3) {
if (!token) {
return dispatch('autoLogin');
}
if (!userInfo.partyId) {
return uni.showToast({title: "您还不是党员,暂时无法使用该功能", icon: "none"});
}
uni.navigateTo({url: modulePath});
}
}
}
}

View File

@@ -328,30 +328,6 @@ const $getLoginCode = () => {
});
};
const $autoLogin = (params, store) => {
params = params ? params : {};
return new Promise(function (resolve, reject) {
$getLoginCode().then((res) => {
let body = {...params, code: res.code};
store.commit('getToken', {
...body,
then: (v1) => {
if (v1) {
store.commit('getUserInfo', (v2) => {
if (v2) {
resolve(v2);
} else {
reject(v2);
}
});
} else {
reject(v1);
}
}
});
});
});
};
export default {
$toast,
$loading,
@@ -366,6 +342,5 @@ export default {
$dayjs,
$dict,
$getLoginCode,
$autoLogin,
$qs
};