李程龙 hace 3 años
padre
commit
3d606b5205

+ 16 - 11
App.vue

@@ -1,25 +1,30 @@
 <script>
-	import cache from '@/utils/cache'
+	import cache from '@/utils/cache';
+	import {
+		userLogin
+	} from '@/api/common.js';
 	import {
 		LOGIN_TOKEN,
-		CLIENT_ID
 	} from '@/config/cache'
 	export default {
-		// 全局获取token 与 客户端id
-		onLaunch(option) {
-			// 如果有token 就储存token与 clientId到缓存中
+		// 全局获取token
+		async onLaunch(option) {
 			// c测试数据
-			// cache.set(LOGIN_TOKEN,'XB5TDFmqD/EFLD7Bmsfp11vkfOjrNGqvcGEnWIAIGaE=');
-			if(option.query.token){
-				cache.set(LOGIN_TOKEN,option.query.token);
+			 // cache.set(LOGIN_TOKEN,'XB5TDFmqD/EFLD7Bmsfp11vkfOjrNGqvcGEnWIAIGaE=');
+			// 登录token
+			if (!option.query.token) {
+				return;
 			}
-			
+			this.$api.loading('登陆中...');
+			const  res = await userLogin();
+			this.$api.hide();
+			cache.set(LOGIN_TOKEN, res?.session_key ?? '');
 		},
 		onShow() {
-		
+
 		},
 		onHide() {
-			
+
 		}
 	}
 </script>

+ 14 - 0
api/common.js

@@ -0,0 +1,14 @@
+import request from '@/utils/request/index.js'
+import config from '@/config/config.js'
+import cache from '@/utils/cache'
+import {
+	LOGIN_TOKEN
+} from '@/config/cache'
+
+
+// 用户根据token 登录
+export const userLogin = async (params) => {
+	const res = await request.post(`api/api_gateway?method=user.login.pp_app_login_user`, params);
+	return res?.data;
+}
+

+ 1 - 1
components/ui-picker/ui-picker.vue

@@ -38,7 +38,7 @@
 		watch: {
 			value(val) {
 				let res = this.list.find(item => item.value == val);
-				return res?.text ?? ''
+				this.text = res?.text ?? ''
 			}
 		},
 		mounted() {

+ 4 - 2
pages/weather/history.vue

@@ -20,7 +20,7 @@
 			<uni-table class="table-style" ref="table" :loading="pageLoading" emptyText="暂无更多数据">
 				<uni-tr>
 					<block v-for="(header,index) in historyHeader" :key="index">
-						<uni-th align="center">{{header.text}}</uni-th>
+						<uni-th :width="index==0?120:80" align="center">{{header.text}}</uni-th>
 					</block>
 				</uni-tr>
 				<uni-tr v-for="(item, index) in historyList" :key="index">
@@ -46,6 +46,7 @@
 	} from '@/api/weather.js'
 	import {
 		timeFrame,
+		timeFrameText,
 		dateToUnix
 	} from '@/utils/utils.js'
 	export default {
@@ -72,7 +73,7 @@
 					page: 1,
 					page_size: 10,
 				},
-				searchTime: ['', ''],
+				searchTime: [timeFrameText('start'), timeFrameText('end')],
 				historyHeader: [], // 头部列表
 				historyList: [], // 历史数据
 				total: 0, // 数据总数
@@ -136,6 +137,7 @@
 					end: this.params.end_time
 				});
 				this.chartData = charts; // 统计数据集合
+				console.log(pickes);
 				this.pickerList = pickes; // 下拉列表集合
 				this.pickesId = pickes[0]?.value ?? ''; // 当前通道号
 				// 统计图显示数据

+ 2 - 1
pages/worm/analyse.vue

@@ -88,6 +88,7 @@
 		getPestBaseData
 	} from '@/api/worm.js'
 	import {
+		timeFrameText,
 		timeFrame,
 		dateToUnix
 	} from '@/utils/utils.js'
@@ -104,7 +105,7 @@
 					end_time: timeFrame('end'), // 结束时间
 				},
 				// === 虫害统计信息参数
