Переглянути джерело

feat(message,App): 在打卡时间段登录 未打卡提示用户打卡

wangpx 1 рік тому
батько
коміт
d248aa5031
2 змінених файлів з 41 додано та 12 видалено
  1. 33 8
      App.vue
  2. 8 4
      pages/message/index.vue

+ 33 - 8
App.vue

@@ -26,25 +26,49 @@ export default {
 			const user = getUserInfo()
 			if (!getUserInfo()) {
 				$tab.reLaunch('/pages/login')
-        } else {
+			} else {
+				// 是否在上班打卡时间段
+				if (this.isInTimeRange('08:30:00', '10:00:00')) {
 					const now = new Date()
 					const params = {
 						universalid: user.useId,
 						rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
 					}
-					CheckAttendance(params).then(({ returnParams }) => { // 获取当天考勤信息
-						if (returnParams.list.length) { 
-							// 已签到 跳转消息页面
+					// 获取当天考勤信息
+					CheckAttendance(params).then(({ returnParams }) => { 
+						if (returnParams.list.length) {
+							// 已签到 跳转消息页
 							$tab.reLaunch('/pages/message/index')
-						} else { 
+						} else {
 							// 未签到 跳转考勤页面
 							$tab.reLaunch('/pages/message/index?to=clockIn')
 						}
 					})
+				} else {
+					$tab.reLaunch('/pages/message/index')
 				}
-      }
+			}
+		},
+		//判断时间是否在区间内
+		isInTimeRange(start, end) {
+			// 获取当前时间戳
+			const now = Date.now();
+
+			// 获取当前日期
+			const currentDate = new Date(now);
+			const year = currentDate.getFullYear();
+			const month = currentDate.getMonth();
+			const day = currentDate.getDate();
+
+			// 构建当天的起始时间和结束时间的时间戳
+			const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
+			const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
+
+			// 判断当前时间是否在范围内
+			return now >= startTime && now <= endTime;
 		}
 	}
+}
 </script>
 
 <style lang="scss">
@@ -65,6 +89,7 @@ page {
 /* #endif */
 .example-info {
 	font-size: 14px;
-	color: #333;	padding: 10px;
-	}
+	color: #333;
+	padding: 10px;
+}
 </style>

+ 8 - 4
pages/message/index.vue

@@ -158,14 +158,18 @@
 	import { onMounted, reactive, ref } from 'vue';
 	import { onLoad } from '@dcloudio/uni-app'
 	import $tab from '@/plugins/tab.js';
+	import $modal from '@/plugins/modal.js';
 	import processList from '@/components/ygoa/processList.vue'
 	import { useUserStore } from '@/store/user.js'
+	import { GetMessageList, GetNoticeList } from '@/api/message.js';
 	onLoad((options) => {
-		if (options.to == 'clockIn') {
-			$tab.navigateTo('/pages/mine/clockIn/clockIn')
-		}
+		if (options.to == 'clockIn') toClockIn()
 	})
-	import { GetMessageList, GetNoticeList } from '@/api/message.js';
+	function toClockIn() {
+		$modal.confirm('当前未打卡,是否前往打卡').then(() => {
+			$tab.navigateTo('/pages/mine/clockIn/clockIn')
+		})
+	}
 	onMounted(() => {
 		onClickItem({ currentIndex: 0 })
 		onClickItem2({ currentIndex: 0 })