Pārlūkot izejas kodu

Merge branch 'master' of http://222.243.138.146:2000/ygtx/ygoa_miniapp

wangpx 1 gadu atpakaļ
vecāks
revīzija
ce5486cdaf
2 mainītis faili ar 41 papildinājumiem un 25 dzēšanām
  1. 13 9
      pages/login.vue
  2. 28 16
      store/config.js

+ 13 - 9
pages/login.vue

@@ -32,7 +32,7 @@ import { getLoginInfo } from '@/utils/auth'
 import { useConfigStore } from '@/store/config.js'
 import { onLoad } from '@dcloudio/uni-app'
 const userStore = useUserStore()
-const configStore=useConfigStore();
+const configStore = useConfigStore();
 
 const loginForm = ref({
 	username: getLoginInfo().username || '',
@@ -60,12 +60,13 @@ onLoad((options) => {
 	if (options.type) {
 		// console.log('autoLogin');
 		handleLogin()
-	} 
+	}
 })
 function loginSuccess() {
-	userStore.GetInfo().then(()=>{
+	userStore.GetInfo().then(() => {
 		// 是否在上班打卡时间段
-		configStore.GetAttRule(userStore.user).then(()=>{
+		configStore.GetAttRule(userStore.user).then(() => {
+			console.log('GetAttRule');
 			if (isInTimeRange(...configStore.signInTimeRange)) {
 				const now = new Date()
 				const params = {
@@ -85,11 +86,13 @@ function loginSuccess() {
 			} else {
 				$tab.reLaunch('/pages/message/index')
 			}
-		})
+		}).catch((error) => {
+			// console.log('GetAttRule error:', error);
+			if (['getAttendanceSegmentErr', 'getAttendanceRuleErr'].includes(error)) {
+				$tab.reLaunch('/pages/message/index')
+			}
+		});
 	})
-	
-	
-	
 }
 //判断时间是否在区间内
 function isInTimeRange(start, end) {
@@ -224,7 +227,8 @@ image {
 				text-align: center;
 				text-decoration: none;
 				overflow: visible;
-				margin-left: initial;		transform: translate(0rpx, 0rpx);
+				margin-left: initial;
+				transform: translate(0rpx, 0rpx);
 				margin-right: initial;
 			}
 		}

+ 28 - 16
store/config.js

@@ -10,22 +10,34 @@ export const useConfigStore = defineStore('config', () => {
 	
 	function GetAttRule(user) {
 		const fillZero = (timeStr) => timeStr + ':00'
-		return new Promise((resolve) => {
-		    getAttendanceSegment(user.unitId).then(res => {
-		    	const result = res.returnParams.find(item => item.segment_status == "1");
-		    	const { startTime, endTime } = getStartAndEndTime(result.work_time);
-		    	getAttendanceRule(user.unitId).then(res => {
-		    		//找到正在用的考勤规则
-		    		const attRule = res.returnParams.Rows.find(item => item.rule_status == "1");
-		    		signInTimeRange.value = [addMinutesToTime(startTime, -attRule.on_advance_num), fillZero(startTime)];
-		    		signOutTimeRange.value = [fillZero(endTime), addMinutesToTime(endTime, attRule.off_delay_num)];
-		    		lateTimeRange.value = [fillZero(startTime), addMinutesToTime(startTime, attRule.late_num)];
-		    		earlyTimeRange.value = [addMinutesToTime(endTime, -attRule.eary_num), fillZero(endTime)];
-					resolve(); // 确保执行完成后调用 resolve
-				})
-		    })
-		    
-		  });
+		return new Promise((resolve, reject) => {
+			try {
+				getAttendanceSegment(user.unitId).then(res => {
+					console.log('getAttendanceSegment', res);
+					const result = res.returnParams.find(item => item.segment_status == "1");
+					const { startTime, endTime } = getStartAndEndTime(result.work_time);
+					getAttendanceRule(user.unitId).then(res => {
+						// 找到正在用的考勤规则
+						const attRule = res.returnParams.Rows.find(item => item.rule_status == "1");
+						signInTimeRange.value = [addMinutesToTime(startTime, -attRule.on_advance_num), fillZero(startTime)];
+						signOutTimeRange.value = [fillZero(endTime), addMinutesToTime(endTime, attRule.off_delay_num)];
+						lateTimeRange.value = [fillZero(startTime), addMinutesToTime(startTime, attRule.late_num)];
+						earlyTimeRange.value = [addMinutesToTime(endTime, -attRule.eary_num), fillZero(endTime)];
+						resolve(); // 确保执行完成后调用 resolve
+					}).catch(err => {
+						console.log('获取考勤规则时发生错误', err);
+						reject('getAttendanceRuleErr');
+					});
+				}).catch(err => {
+					console.log('获取考勤时间段时发生错误', err);
+					reject('getAttendanceSegmentErr');
+				});
+			} catch (err) {
+				console.error('处理考勤数据时发生错误', err);
+				reject(err);
+			}
+		});
+		
 		
 	}