zhengkaixin 2 rokov pred
rodič
commit
0d6bb9878b

+ 3 - 0
.env.development

@@ -3,6 +3,9 @@ VUE_APP_NODE_NAME=devlopment
 OUT_PUT_NAME=dev
 VUE_APP_LOCAL_STORAGE_PREFIX=dev
 
+#项目缓存抬头
+VUE_APP_LOCAL_PREFIX_MAIN=ga_file_xpgj_
+
 #VUE_APP_BACKEND_URL=https://ykt-test.xiaoxinda.com/jp-housekeeper-server/
 #VUE_APP_BACKEND_URL=http://localhost:8086/jp-housekeeper-server/
 VUE_APP_BACKEND_URL=https://xpgjapi.xiaoxinda.com/

+ 4 - 0
.env.production

@@ -2,6 +2,10 @@ NODE_ENV=production
 VUE_APP_NODE_NAME=production
 OUT_PUT_NAME=prod
 VUE_APP_LOCAL_STORAGE_PREFIX=prod
+
+#项目缓存抬头
+VUE_APP_LOCAL_PREFIX_MAIN=ga_file_xpgj_
+
 VUE_APP_BACKEND_URL=https://xpgjapi.xiaoxinda.com/
 VUE_APP_BACKEND_URL51=https://51team.xiaoxinda.com/charging-parking/
 VUE_APP_MIRROR_BACKEND_URL=https://mirror.xiaoxinda.com/xpgjapi/

+ 4 - 0
.env.test

@@ -2,6 +2,10 @@ NODE_ENV=production
 VUE_APP_NODE_NAME=test
 OUT_PUT_NAME=test
 VUE_APP_LOCAL_STORAGE_PREFIX=test
+
+#项目缓存抬头
+VUE_APP_LOCAL_PREFIX_MAIN=ga_file_xpgj_
+
 VUE_APP_BACKEND_URL=https://ykt-test.xiaoxinda.com/jp-housekeeper-server/
 VUE_APP_BACKEND_URL51=https://51team.xiaoxinda.com/charging-parking/
 

+ 236 - 0
src/commin.js

