|
@@ -4,6 +4,9 @@ import router from './router'
|
|
import store from '$project/store'
|
|
import store from '$project/store'
|
|
|
|
|
|
import * as API_User from '$project/apis/user'
|
|
import * as API_User from '$project/apis/user'
|
|
|
|
+import {
|
|
|
|
+ clear,
|
|
|
|
+} from '$project/utils/storage'
|
|
|
|
|
|
//引入mui
|
|
//引入mui
|
|
import mui from '$project/assets/js/mui.js'
|
|
import mui from '$project/assets/js/mui.js'
|
|
@@ -88,7 +91,7 @@ function getFunList() {
|
|
|
|
|
|
const auth = (to, from, next) => {
|
|
const auth = (to, from, next) => {
|
|
if (to.meta != null && to.meta.requireAuth) {
|
|
if (to.meta != null && to.meta.requireAuth) {
|
|
- if (store.state.person_data) {
|
|
|
|
|
|
+ if (store.state.person_data || store.state.fun_list) {
|
|
|
|
|
|
if ((to.meta.form != null && to.meta.form) || (to.meta.mode != null && to.meta.mode)) {
|
|
if ((to.meta.form != null && to.meta.form) || (to.meta.mode != null && to.meta.mode)) {
|
|
|
|
|
|
@@ -108,7 +111,6 @@ const auth = (to, from, next) => {
|
|
//不验证
|
|
//不验证
|
|
next();
|
|
next();
|
|
}
|
|
}
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
window.location.href = '../home/#/user/login';
|
|
window.location.href = '../home/#/user/login';
|
|
}
|
|
}
|
|
@@ -117,6 +119,20 @@ const auth = (to, from, next) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const checkRole = (to, from, next) => {
|
|
|
|
+ //切换当前场景
|
|
|
|
+ if (to.query.exchange == '1' && to.query.role_id) {
|
|
|
|
+ API_User.exchangePopedom({
|
|
|
|
+ id: to.query.role_id
|
|
|
|
+ }).then(response => {
|
|
|
|
+ auth(to, from, next)
|
|
|
|
+ }).catch(error => {
|
|
|
|
+ mui.toast(error);
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ auth(to, from, next)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.query.test) {
|
|
if (to.query.test) {
|
|
@@ -125,22 +141,43 @@ router.beforeEach((to, from, next) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //更新版本号,清除本地数据
|
|
|
|
+ if (store.state.app_version != process.env.VUE_APP_VERSION) {
|
|
|
|
+ clear();
|
|
|
|
+ //写入当前版本号
|
|
|
|
+ store.commit('SET_APP_VERSION', process.env.VUE_APP_VERSION);
|
|
|
|
+ }
|
|
|
|
+
|
|
//如果传递过来了token则写入
|
|
//如果传递过来了token则写入
|
|
if (to.query.token) {
|
|
if (to.query.token) {
|
|
|
|
+ console.log(to.query.token)
|
|
store.commit('SET_TOKEN', to.query.token);
|
|
store.commit('SET_TOKEN', to.query.token);
|
|
}
|
|
}
|
|
|
|
|
|
- //切换当前场景
|
|
|
|
- if (to.query.exchange == '1' && to.query.role_id) {
|
|
|
|
- API_User.exchangePopedom({
|
|
|
|
- id: to.query.role_id
|
|
|
|
- }).then(response => {
|
|
|
|
- auth(to, from, next)
|
|
|
|
- }).catch(error => {
|
|
|
|
- mui.toast(error);
|
|
|
|
- })
|
|
|
|
|
|
+ //如果funlist不存在,在更新版本号清空后,先重新请求再判断
|
|
|
|
+ if (!store.state.fun_list) {
|
|
|
|
+ var token = to.query.token;
|
|
|
|
+ if (token) {
|
|
|
|
+ //这里token一定要存在,从微信模板消息带过来的
|
|
|
|
+ API_User.getAllFunList(token).then(response => {
|
|
|
|
+
|
|
|
|
+ if (response && response.allIcon) {
|
|
|
|
+ var allIcon = response.allIcon;
|
|
|
|
+ store.commit('SET_FUN_LIST', allIcon);
|
|
|
|
+
|
|
|
|
+ checkRole(to, from, next);
|
|
|
|
+ } else {
|
|
|
|
+ mui.toast('token已过期');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }).catch(error => {
|
|
|
|
+ mui.toast(error);
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ checkRole(to, from, next);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- auth(to, from, next)
|
|
|
|
|
|
+ checkRole(to, from, next);
|
|
}
|
|
}
|
|
|
|
|
|
})
|
|
})
|