Selaa lähdekoodia

微信模板消息进入修改

wgl 4 vuotta sitten
vanhempi
commit
5969f57c58

+ 9 - 1
src/apis/user.js

@@ -1,6 +1,10 @@
 import request from '$project/utils/request'
 import Qs from 'qs';
 
+import {
+	getToken
+} from '$project/utils/storage'
+
 //获取用户角色列表
 export function getRoleList() {
 	return request({
@@ -38,11 +42,15 @@ export function getFunList() {
 }
 
 //获取所有功能列表,包括常用功能
-export function getAllFunList() {
+export function getAllFunList(token) {
+	var token = token || (getToken() ? getToken() : '');
 	return request({
 		url: '/mobile/icon/findAllIconByPersonRole',
 		data: Qs.stringify({}),
 		method: 'post',
+		headers: {
+			'Authorization': token,
+		},
 	})
 }
 

+ 14 - 4
src/components/Common.vue

@@ -123,7 +123,11 @@
 					this.set_common_menu_list(commonIconInfoList);
 
 					//获取所有功能列表
-					this.getAllFunList();
+					if (token) {
+						this.getAllFunList();
+					} else {
+						this.asynCallBack();
+					}
 
 				}).catch(error => {
 					mui.toast(error);
@@ -132,11 +136,17 @@
 			//获取所有功能列表
 			getAllFunList() {
 				API_User.getAllFunList().then(response => {
+					console.log('response');
+					console.log(response);
+					if (response && response.allIcon) {
+						var allIcon = response.allIcon;
+						this.set_fun_list(allIcon);
 
-					var allIcon = response.allIcon;
-					this.set_fun_list(allIcon);
+						this.asynCallBack();
+					} else {
+						mui.toast('未返回allIcon');
+					}
 
-					this.asynCallBack();
 
 				}).catch(error => {
 					mui.toast(error);

+ 2 - 22
src/projects/business/App.vue

@@ -9,25 +9,10 @@
 		mapGetters,
 		mapMutations
 	} from 'vuex'
-	import {
-		clear,
-	} from '$project/utils/storage'
-	import * as types from '$project/store/mutation-types'
 	export default {
 		name: 'Home',
-		created() {
-			//更新版本号,清除本地数据
-			if (this.app_version != process.env.VUE_APP_VERSION) {
-				clear();
-				//写入当前版本号
-				this.set_app_version(process.env.VUE_APP_VERSION);
-			}
-		},
-		methods: {
-			...mapMutations({
-				set_app_version: types.SET_APP_VERSION,
-			})
-		},
+		created() {},
+		methods: {},
 		mounted() {
 			mui('body').on('tap', '.kfz', function() {
 				mui.toast('开发中');
@@ -36,11 +21,6 @@
 				document.location.href = this.href;
 			});
 		},
-		computed: {
-			...mapGetters({
-				app_version: 'app_version'
-			})
-		}
 	}
 </script>
 

+ 49 - 12
src/projects/business/main.js

@@ -4,6 +4,9 @@ import router from './router'
 import store from '$project/store'
 
 import * as API_User from '$project/apis/user'
+import {
+	clear,
+} from '$project/utils/storage'
 
 //引入mui
 import mui from '$project/assets/js/mui.js'
@@ -88,7 +91,7 @@ function getFunList() {
 
 const auth = (to, from, next) => {
 	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)) {
 
@@ -108,7 +111,6 @@ const auth = (to, from, next) => {
 				//不验证
 				next();
 			}
-
 		} else {
 			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) => {
 	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则写入
 	if (to.query.token) {
+		console.log(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 {
-		auth(to, from, next)
+		checkRole(to, from, next);
 	}
 
 })

+ 3 - 22
src/projects/pension/App.vue

@@ -9,25 +9,10 @@
 		mapGetters,
 		mapMutations
 	} from 'vuex'
-	import {
-		clear,
-	} from '$project/utils/storage'
-	import * as types from '$project/store/mutation-types'
 	export default {
 		name: 'Home',
-		created() {
-			//更新版本号,清除本地数据
-			if (this.app_version != process.env.VUE_APP_VERSION) {
-				clear();
-				//写入当前版本号
-				this.set_app_version(process.env.VUE_APP_VERSION);
-			}
-		},
-		methods: {
-			...mapMutations({
-				set_app_version: types.SET_APP_VERSION,
-			})
-		},
+		created() {},
+		methods: {},
 		mounted() {
 			mui('body').on('tap', '.kfz', function() {
 				mui.toast('开发中');
@@ -36,11 +21,7 @@
 				document.location.href = this.href;
 			});
 		},
-		computed: {
-			...mapGetters({
-				app_version: 'app_version'
-			})
-		}
+		computed: {}
 	}
 </script>
 

+ 51 - 12
src/projects/pension/main.js

@@ -3,6 +3,11 @@ import App from './App.vue'
 import router from './router'
 import store from '$project/store'
 
+import * as API_User from '$project/apis/user'
+import {
+	clear,
+} from '$project/utils/storage'
+
 //引入mui
 import mui from '$project/assets/js/mui.js'
 import '$project/assets/css/mui.min.css'
@@ -63,7 +68,7 @@ function getFunList() {
 
 const auth = (to, from, next) => {
 	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)) {
 
@@ -92,6 +97,21 @@ 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) => {
 	if (to.query.test) {
 		if (to.query.test == 'test') {
@@ -99,24 +119,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则写入
 	if (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 {
-		auth(to, from, next)
+		checkRole(to, from, next);
 	}
-
 })
 
 new Vue({