@@ -0,0 +1,236 @@
+//const projectName = require('$root/config/project');
+	import * as API_WeiXin from '@/apis/weixin'
+	import * as API_User from '@/apis/user'
+	import Loading from '@/components/Loading.vue'
+	import {
+		getUrlParam,
+		getWeixinRedirectURI,
+		isWeiXin
+	} from '@/utils'
+	import {
+		mapGetters,
+		mapMutations
+	} from 'vuex'
+	import * as types from '@/store/mutation-types'
+	import * as Dictionaries from '@/utils/dictionaries'
+	export default {
+		name: 'Common',
+		components: {
+			Loading,
+		},
+		props: {
+			
+			//是否获取openid
+			checkOpenId: {
+				require: false,
+				default: true,
+			},
+			projectCheckLogin: {
+				require: false,
+				default: false,
+			},
+			//用户角色
+			role: {
+				require: false,
+				default: '',
+			},
+			//是否检测项目,进行跳转
+			projectCheck: {
+				require: false,
+				default: true,
+			},
+			doLoading: {
+				require: false,
+				default: false,
+			},
+		},
+		data() {
+			return {
+				//testOpenid:"oHjCawjpLV6Dbdit8MVkShB6G58w",
+				testOpenid:"oHjCawigqi8SEAwutwkQ-VEgdp3k",
+				isLoading: false,
+			}
+		},
+		created() {
+			//公共组件的执行方法放在created中执行,父组件的create放在motuned中执行
+			if (isWeiXin()) {
+				if (this.checkOpenId) {
+					if (!this.openId) {
+						this.getOpenid();
+					} else {
+						this.getDataByOpenId();
+					}
+				}
+			} else {
+				if (this.checkOpenId) {
+					/* mui.alert('请使用微信浏览打开!', '提示', function() {
+						//info.innerText = '你刚关闭了警告框';
+					}); */
+				}
+			}
+		},
+		methods: {
+			//获取openid
+			getOpenid() {
+				const code = getUrlParam('code');
+				if (!code) {
+					window.location.href = getWeixinRedirectURI(process.env.VUE_APP_WXAPPID, document.URL);
+				} else {
+					console.log(code);
+
+					if (!this.openId) {
+						const step1 = API_WeiXin.getDataByCode(code).then(response => {
+							//console.log(response)
+							this.set_openid(response.openid);
+							window.localStorage.setItem("xpgj_wx_user_info", JSON.stringify(response))
+							
+							//角色判定调用不同的信息获取详情
+							this.getDataByOpenId();
+
+							return Promise.resolve(response.openid);
+						}).catch(error => {
+							//console.log(error);
+							return Promise.reject(error);
+						});
+						step1.then(() => {
+							let redirect = this.$route.query.redirect;
+							if (redirect) {
+								this.$router.push({
+									path: decodeURIComponent(redirect)
+								});
+							} else {
+								window.location.href = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
+							}
+						});
+					} else {
+						//如果存在openid,把链接中code字符去除
+						window.location.href = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
+					}
+				}
+			},
+			//角色判定调用不同的信息获取详情
+			getDataByOpenId() {
+				this.getUserInfoByOpenId();
+			},
+			//获取用户详情
+			getUserInfoByOpenId() {
+				this.isLoading = true;
+				var openId=this.openId;
+			
+				if (process.env.VUE_APP_NODE_NAME == 'devlopment') {			
+					openId=this.testOpenid;
+				}
+				var type = type || '';
+				API_WeiXin.getDataByOpenId(openId).then(response => {
+
+					this.isLoading = false;
+
+					//console.log(response)
+
+					var token = response ? response.token : '';
+					this.set_token(token);
+
+					var person = response ? response.person : '';
+					this.set_person_data(person);
+					this.set_person_temp(person);
+
+					var personPopedom = response ? response.personPopedom : '';
+					this.set_person_popedom(personPopedom);
+
+					var iconInfoList = response ? response.iconInfoList : '';
+					this.set_menu_list(iconInfoList);
+
+					var commonIconInfoList = response ? response.commonIconInfoList : '';
+					this.set_common_menu_list(commonIconInfoList);
+
+					//获取所有功能列表
+					if (token) {
+						this.getAuthFunList();
+					} else {
+						this.asynCallBack(true);
+					}
+
+				}).catch(error => {
+					mui.toast(error);
+				})
+			},
+			//获取所有功能监权列表
+			getAuthFunList() {
+				this.isLoading = true;
+				API_User.getAuthFunList().then(response => {
+
+					this.isLoading = false;
+
+					if (response && response.allIconRoute) {
+						var allIconRoute = response.allIconRoute;
+						this.set_auth_fun_list(allIconRoute);
+
+						this.asynCallBack();
+					} else {
+						mui.toast('未返回allIcon');
+					}
+
+
+				}).catch(error => {
+					mui.toast(error);
+				})
+			},
+			//判断权限然后进行跳转
+			projectExchange() {
+				//如果不想跳转,还可以传参exchange,一般用于home注册切换等功能
+				// if (this.projectCheck && this.$route.query.exchange != '1' && this.person_popedom && this.person_popedom.sceneId) {
+				// 	let project = Dictionaries.getProject(this.person_popedom.sceneId);
+				// 	if (projectName.name != project && ['devlopment'].indexOf(process.env.VUE_APP_NODE_NAME) == -1) {
+				// 		window.location.href = '../' + project + '/#/master';
+				// 	}
+				// }
+				if (this.projectCheckLogin) {
+					//window.location.href = '../#/master';
+					window.location.href = '#/master';
+				}
+			},
+
+
+			//异步回调父组件的方法
+			asynCallBack(bl) {
+				
+				if(!bl){
+					this.projectExchange();
+				}
+				//this.projectExchange();
+				this.$emit('asynCallBack',bl);
+			},
+			...mapMutations({
+				set_openid: types.SET_WEIXIN_OPENID,
+				set_token: types.SET_TOKEN,
+				set_person_data: types.SET_PERSON_DATA,
+				set_person_popedom: types.SET_PERSON_POPEDOM,
+				set_menu_list: types.SET_MENI_LIST,
+				set_person_temp: types.SET_PERSON_TEMP,
+				set_auth_fun_list: types.SET_AUTH_FUN_LIST,
+				set_app_version: types.SET_APP_VERSION,
+				set_common_menu_list: types.SET_COMMON_MENU_LIST,
+			})
+		},
+		mounted() {
+			//如果是开发环境则直接读取findbyopenid信息
+			if (process.env.VUE_APP_NODE_NAME == 'devlopment') {
+				
+				
+				this.getDataByOpenId();
+			}
+		},
+		computed: {
+			...mapGetters({
+				openId: 'wx_openid',
+				token: 'token',
+				person_data: 'person_data',
+				person_popedom: 'person_popedom',
+				menu_list: 'menu_list',
+				common_menu_list: 'common_menu_list',
+				person_temp: 'person_temp',
+				auth_fun_list: 'auth_fun_list',
+				app_version: 'app_version'
+			})
+		}
+	}

