@dongkboy 3 hete
szülő
commit
89017584e3
1 módosított fájl, 71 hozzáadás és 65 törlés
  1. 71 65
      pages/index/index.vue

+ 71 - 65
pages/index/index.vue

@@ -245,76 +245,16 @@ export default {
 		}
 		// 已登录但首页数据未加载(如未登录时进入过首页后再登录,onLoad 不会重新执行),补加载
 		if (!this.tenantLoaded) {
-			await this.onLoad();
+			await this.loadHomeData(); // 与 onLoad 生命周期共用同一加载方法(内部有防重入)
 		} else if (!this.historyLoaded) {
 			this.loadHistoryQuote(); //机构已加载但历史车牌失败过,单独补
 		}
 		await this.getDicType("car_kind_code"); //车辆种类
 	},
-	async onLoad() {
-		if (!store.state.token) {
-			return; // 未登录不发请求(onShow 会跳转登录页),避免 getTenantList 等接口 401 弹“登录已失效”
-		}
-		if (this.tenantLoading || this.tenantLoaded) {
-			return; // 防重入:加载中或已加载过则不再执行,避免重复请求/重复签到
-		}
-		const loadToken = store.state.token; // 快照本次加载的token,完成时校验账号是否已变化
-		this.tenantLoading = true;
-		try {
-			let res = await this.$http.post('/userInfo/getTenantList'); //获取机构列表
-			if (res.code == '200') {
-				if (res.data && res.data.length) {
-					if (res.data.length > 1) {
-						this.tenantOrglist = res.data;
-						if (!store.state.system_code) {
-							this.deptSelectShow = true; //多个租户弹窗选择
-						} else {
-							this.deptradiovalue = store.state.system_code;
-							this.deptradioName = store.state.system_Name;
-						}
-					} else {
-						//单个租户赋值第一个(仅组件内数据,写store/签到等副作用在校验通过后执行)
-						this.tenantOrglist = res.data;
-						this.deptradiovalue = res.data[0].systemCode;
-						this.deptradioName = res.data[0].deptName;
-					}
-				}
-				// 账号校验前置:加载期间账号已变化则放弃并清理,避免旧账号数据污染store/重复签到
-				if (store.state.token !== loadToken) {
-					this.tenantOrglist = [];
-					this.deptradiovalue = '';
-					this.deptradioName = '';
-					this.deptSelectShow = false;
-					return;
-				}
-				// 校验通过后才执行写store与签到等副作用操作
-				if (res.data && res.data.length === 1) {
-					store.commit('setUserModules', {
-						title: 'system_code',
-						data: this.tenantOrglist[0].systemCode
-					})
-					store.commit('setUserModules', {
-						title: 'system_Name',
-						data: this.tenantOrglist[0].sysName
-					})
-					await this.bannerquery(); //获取轮播图
-					await this.getUserInfo(); //获取人员信息
-					await this.$http.post('/signIn/doSignIn')
-				}
-				// 整条初始化链成功后才置位(任一环节失败则不置位,onShow 下次可重试)
-				this.tenantLoaded = true;
-				this.loadedToken = loadToken;
-			}
-		} catch (e) {
-			// 静默:401 由 dataFactory 统一处理,网络异常不中断;tenantLoaded 保持 false,下次 onShow 可重试
-		} finally {
-			this.tenantLoading = false;
-		}
-		try {
-			await this.loadHistoryQuote(); //获取历史报价车牌
-		} catch (e) {
-			// 静默:历史报价车牌加载失败不影响主流程
-		}
+	onLoad() {
+		// 页面生命周期:首次进入触发初始化加载。注意不能 this.onLoad() 直接调用——
+		// 页面生命周期钩子不挂载到组件实例,onShow 中补加载需走 methods 里的 loadHomeData
+		this.loadHomeData();
 	},
 	beforeCreate() {
 		// setTimeout(() => {
@@ -323,6 +263,72 @@ export default {
 	},
 	methods: {
 		...mapMutations(['activelicenseNo']),
+		// 首页初始化数据加载:onLoad 生命周期与 onShow 补加载共用(页面生命周期钩子不可 this.onLoad() 调用,故抽为普通方法)
+		async loadHomeData() {
+			if (!store.state.token) {
+				return; // 未登录不发请求(onShow 会跳转登录页),避免 getTenantList 等接口 401 弹“登录已失效”
+			}
+			if (this.tenantLoading || this.tenantLoaded) {
+				return; // 防重入:加载中或已加载过则不再执行,避免重复请求/重复签到
+			}
+			const loadToken = store.state.token; // 快照本次加载的token,完成时校验账号是否已变化
+			this.tenantLoading = true;
+			try {
+				let res = await this.$http.post('/userInfo/getTenantList'); //获取机构列表
+				if (res.code == '200') {
+					if (res.data && res.data.length) {
+						if (res.data.length > 1) {
+							this.tenantOrglist = res.data;
+							if (!store.state.system_code) {
+								this.deptSelectShow = true; //多个租户弹窗选择
+							} else {
+								this.deptradiovalue = store.state.system_code;
+								this.deptradioName = store.state.system_Name;
+							}
+						} else {
+							//单个租户赋值第一个(仅组件内数据,写store/签到等副作用在校验通过后执行)
+							this.tenantOrglist = res.data;
+							this.deptradiovalue = res.data[0].systemCode;
+							this.deptradioName = res.data[0].deptName;
+						}
+					}
+					// 账号校验前置:加载期间账号已变化则放弃并清理,避免旧账号数据污染store/重复签到
+					if (store.state.token !== loadToken) {
+						this.tenantOrglist = [];
+						this.deptradiovalue = '';
+						this.deptradioName = '';
+						this.deptSelectShow = false;
+						return;
+					}
+					// 校验通过后才执行写store与签到等副作用操作
+					if (res.data && res.data.length === 1) {
+						store.commit('setUserModules', {
+							title: 'system_code',
+							data: this.tenantOrglist[0].systemCode
+						})
+						store.commit('setUserModules', {
+							title: 'system_Name',
+							data: this.tenantOrglist[0].sysName
+						})
+						await this.bannerquery(); //获取轮播图
+						await this.getUserInfo(); //获取人员信息
+						await this.$http.post('/signIn/doSignIn')
+					}
+					// 整条初始化链成功后才置位(任一环节失败则不置位,onShow 下次可重试)
+					this.tenantLoaded = true;
+					this.loadedToken = loadToken;
+				}
+			} catch (e) {
+				// 静默:401 由 dataFactory 统一处理,网络异常不中断;tenantLoaded 保持 false,下次 onShow 可重试
+			} finally {
+				this.tenantLoading = false;
+			}
+			try {
+				await this.loadHistoryQuote(); //获取历史报价车牌
+			} catch (e) {
+				// 静默:历史报价车牌加载失败不影响主流程
+			}
+		},
 		//获取历史报价车牌(独立方法,失败后 onShow 可单独重试)
 		async loadHistoryQuote() {
 			const loadToken = store.state.token; // 快照token,完成时校验账号是否已变化