Browse Source

fix(process.detail):登录状态过期处理

HMY 1 year ago
parent
commit
6e9493ca6d
4 changed files with 168 additions and 178 deletions
  1. 19 73
      pages/mine/checkIn/checkIn.vue
  2. 24 11
      pages/process/detail/index.vue
  3. 18 9
      utils/request.js
  4. 107 85
      utils/upload.js

+ 19 - 73
pages/mine/checkIn/checkIn.vue

@@ -162,10 +162,11 @@
 			"#ea7ccc"
 		], // 设定图表颜色
 		padding: [15, 15, 0, 5],
-		enableScroll: false, // 禁用滚动
+		enableScroll: false, // 滚动
 		legend: {}, // 图例设置
 		xAxis: {
-			disableGrid: true // 禁用网格线
+			disableGrid: true ,// 禁用网格线
+			// scrollShow: true,
 		},
 		yAxis: {
 			data: [{
@@ -428,7 +429,7 @@
 			case '周':
 				chartsType.value = 'pie'; // 设置图表类型为饼图
 				fetchWeekAttData().then(message => {
-					console.log(message);
+					// console.log(message);
 					showWeekAndMonth();
 					updateChart(message);
 				})
@@ -559,7 +560,7 @@
 			let data1 = []; // 收集 type6 的值
 			let data2 = []; // 收集 type4 的值
 			let data3 = []; // 收集 type5 的值
-			console.log('attendanceCount: ',attendanceCount.value);
+			// console.log('attendanceCount: ',attendanceCount.value);
 			// 遍历 myMonthAttData 并收集指定类型的值
 			myMonthAttData.forEach(item => {
 			    data1.push(item.type6);
@@ -570,14 +571,12 @@
 				lateCount.value += item.type4;
 				leaveEarlyCount.value += item.type5;
 				absenteeismCount.value += item.type6;
-				// console.log('attendanceCount: ',attendanceCount.value,typeof myMonthAttData.attDays );
 			});
-			console.log('data1',data1);
 			
 			// 定义一个常量数组生成器
 			const generateWeekArray = n => Array.from({ length: n }, (_, i) => `第${i + 1}周`);
-			let categoriesArr=generateWeekArray(4)
-			console.log(categoriesArr);
+			let categoriesArr=generateWeekArray(myMonthAttData.length)
+			// console.log(categoriesArr);
 			const mockData = {
 				categories:  categoriesArr,
 				series: [{
@@ -593,75 +592,22 @@
 			};
 			updateChart(mockData)
 		})
-		
-		// return new Promise((resolve, reject) => {
-		// 	const weekNodeList = [];// 存储近月每周的周一,周天日期
-		// 	weekNodeList.unshift(thisMondayDate.value, todayData.day);
-		// 	while (weekNodeList.length !== 8) {
-		// 		const weekNode = getOneDaysAgo(weekNodeList[0]);
-		// 		weekNodeList.unshift(weekNode);
-		// 		weekNodeList.unshift(getSixDaysAgo(weekNode));
-		// 	}
-
-		// 	const data1 = [];
-		// 	const data2 = [];
-		// 	const data3 = [];
-		// 	const dataFetchPromises = []; // 存储所有数据请求的promise
-
-		// 	for (let i = 0; i < weekNodeList.length - 1; i += 2) {
-		// 		const params = {
-		// 			staffId: userId,
-		// 			start_date: weekNodeList[i],
-		// 			end_date: weekNodeList[i + 1]
-		// 		};
-		// 		const fetchPromise = getMyTotalCount(params).then(res => {
-		// 			// for (const type in res.returnParams) {
-		// 			// 	console.log('type', type);
-		// 			// }
-		// 			console.log('res.returnParams', res.returnParams);
-
-		// 			data1.push(res.returnParams.type6);
-		// 			data2.push(res.returnParams.type4);
-		// 			data3.push(res.returnParams.type5);
-		// 		});
-		// 		dataFetchPromises.push(fetchPromise);
-		// 	}
-
-		// 	// 等待所有数据请求完成
-		// 	Promise.all(dataFetchPromises).then(() => {
-		// 		const params = {
-		// 			staffId: userId,
-		// 			start_date: weekNodeList[0],
-		// 			end_date: weekNodeList[weekNodeList.length - 1]
-		// 		};
-		// 		return getMyTotalCount(params);
-		// 	}).then(res => {
-		// 		const myMonthAttData = res.returnParams;
-				
-
-				
-		// 		// console.log(data1); // 打印data1检查内容
-		// 		resolve(mockData);
-		// 	}).catch(error => {
-		// 		reject(error);
-		// 	});
-		// });
 	}
 	
 
 
-	//获取六天前的日期
-	function getSixDaysAgo(dateStr) {
-		const date = new Date(dateStr);
-		date.setDate(date.getDate() - 6);
-		return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
-	}
-	//获取一天前的日期
-	function getOneDaysAgo(dateStr) {
-		const date = new Date(dateStr);
-		date.setDate(date.getDate() - 1);
-		return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
-	}
+	// //获取六天前的日期
+	// function getSixDaysAgo(dateStr) {
+	// 	const date = new Date(dateStr);
+	// 	date.setDate(date.getDate() - 6);
+	// 	return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
+	// }
+	// //获取一天前的日期
+	// function getOneDaysAgo(dateStr) {
+	// 	const date = new Date(dateStr);
+	// 	date.setDate(date.getDate() - 1);
+	// 	return date.toISOString().split('T')[0]; // 返回格式为'YYYY-MM-DD'的字符串
+	// }
 
 
 	// 更新图表数据

+ 24 - 11
pages/process/detail/index.vue

@@ -234,7 +234,7 @@ import $modal from '@/plugins/modal.js'
 import { getProcessFlowInfo, getProcessFormInfo, getProcessFormInfoInFlow, getProcessFlow, submitProcessFlow, cancelProcessFlow, uploadSignatureImg, uploadSignatureBoardImg, uploadFile } from '@/api/process.js'
 import { useUserStore } from '@/store/user.js'
 import {getLoginInfo,getSession,setSession} from '@/utils/auth.js'
-import {reLogin} from '@/api/login.js'
+import {reLogin,keepSession} from '@/api/login.js'
 const fieldTypeDict = {
 	'0': 'text',
 	'1': 'digit'
@@ -264,17 +264,30 @@ onLoad(({ insId, tinsId, insName, control }) => {
 	});
 })
 onShow(()=>{
-	const loginInfo = getLoginInfo()
-	//如果有登录信息,就自动登录刷session
-	if(Object.keys(loginInfo).length !== 0){
-		reLogin(loginInfo.username, loginInfo.password).then((res) => {
-				if ("ok" === res.data) {
+	keepSession().then(res=>{
+		if(typeof res === 'number'){
+			return
+		}else{
+			const loginInfo = getLoginInfo()
+			//如果有登录信息,就自动登录刷session
+			if(Object.keys(loginInfo).length !== 0){
+				reLogin(loginInfo.username, loginInfo.password).then((res) => {
+					if ("ok" === res.data) {
 						setSession(res.cookies[0].split("=")[1].split(";")[0]);
-				}
-		}).catch(res=>{
-			console.log(res);
-		})
-	}
+					}
+				}).catch(res=>{
+					console.log(res);
+				})
+			}else{
+				$tab.reLaunch({ url: '/pages/login' })
+			}
+		}
+	})
+	.catch(err=>{
+		console.log('err',err);
+		// $tab.navigateBack()
+	})
+	
 })
 
 onMounted(() => {

+ 18 - 9
utils/request.js

@@ -1,9 +1,10 @@
 // import { useUserStore } from '@/store/user.js'
 import config from '@/config'
-import { getSession } from '@/utils/auth'
+import { getSession,getLoginInfo } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
 import $modal from '@/plugins/modal.js'
+import $tab from '@/plugins/tab.js'
 
 let timeout = config.timeout
 const baseUrl = config.baseUrl
@@ -20,17 +21,25 @@ const request = config => {
       flag = true
       uni.showModal({
         title: '系统提示',
-        content: '登录状态已过期,您可以继续留在该页面,或者重新登录?',
+        content: '登录状态已过期,是否重新登录?',
         cancelText: '取消',
         confirmText: '确定',
         success: function (res) {
-          console.log('showModal success');
-          
-          if (res.confirm) {
-            uni.reLaunch({ url: '/pages/login?type=autoLogin' })
-            return
-          }
-          return
+          if (res.confirm) { 
+			  const loginInfo = getLoginInfo()
+			  //如果有登录信息,就自动登录刷session
+			  if(Object.keys(loginInfo).length !== 0){
+				  uni.reLaunch({ url: '/pages/login?type=autoLogin' })
+				}else{
+					uni.reLaunch({ url: '/pages/login' })
+				}
+          }else{
+			  //判断是否有上一页
+			  const hasPreviousPage = () => getCurrentPages().length > 1;
+			  if(hasPreviousPage()){
+				  $tab.navigateBack()
+			  }
+		  }
         }
       })
     }

+ 107 - 85
utils/upload.js

@@ -1,8 +1,15 @@
 // import store from '@/store'
 import config from '@/config'
-import { getSession } from '@/utils/auth'
+import {
+	getSession,getLoginInfo
+} from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
-import { toast, showConfirm, tansParams } from '@/utils/common'
+import {
+	toast,
+	showConfirm,
+	tansParams
+} from '@/utils/common'
+import $tab from '@/plugins/tab.js'
 
 let timeout = config.timeout
 const baseUrl = config.baseUrl
@@ -11,95 +18,110 @@ const upload = config => {
 	const isSession = config.isSession || false
 	config.header = config.header || {}
 	if (isSession) {
-	  if (getSession()) {
-	    config.header['cookie'] = 'JSESSIONID=' + getSession()
-	  } else {
-	    uni.showModal({
-	      title: '系统提示',
-	      content: '登录状态已过期,您可以继续留在该页面,或者重新登录?',
-	      cancelText: '取消',
-	      confirmText: '确定',
-	      success: function (res) {
-	        console.log('showModal success'); 
-	        if (res.confirm) {
-	          uni.reLaunch({ url: '/pages/login?type=autoLogin' })
-	          return
-	        }
-	        return
-	      }
-	    })
-	  }
+		if (getSession()) {
+			config.header['cookie'] = 'JSESSIONID=' + getSession()
+		} else {
+			uni.showModal({
+				title: '系统提示',
+				content: '登录状态已过期,您可以继续留在该页面,或者重新登录?',
+				cancelText: '取消',
+				confirmText: '确定',
+				success: function(res) {
+					console.log('showModal success');
+					if (res.confirm) {
+						const loginInfo = getLoginInfo()
+						//如果有登录信息,就自动登录刷session
+						if (Object.keys(loginInfo).length !== 0) {
+							uni.reLaunch({
+								url: '/pages/login?type=autoLogin'
+							})
+						} else {
+							uni.reLaunch({
+								url: '/pages/login'
+							})
+						}
+						return
+					}
+					return
+				}
+			})
+		}
+	}
+	// get请求映射params参数
+	if (config.params) {
+		let url = config.url + '?' + tansParams(config.params)
+		url = url.slice(0, -1)
+		config.url = url
 	}
-  // get请求映射params参数
-  if (config.params) {
-    let url = config.url + '?' + tansParams(config.params)
-    url = url.slice(0, -1)
-    config.url = url
-  }
-  console.log('upload.config', config);
-  return new Promise((resolve, reject) => {
-    uni.uploadFile({
-      timeout: config.timeout || timeout,
-      url: baseUrl + config.url,
-      // files: config.files,
-      filePath: config.filePath,
-      name: config.name || 'file',
-      header: config.header,
-      formData: config.formData,
-      success: (response) => {
+	console.log('upload.config', config);
+	return new Promise((resolve, reject) => {
+		uni.uploadFile({
+			timeout: config.timeout || timeout,
+			url: baseUrl + config.url,
+			// files: config.files,
+			filePath: config.filePath,
+			name: config.name || 'file',
+			header: config.header,
+			formData: config.formData,
+			success: (response) => {
 				console.log('upload.response', response);
-        const { statusCode, data } = response
+				const {
+					statusCode,
+					data
+				} = response
 				try {
 					const result = JSON.parse(data)
 				} catch (e) {
-          toast('上传失败, 请重试')
-          reject(-20201)
-          return
+					toast('上传失败, 请重试')
+					reject(-20201)
+					return
 				}
-        const result = JSON.parse(data)
+				const result = JSON.parse(data)
 				const returnCode = result.returnCode
-        const code = statusCode || 200
-        const msg = errorCode[code] || result.returnMsg || errorCode['default']
-        if (returnCode == -20201) {
-          toast(msg)
-          reject(returnCode)
-          return
-        }
-        if (code === 200) {
-          resolve(result)
-          // } else if (code == 401) {
-          //   showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(response => {
-          //     if (response.confirm) {
-          //       store.dispatch('LogOut').then(response => {
-          //         uni.reLaunch({ url: '/pages/login' })
-          //       })
-          //     }
-          //   })
-          //   reject('无效的会话,或者会话已过期,请重新登录。')
-        } else if (code === 500) {
-          toast(msg)
-          reject('500')
-        } else if (code !== 200) {
-          toast(msg)
-          reject(code)
-        }
-      },
-      fail: (error) => {
-        let { errMsg } = error
-        if (errMsg == 'Network Error') {
-          errMsg = '后端接口连接异常'
-        } else if (errMsg.includes('timeout')) {
-          errMsg = '系统接口请求超时'
-        } else if (errMsg.includes('Request failed with status code')) {
-          errMsg = '系统接口' + errMsg.substr(errMsg.length - 3) + '异常'
-        } else if (errMsg.includes('request:fail')) {
-          errMsg = '网络请求失败'
-        }
-        toast(errMsg)
-        reject(error)
-      }
-    })
-  })
+				const code = statusCode || 200
+				const msg = errorCode[code] || result.returnMsg || errorCode['default']
+				if (returnCode == -20201) {
+					toast(msg)
+					reject(returnCode)
+					return
+				}
+				if (code === 200) {
+					resolve(result)
+					// } else if (code == 401) {
+					//   showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(response => {
+					//     if (response.confirm) {
+					//       store.dispatch('LogOut').then(response => {
+					//         uni.reLaunch({ url: '/pages/login' })
+					//       })
+					//     }
+					//   })
+					//   reject('无效的会话,或者会话已过期,请重新登录。')
+				} else if (code === 500) {
+					toast(msg)
+					reject('500')
+				} else if (code !== 200) {
+					toast(msg)
+					reject(code)
+				}
+			},
+			fail: (error) => {
+				let {
+					errMsg
+				} = error
+				if (errMsg == 'Network Error') {
+					errMsg = '后端接口连接异常'
+				} else if (errMsg.includes('timeout')) {
+					errMsg = '系统接口请求超时'
+				} else if (errMsg.includes('Request failed with status code')) {
+					errMsg = '系统接口' + errMsg.substr(errMsg.length - 3) + '异常'
+				} else if (errMsg.includes('request:fail')) {
+					errMsg = '网络请求失败'
+				}
+				toast(errMsg)
+				reject(error)
+			}
+		})
+	})
 }
 
-export default upload
+export default upload