-				searchTime: ['', ''],
+				searchTime: [timeFrameText('start'), timeFrameText('end')],
 				chartLoading: false,
 				// 饼状图数据
 				pestPieData: null,

+ 2 - 1
pages/worm/image.vue

@@ -24,6 +24,7 @@
 	} from '@/api/worm.js'
 	import {
 		timeFrame,
+		timeFrameText,
 		dateToUnix
 	} from '@/utils/utils.js'
 	// 虫情监测查看图片逻辑
@@ -38,7 +39,7 @@
 					page: 1,
 					page_number: 20,
 				},
-				searchTime: ['', ''],
+				searchTime: [timeFrameText('start'), timeFrameText('end')],
 				imageList: [], // 图片列表
 			}
 		},

+ 4 - 49
utils/request/index.js

@@ -32,6 +32,10 @@ service.interceptors.request.use(async (config, ...args) => {
 
 // response interceptor
 service.interceptors.response.use((response, ...args) => { // 响应拦截器(可以设置多个, 同时可以也可以使用异步方法)
+	// 状态403token无效 清除token
+	if (response.data.errorCode == 403) {
+		cache.set(LOGIN_TOKEN, '');
+	}
 	if (response.data.message) {
 		uni.showToast({
 			title: response.data.message,
@@ -43,52 +47,3 @@ service.interceptors.response.use((response, ...args) => { // 响应拦截器(
 	return response
 })
 export default service
-
-
-// export const myRequest = (options) => {
-// 	let BASE_URL = 请求地址
-// 	console.log(BASE_URL)
-// 	var session_key = ""
-// 	session_key = uni.getStorageSync('session_key')
-// 	let url = ""
-// 	let data = options.data || {}
-// 	if (options.url.split('=')[1]) {
-// 		url = options.url.split('=')[1]
-// 	} else {
-// 		url = options.url.split('api/')[1]
-// 	}
-// 	console.log(url)
-// 	if (url != 'user.login.login_user') {
-// 		data.token = session_key
-// 	}
-
-// 	return new Promise((resolve, reject) => {
-// 		uni.request({
-// 			url: BASE_URL + options.url,
-// 			method: options.method || 'POST',
-// 			header: {
-// 				"Content-Type": "application/x-www-form-urlencoded",
-// 			},
-// 			data: data,
-// 			success: (res) => {
-// 				if (res.data.message != "") {
-// 					if (res.data.message == "识别无结果") {
-// 						resolve(res.data.data)
-// 					} else {
-// 						return uni.showToast({
-// 							title: res.data.message,
-// 							icon: "none"
-// 						})
-// 					}
-// 				}
-// 				resolve(res.data.data)
-// 			},
-// 			fail: (err) => {
-// 				uni.showToast({
-// 					title: '请求接口失败'
-// 				})
-// 				reject(err)
-// 			}
-// 		})
-// 	})
-// }

+ 13 - 8
utils/utils.js

@@ -167,13 +167,18 @@ export function dateToUnix(dateText) {
  * @param {String} type 
  */
 export function timeFrame(type = 'start') {
-	let timestamp = Date.parse(new Date());
-	let date = new Date(timestamp);
-	let Y = date.getUTCFullYear();
-	let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
-	let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
-
-	let startTime = Date.parse(Y + '/' + M + '/' + D + ' ' + '00:00:00')
-	let endTime = Date.parse(Y + '/' + M + '/' + D + ' ' + '23:59:59')
+	let date = new Date();
+	date = date.setDate(date.getDate() - 1);
+	let startTime = Date.parse(new Date(date));
+	let endTime = Date.parse(timeFormat());
 	return type == 'start' ? startTime / 1000 : endTime / 1000
 }
+/**
+ * 获取一天的展示时间
+ * @param {String} type 
+ */
+export function timeFrameText(type = 'start') {
+	let date = new Date();
+	date = date.setDate(date.getDate() - 1);
+	return type == 'start' ? timeFormat(new Date(date), 'yyyy-mm-dd') : timeFormat(new Date(), 'yyyy-mm-dd')
+}