Преглед на файлове

鉴权与切换的顺序问题修改

wgl преди 4 години
родител
ревизия
db37f0348d
променени са 2 файла, в които са добавени 56 реда и са изтрити 56 реда
  1. 28 28
      src/projects/business/main.js
  2. 28 28
      src/projects/pension/main.js

+ 28 - 28
src/projects/business/main.js

@@ -89,7 +89,7 @@ function getFunList() {
 }
 //console.log(funList)
 
-const auth = (to, from, next) => {
+const checkAuth = (to, from, next) => {
 	if (to.meta != null && to.meta.requireAuth) {
 		if (store.state.person_data || store.state.fun_list) {
 
@@ -125,12 +125,36 @@ const checkRole = (to, from, next) => {
 		API_User.exchangePopedom({
 			id: to.query.role_id
 		}).then(response => {
-			auth(to, from, next)
+			checkFun(to, from, next)
 		}).catch(error => {
 			mui.toast(error);
 		})
 	} else {
-		auth(to, from, next)
+		checkFun(to, from, next)
+	}
+}
+
+const checkFun = (to, from, next) => {
+	//如果funlist不存在,在更新版本号清空后,先重新请求再判断
+	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);
+
+				checkAuth(to, from, next);
+			} else {
+				mui.toast('token已过期');
+			}
+
+		}).catch(error => {
+			mui.toast(error);
+		})
+	} else {
+		checkAuth(to, from, next);
 	}
 }
 
@@ -154,31 +178,7 @@ router.beforeEach((to, from, next) => {
 		store.commit('SET_TOKEN', to.query.token);
 	}
 
-	//如果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 {
-		checkRole(to, from, next);
-	}
+	checkRole(to, from, next);
 
 })
 

+ 28 - 28
src/projects/pension/main.js

@@ -66,7 +66,7 @@ function getFunList() {
 }
 //console.log(funList)
 
-const auth = (to, from, next) => {
+const checkAuth = (to, from, next) => {
 	if (to.meta != null && to.meta.requireAuth) {
 		if (store.state.person_data || store.state.fun_list) {
 
@@ -103,12 +103,36 @@ const checkRole = (to, from, next) => {
 		API_User.exchangePopedom({
 			id: to.query.role_id
 		}).then(response => {
-			auth(to, from, next)
+			checkFun(to, from, next)
 		}).catch(error => {
 			mui.toast(error);
 		})
 	} else {
-		auth(to, from, next)
+		checkFun(to, from, next)
+	}
+}
+
+const checkFun = (to, from, next) => {
+	//如果funlist不存在,在更新版本号清空后,先重新请求再判断
+	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);
+
+				checkAuth(to, from, next);
+			} else {
+				mui.toast('token已过期');
+			}
+
+		}).catch(error => {
+			mui.toast(error);
+		})
+	} else {
+		checkAuth(to, from, next);
 	}
 }
 
@@ -131,31 +155,7 @@ router.beforeEach((to, from, next) => {
 		store.commit('SET_TOKEN', to.query.token);
 	}
 
-	//如果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 {
-		checkRole(to, from, next);
-	}
+	checkRole(to, from, next);
 })
 
 new Vue({