Просмотр исходного кода

fix(login):登录后不会判断是否打卡
refactor(App):改为使用config中的时间配置判断是否打卡

wangpx 1 год назад
Родитель
Сommit
ede036cf2c
2 измененных файлов с 47 добавлено и 8 удалено
  1. 6 5
      App.vue
  2. 41 3
      pages/login.vue

+ 6 - 5
App.vue

@@ -1,18 +1,19 @@
 <script>
 import { getUserInfo } from '@/utils/auth'
 import { checkAttendance } from '@/api/mine.js'
+import config from '@/config.js'
 import $tab from '@/plugins/tab.js'
 export default {
 	onLaunch: function () {
-		console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
+		// console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
 		this.initApp()
-		console.log('App Launch')
+		// console.log('App Launch')
 	},
 	onShow: function () {
-		console.log('App Show')
+		// console.log('App Show')
 	},
 	onHide: function () {
-		console.log('App Hide')
+		// console.log('App Hide')
 	},
 	methods: {
 		// 初始化应用
@@ -28,7 +29,7 @@ export default {
 				$tab.reLaunch('/pages/login')
 			} else {
 				// 是否在上班打卡时间段
-				if (this.isInTimeRange('08:30:00', '10:00:00')) {
+				if (this.isInTimeRange(...config.signInTimeRange)) {
 					const now = new Date()
 					const params = {
 						universalid: user.useId,

+ 41 - 3
pages/login.vue

@@ -23,11 +23,12 @@
 </template>
 
 <script setup lang="ts">
-	import config from '@/config.js'
 	import { ref } from 'vue'
-	import { useUserStore } from '@/store/user.js'
+	import { checkAttendance } from '@/api/mine.js'
+	import config from '@/config.js'
 	import $modal from '@/plugins/modal.js'
 	import $tab from '@/plugins/tab.js'
+	import { useUserStore } from '@/store/user.js'
 	const userStore = useUserStore()
 	const loginForm = ref({
 		username: '',
@@ -51,7 +52,44 @@
 	}
 	function loginSuccess() {
 		userStore.GetInfo()
-		$tab.reLaunch('/pages/message/index')
+		// 是否在上班打卡时间段
+		if (isInTimeRange(...config.signInTimeRange)) {
+			const now = new Date()
+			const params = {
+				universalid: userStore.useId,
+				rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
+			}
+			// 获取当天考勤信息
+			checkAttendance(params).then(({ returnParams }) => { 
+				if (returnParams.list.length) {
+					// 已签到 跳转消息页
+					$tab.reLaunch('/pages/message/index')
+				} else {
+					// 未签到 跳转考勤页面
+					$tab.reLaunch('/pages/message/index?to=clockIn')
+				}
+			})
+		} else {
+			$tab.reLaunch('/pages/message/index')
+		}
+	}
+	//判断时间是否在区间内
+	function 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>