+ 2 - 234
src/components/Common.vue

@@ -5,240 +5,8 @@
 </template>
 
 <script>
-	//const projectName = require('$root/config/project');
-	import * as API_WeiXin from '@/apis/weixin'
-	import * as API_User from '@/apis/user'
-	import Loading from '@/components/Loading.vue'
-	import {
-		getUrlParam,
-		getWeixinRedirectURI,
-		isWeiXin
-	} from '@/utils'
-	import {
-		mapGetters,
-		mapMutations
-	} from 'vuex'
-	import * as types from '@/store/mutation-types'
-	import * as Dictionaries from '@/utils/dictionaries'
-	export default {
-		name: 'Common',
-		components: {
-			Loading,
-		},
-		props: {
-			
-			//是否获取openid
-			checkOpenId: {
-				require: false,
-				default: true,
-			},
-			projectCheckLogin: {
-				require: false,
-				default: false,
-			},
-			//用户角色
-			role: {
-				require: false,
-				default: '',
-			},
-			//是否检测项目,进行跳转
-			projectCheck: {
-				require: false,
-				default: true,
-			},
-			doLoading: {
-				require: false,
-				default: false,
-			},
-		},
-		data() {
-			return {
-				testOpenid:"oHjCawjpLV6Dbdit8MVkShB6G58w",
-				isLoading: false,
-			}
-		},
-		created() {
-			//公共组件的执行方法放在created中执行,父组件的create放在motuned中执行
-			if (isWeiXin()) {
-				if (this.checkOpenId) {
-					if (!this.openId) {
-						this.getOpenid();
-					} else {
-						this.getDataByOpenId();
-					}
-				}
-			} else {
-				if (this.checkOpenId) {
-					/* mui.alert('请使用微信浏览打开!', '提示', function() {
-						//info.innerText = '你刚关闭了警告框';
-					}); */
-				}
-			}
-		},
-		methods: {
-			//获取openid
-			getOpenid() {
-				const code = getUrlParam('code');
-				if (!code) {
-					window.location.href = getWeixinRedirectURI(process.env.VUE_APP_WXAPPID, document.URL);
-				} else {
-					console.log(code);
-
-					if (!this.openId) {
-						const step1 = API_WeiXin.getDataByCode(code).then(response => {
-							//console.log(response)
-							this.set_openid(response.openid);
-							window.localStorage.setItem("xpgj_wx_user_info", JSON.stringify(response))
-							
-							//角色判定调用不同的信息获取详情
-							this.getDataByOpenId();
-
-							return Promise.resolve(response.openid);
-						}).catch(error => {
-							//console.log(error);
-							return Promise.reject(error);
-						});
-						step1.then(() => {
-							let redirect = this.$route.query.redirect;
-							if (redirect) {
-								this.$router.push({
-									path: decodeURIComponent(redirect)
-								});
-							} else {
-								window.location.href = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
-							}
-						});
-					} else {
-						//如果存在openid,把链接中code字符去除
-						window.location.href = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
-					}
-				}
-			},
-			//角色判定调用不同的信息获取详情
-			getDataByOpenId() {
-				this.getUserInfoByOpenId();
-			},
-			//获取用户详情
-			getUserInfoByOpenId() {
-				this.isLoading = true;
-				var openId=this.openId;
-			
-				if (process.env.VUE_APP_NODE_NAME == 'devlopment') {			
-					openId="oHjCawigqi8SEAwutwkQ-VEgdp3k";
-				}
-				var type = type || '';
-				API_WeiXin.getDataByOpenId(openId).then(response => {
-
-					this.isLoading = false;
-
-					//console.log(response)
-
-					var token = response ? response.token : '';
-					this.set_token(token);
-
-					var person = response ? response.person : '';
-					this.set_person_data(person);
-					this.set_person_temp(person);
-
-					var personPopedom = response ? response.personPopedom : '';
-					this.set_person_popedom(personPopedom);
-
-					var iconInfoList = response ? response.iconInfoList : '';
-					this.set_menu_list(iconInfoList);
-
-					var commonIconInfoList = response ? response.commonIconInfoList : '';
-					this.set_common_menu_list(commonIconInfoList);
-
-					//获取所有功能列表
-					if (token) {
-						this.getAuthFunList();
-					} else {
-						this.asynCallBack(true);
-					}
-
-				}).catch(error => {
-					mui.toast(error);
-				})
-			},
-			//获取所有功能监权列表
-			getAuthFunList() {
-				this.isLoading = true;
-				API_User.getAuthFunList().then(response => {
-
-					this.isLoading = false;
-
-					if (response && response.allIconRoute) {
-						var allIconRoute = response.allIconRoute;
-						this.set_auth_fun_list(allIconRoute);
-
-						this.asynCallBack();
-					} else {
-						mui.toast('未返回allIcon');
-					}
-
-
-				}).catch(error => {
-					mui.toast(error);
-				})
-			},
-			//判断权限然后进行跳转
-			projectExchange() {
-				//如果不想跳转,还可以传参exchange,一般用于home注册切换等功能
-				// if (this.projectCheck && this.$route.query.exchange != '1' && this.person_popedom && this.person_popedom.sceneId) {
-				// 	let project = Dictionaries.getProject(this.person_popedom.sceneId);
-				// 	if (projectName.name != project && ['devlopment'].indexOf(process.env.VUE_APP_NODE_NAME) == -1) {
-				// 		window.location.href = '../' + project + '/#/master';
-				// 	}
-				// }
-				if (this.projectCheckLogin) {
-					//window.location.href = '../#/master';
-					window.location.href = '#/master';
-				}
-			},
-
-
-			//异步回调父组件的方法
-			asynCallBack(bl) {
-				if(bl){
-					this.projectExchange();
-				}
-				//this.projectExchange();
-				this.$emit('asynCallBack',bl);
-			},
-			...mapMutations({
-				set_openid: types.SET_WEIXIN_OPENID,
-				set_token: types.SET_TOKEN,
-				set_person_data: types.SET_PERSON_DATA,
-				set_person_popedom: types.SET_PERSON_POPEDOM,
-				set_menu_list: types.SET_MENI_LIST,
-				set_person_temp: types.SET_PERSON_TEMP,
-				set_auth_fun_list: types.SET_AUTH_FUN_LIST,
-				set_app_version: types.SET_APP_VERSION,
-				set_common_menu_list: types.SET_COMMON_MENU_LIST,
-			})
-		},
-		mounted() {
-			//如果是开发环境则直接读取findbyopenid信息
-			if (process.env.VUE_APP_NODE_NAME == 'devlopment') {
-				
-				
-				this.getDataByOpenId();
-			}
-		},
-		computed: {
-			...mapGetters({
-				openId: 'wx_openid',
-				token: 'token',
-				person_data: 'person_data',
-				person_popedom: 'person_popedom',
-				menu_list: 'menu_list',
-				common_menu_list: 'common_menu_list',
-				person_temp: 'person_temp',
-				auth_fun_list: 'auth_fun_list',
-				app_version: 'app_version'
-			})
-		}
-	}
+	import  API from '@/commin'
+	export default API
 </script>
 
 <style>

