李程龙 před 3 roky
rodič
revize
3c3a80caee

+ 6 - 2
App.vue

@@ -16,9 +16,13 @@
 				return;
 			}
 			this.$api.loading('登陆中...');
-			const  res = await userLogin();
+			const  res = await userLogin({
+				pp_token:option.query.token
+			});
 			this.$api.hide();
-			cache.set(LOGIN_TOKEN, res?.session_key ?? '');
+			let session_key= res?.session_key ?? ''
+			cache.set(LOGIN_TOKEN,session_key);
+			await this.$isResolve()//调用
 		},
 		onShow() {
 

+ 6 - 0
main.js

@@ -19,6 +19,12 @@ Object.keys(filters).forEach(key => {
 Vue.prototype.$api = tool; // 全局api二次封装类
 Vue.prototype.$util = utils; // 全局工具类
 
+
+Vue.prototype.$onLaunched = new Promise(resolve => {
+    Vue.prototype.$isResolve = resolve
+})
+
+
 const app = new Vue({
     ...App
 })

+ 2 - 1
pages/aftersale/list.vue

@@ -82,7 +82,8 @@
 				]
 			};
 		},
-		onLoad() {
+		async onLoad() {
+			await this.$onLaunched
 			this.getDeviceList();
 		},
 		// 触底请求

+ 2 - 1
pages/camera/index.vue

@@ -36,7 +36,8 @@
 				total: 0, // 设备总数
 			};
 		},
-		onLoad() {
+		async onLoad() {
+			await this.$onLaunched;
 			this.getCameraList();
 		},
 		onReachBottom(e) {

+ 2 - 2
pages/pest/discern.vue

@@ -46,9 +46,9 @@
 				token: ''
 			};
 		},
-		onLoad(options) {
+		async onLoad(options) {
+			await this.$onLaunched;
 			this.token = options.token;
-			console.log(this.token);
 		},
 		methods: {
 			openExpert(e) {

+ 2 - 1
pages/pest/index.vue

@@ -51,7 +51,8 @@
 				}]
 			};
 		},
-		onLoad() {
+		async onLoad() {
+			await this.$onLaunched
 			this.getPestList();
 		},
 		// 触底请求

+ 2 - 1
pages/warn/index.vue

@@ -55,7 +55,8 @@
 				total: 0,
 			}
 		},
-		onLoad(options) {
+		async onLoad(options) {
+			await this.$onLaunched;
 			this.getWarningList();
 		},
 		// 触底请求

+ 4 - 1
pages/weather/index.vue

@@ -40,10 +40,13 @@
 				total: 0, // 设备总数
 			};
 		},
-		onLoad(options) {
+		async onLoad(options) {
+			console.log("sds");
+			await this.$onLaunched;
 			//获取类型 5气象站 8墒情站
 			this.params.device_type=options.type ?? 5;
 			this.getDeviceList();
+			
 		},
 		// 触底请求
 		onReachBottom(e) {

+ 2 - 1
pages/worm/index.vue

@@ -41,7 +41,8 @@
 				lampList: [], // 测报灯列表
 			};
 		},
-		onLoad() {
+		async onLoad() {
+			await this.$onLaunched;
 			this.getLampList();
 		},
 		// 触底请求

+ 1 - 1
utils/cache.js

@@ -1,7 +1,7 @@
 const Cache = {
 	// 设置缓存(expire为缓存时效,单位秒)
 	set(key, value, expire=360000000) {
-		console.log(expire);
+		console.log(key,value);
 		let data = {
 			expire: expire ? (this.time() + expire) : this.time() +360000000,
 			value

+ 3 - 2
utils/request/index.js

@@ -19,7 +19,8 @@ const service = request({
 
 // 请求拦截器
 service.interceptors.request.use(async (config, ...args) => {
-
+console.log(config);
+console.log('ddd',cache.get(LOGIN_TOKEN));
 	// 判断token是否存在
 	let token = cache.get(LOGIN_TOKEN) || '';
 	// token为空已过期 刷新token
@@ -34,7 +35,7 @@ service.interceptors.request.use(async (config, ...args) => {
 service.interceptors.response.use((response, ...args) => { // 响应拦截器(可以设置多个, 同时可以也可以使用异步方法)
 	// 状态403token无效 清除token
 	if (response.data.errorCode == 403) {
-		cache.set(LOGIN_TOKEN, '');
+		// cache.set(LOGIN_TOKEN, '');
 	}
 	if (response.data.message) {
 		uni.showToast({