+ 7 - 1
src/main.js

@@ -110,7 +110,13 @@ const checkAuth = (to, from, next) => {
 			}
 		} else {
 			//window.location.href = '../home/#/user/login';
-			window.location.href = '#/user/login';
+		//	window.location.href = '#/user/login';
+			router.push({
+				name: 'UserLogin',
+				query: {
+				
+				}
+			})
 		}
 	} else {
 		next();

+ 3 - 13
src/router/home.js

@@ -13,14 +13,7 @@ const routes = [
 			title: '首页',
 		}
 	},
-	{
-		path: '/master',
-		name: 'Home',
-		component: () => import('../views-home/Home.vue'),
-		meta: {
-			title: '首页',
-		}
-	},
+	
 		//切换
 			{
 				path: '/select',
@@ -383,9 +376,6 @@ const routes = [
 
 ]
 
-const router = new VueRouter({
-	//base: process.env.BASE_URL,
-	routes
-})
 
-export default router
+
+export default routes

+ 1 - 11
src/router/index.js

@@ -18,17 +18,7 @@ import homeOther from './home'
 if (!window.VueRouter) Vue.use(VueRouter)
 
 const routesIndex = [
-	//首页
-	{
-		path: '/',
-		name: 'Home',
-		component: () => import('../views/Home.vue'),
-		meta: {
-			requireAuth: false,
-			role: [],
-			title: '首页',
-		}
-	},
+	
 ]
 
 const routes = routesIndex.concat(routesCommon, routesGuest, routesMaster, routesControl, routesOther,homeOther);

+ 2 - 1
src/utils/storage.js

@@ -30,7 +30,8 @@ function delCookie(name) {
 }
 
 
-const prefix = 'xpgj_'
+const prefix = process.env.VUE_APP_LOCAL_PREFIX_MAIN;
+
 const engine = window.localStorage
 
 export const get = key => !engine.getItem(prefix + key) ? null : JSON.parse(engine.getItem(prefix + key))

+ 1 - 1
src/views-home/User/Login.vue

@@ -1,6 +1,6 @@
 <template>
 	<div>
-		<common @asynCallBack="asynCallBack" ></common>
+		<common @asynCallBack="asynCallBack" :projectCheckLogin="true" ></common>
 		<top-header :pageTitle="pageTitle" :leftShow="false"></top-header>
 
 		<div class="mui-content">

+ 7 - 1
src/views/Master/Home.vue

@@ -359,7 +359,13 @@
 					//获取最新二条通知消息
 					this.prefetchNotice();
 				}else{
-					window.location.href = '../home/#/select';
+					//window.location.href = '../home/#/select';
+					this.$router.push({
+						name: 'UserLogin',
+						query: {
+						
+						}
+					})
 				}
 				
 			},

+ 7 - 1
src/views/Master/Mine/Center.vue

@@ -99,7 +99,13 @@
 		created() {
 			//如果不存在则跳转到注册页面
 			if (!this.person_data) {
-				window.location.href = "../home/#/user/login";
+				//window.location.href = "../home/#/user/login";
+				this.$router.push({
+					name: 'UserLogin',
+					query: {
+					
+					}
+				})
 			}
 		},
 		methods: {

+ 7 - 1
src/views/Master/Mine/Message.vue

@@ -69,7 +69,13 @@
 		created() {
 			//如果不存在则跳转到注册页面
 			if (!this.person_data) {
-				window.location.href = '../home/#/user/login'
+				//window.location.href = '../home/#/user/login'
+				this.$router.push({
+					name: 'UserLogin',
+					query: {
+					
+					}
+				})
 			}
 		},
 		methods: {

+ 7 - 2
src/views/Other/Energy/Info.vue

@@ -612,8 +612,13 @@
 					this.initNew()
 				} else {
 					mui.toast("请登录后查看");
-					window.location.href = '../home/#/select';
-
+					//window.location.href = '../home/#/select';
+					this.$router.push({
+						name: 'UserLogin',
+						query: {
+						
+						}
+					})
 				}
 
 			}