Kaynağa Gözat

feat(login):自动登录

HMY 1 yıl önce
ebeveyn
işleme
2f2eb79e08

+ 29 - 28
App.vue

@@ -27,35 +27,36 @@ export default {
 			this.checkLogin()
 		},
 		checkLogin() {
-			const configStore=useConfigStore()
-			const user = getUserInfo()
-			if (!getUserInfo()) {
-				$tab.reLaunch('/pages/login')
-			} else {
-				// 是否在上班打卡时间段
-				configStore.GetAttRule(user).then(()=>{
-					if (this.isInTimeRange(...configStore.signInTimeRange)) {
-						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) {
-								// 已签到 跳转消息页
-								$tab.reLaunch('/pages/message/index')
-							} else {
-								// 未签到 跳转考勤页面
-								$tab.reLaunch('/pages/message/index?to=clockIn')
-							}
-						})
-					} else {
-						$tab.reLaunch('/pages/message/index')
-					}
-				})
+			$tab.reLaunch('/pages/login?type=autoLogin')
+			// const configStore=useConfigStore()
+			// const user = getUserInfo()
+			// if (!getUserInfo()) {
+			// 	$tab.reLaunch('/pages/login')
+			// } else {
+			// 	// 是否在上班打卡时间段
+			// 	configStore.GetAttRule(user).then(()=>{
+			// 		if (this.isInTimeRange(...configStore.signInTimeRange)) {
+			// 			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) {
+			// 					// 已签到 跳转消息页
+			// 					$tab.reLaunch('/pages/message/index')
+			// 				} else {
+			// 					// 未签到 跳转考勤页面
+			// 					$tab.reLaunch('/pages/message/index?to=clockIn')
+			// 				}
+			// 			})
+			// 		} else {
+			// 			$tab.reLaunch('/pages/message/index')
+			// 		}
+			// 	})
 				
-			}
+			// }
 		},
 		//判断时间是否在区间内
 		isInTimeRange(start, end) {

+ 9 - 0
pages/login.vue

@@ -30,6 +30,7 @@ import $tab from '@/plugins/tab.js'
 import { useUserStore } from '@/store/user.js'
 import { getLoginInfo } from '@/utils/auth'
 import { useConfigStore } from '@/store/config.js'
+import { onLoad } from '@dcloudio/uni-app'
 const userStore = useUserStore()
 const configStore=useConfigStore();
 
@@ -53,6 +54,14 @@ function handleLogin() {
 		})
 	}
 }
+
+onLoad((options) => {
+	//判断是否要自动登录
+	if (options.type) {
+		// console.log('autoLogin');
+		handleLogin()
+	} 
+})
 function loginSuccess() {
 	userStore.GetInfo().then(()=>{
 		// 是否在上班打卡时间段

+ 2 - 2
pages/message/index.vue

@@ -237,7 +237,7 @@ function handleToMessageDetail({ messageid, universalid }) {
 				const loginInfo = getLoginInfo();
 				userStore.LogOut().then(res => {
 					uni.setStorageSync('loginInfo', loginInfo)
-					$tab.reLaunch('/pages/login')
+					$tab.reLaunch('/pages/login?type=autoLogin')
 				})
 			}).catch(() => { })
 		}
@@ -317,7 +317,7 @@ function setAllMsgRead() {
 					} else {
 						$modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
 							userStore.LogOut().then(res => {
-								uni.reLaunch({ url: '/pages/login' })
+								uni.reLaunch({ url: '/pages/login?type=autoLogin' })
 							})
 						}).catch(() => { })
 					}

+ 5 - 4
pages/mine/checkIn/checkIn.vue

@@ -230,17 +230,18 @@
 		}
 		checkAttendance(params).then(res => {
 			if ("success" == res.returnMsg) {
+				//数据初始化
+				todayData.startTime = '';
+				todayData.endTime = '';
 				if (res.returnParams.list.length == 0) {
-					todayData.startTime = '';
-					todayData.endTime = ''
-					return;
+					return
 				}
 				const attList = res.returnParams.list;
+				
 				const time1 = attList.find(item => item.att_type_id === '1');
 				const time2 = attList.filter(item => item.att_type_id === '2').pop();
 				if (time1 !== undefined) {
 					todayData.startTime = time1.att_time.split(' ')[1];
-					todayData.endTime ='';
 				}
 				if (time2 !== undefined) {
 					todayData.endTime = time2.att_time.split(' ')[1];

+ 25 - 16
pages/mine/clockIn/clockIn.vue

@@ -57,7 +57,7 @@
 	import config from '@/config.js';
 	import { createAttendance, tranAddress, checkAttendance, getAttendanceRule, getAttendanceSegment } from '@/api/mine.js'
 	const userStore = useUserStore();
-	const configStore=useConfigStore();
+	const configStore = useConfigStore();
 	const thisUser = userStore.user;
 	const intervalId = ref(null); // 定时器ID
 	onBeforeUnmount(() => {
@@ -96,6 +96,9 @@
 		const dayOfWeek = nowDate.getDay(); // 获取当前星期
 		currentDay.value = weekArr[dayOfWeek]; // 设置当前星期
 		getTodayAtt();
+		// if (nowTime.value > '12:00') {
+		// 	signName.value = '下班签退'
+		// }
 	}
 
 
@@ -122,7 +125,7 @@
 				const time1 = attList.find(item => item.att_type_id === '1');
 				//拿到所有签退数据后,用pop取最后一个
 				const time2 = attList.filter(item => item.att_type_id === '2').pop();
-				console.log('time2', time2);
+				console.log('time1', time1);
 				if (time1 !== undefined) {
 					// console.log('getTime1',time1);
 					signInTime.value = time1.att_time.split(' ')[1];
@@ -134,7 +137,9 @@
 						signInStatusName.value = '旷工';
 						isSignInStatusDisabled.value = false;
 					}
-				} else {
+				}else if (new Date().getHours()>=12) {
+					signName.value = '下班签退'
+				}  else {
 					signName.value = '上班签到';
 				}
 				if (time2 !== undefined) {
@@ -404,44 +409,48 @@
 
 	//是否补卡、请假判断
 	function isToFillClock(attType, time) {
+		// console.log('isToFillClock',attType,time);
 		//早上迟到跳补卡
 		let status = '';
 		if (attType == 1) {
-			if (isTimeInRange(time, ...configStore.lateTimeRange)){
+			if (isTimeInRange(time, ...configStore.lateTimeRange)) {
 				status = '迟到'
 			} else if (isTimeInRange(time, configStore.lateTimeRange[1], '23:59:59')) {
 				status = '旷工'
-			} else{
+			} else {
+				$modal.msgSuccess('打卡成功')
+				setTimeout(() => {
+					$tab.navigateTo('/pages/mine/checkIn/checkIn')
+				}, 1000)
 				return
 			}
 			$modal.confirm('当前状态为' + status + '!\n是否跳转补卡页面').then(() => {
 				$tab.reLaunch('/pages/work/index')
 			})
-			.catch(() => {
+				.catch(() => {
 					$tab.navigateTo('/pages/mine/checkIn/checkIn')
 				})
 		} else if (attType == 2) {
 			//早退请假提示
-			if(isTimeInRange(time, '00:00:00',configStore.earlyTimeRange[0])){
+			if (isTimeInRange(time, '00:00:00', configStore.earlyTimeRange[0])) {
 				status = '旷工'
-			}else if (isTimeInRange(time, ...configStore.earlyTimeRange)) {
+			} else if (isTimeInRange(time, ...configStore.earlyTimeRange)) {
 				status = '早退'
-			} else{
+			} else {
+				$modal.msgSuccess('打卡成功')
+				setTimeout(() => {
+					$tab.navigateTo('/pages/mine/checkIn/checkIn')
+				}, 1000)
 				return
 			}
 			$modal.confirm('当前状态为' + status + '!\n是否跳转请假页面').then(() => {
 				$tab.reLaunch('/pages/work/index')
 			})
-			.catch(() => {
+				.catch(() => {
 					$tab.navigateTo('/pages/mine/checkIn/checkIn')
 				})
 		}
-		else {
-			$modal.msgSuccess('打卡成功')
-			setTimeout(() => {
-				$tab.navigateTo('/pages/mine/checkIn/checkIn')
-			}, 1000)
-		}
+		
 	}
 
 	//判断是否已经打卡

+ 47 - 4
pages/work/edit/index.vue

@@ -45,7 +45,8 @@
 								</view>
 							</picker>
 							<!-- 数据选择器 -->
-							<uni-data-checkbox v-else-if="'5' == elem.type" multiple v-model="elem.defaultValue" :localdata="formatDict(elem.typeDetail.enum)"></uni-data-checkbox>
+							<uni-data-checkbox v-else-if="'5' == elem.type" multiple v-model="elem.defaultValue" :localdata="formatCheckbox(elem)" @change="changeDataCheckBox($event,elem)"></uni-data-checkbox>
+							<!-- <uni-data-checkbox v-else-if="'5' == elem.type" multiple v-model="elem.defaultValue" :localdata="formatDict(elem.typeDetail.enum)" @change="changeDataCheckBox"></uni-data-checkbox> -->
 							<!-- 开始时间选择器 -->
 							<uni-datetime-picker :end="formElements[elem.endElemIndex].defaultValue"
 								@change="setTimeRange(elem)"
@@ -396,6 +397,20 @@ function bindPickerChange(e, item) {
 function formatDict(dict) {
 	return dict.map(({ enumVname }) => enumVname)
 }
+//数据选择器
+function formatCheckbox(elem){
+	let dict = elem.typeDetail.enum
+	elem['checkBox'] = true
+	return dict.map((item, index) => ({
+		text: item.enumVname,
+		value: item.enumVname 
+	}));
+}
+const testValue=ref('')
+function changeDataCheckBox(e,elem){
+	// elem.checkBox=e.detail.value.join(",")
+	testValue.value=e.detail.value.join(",")
+}
 
 // 新增重复表表单
 function addRepeatingFormItem(index) {
@@ -626,9 +641,37 @@ function submitProcess() { // 提交表单
 			return
 		}
 		// 保存表单数据
-		processInfo.form = formElements.value.map(({ tableField, defaultValue }) => {
-			return { name: tableField, value: defaultValue }
-		})
+		
+		// processInfo.form = formElements.value.map(({ checkBox, tableField, defaultValue }) => {
+		// 	// console.log('tableField: ',checkBox,tableField,defaultValue);
+		// 	if(checkBox!==''){
+		// 		const arr =testValue.value.split(",")
+		// 		arr.forEach(item=>{
+		// 			processInfo.form.push({name: tableField+"_showfxx", value: item})
+		// 		})
+		// 		return { name: tableField, value: testValue.value }
+		// 	}
+		// 	return { name: tableField, value: defaultValue }
+		// })
+		
+		const formArray = [];
+	
+		formElements.value.forEach(({ checkBox, tableField, defaultValue }) => {
+			if (checkBox) {
+				if (testValue.value) {
+					const items = testValue.value.split(",").filter(item => item.trim() !== '');
+					items.forEach(item => {
+						formArray.push({ name: `${tableField}_showfxx`, value: item.trim() });
+					});
+				}
+				formArray.push({ name: tableField, value: testValue.value });
+			} else {
+				formArray.push({ name: tableField, value: defaultValue });
+			}
+		});
+	
+		processInfo.form = formArray;
+		
 		repeatingForm.value.elements.forEach((item, index) => {
 			const newItem = item.map(({ name, defaultValue }) => {
 				return {

+ 1 - 1
utils/request.js

@@ -27,7 +27,7 @@ const request = config => {
           console.log('showModal success');
           
           if (res.confirm) {
-            uni.reLaunch({ url: '/pages/login' })
+            uni.reLaunch({ url: '/pages/login?type=autoLogin' })
             return
           }
           return

+ 1 - 1
utils/upload.js

@@ -22,7 +22,7 @@ const upload = config => {
 	      success: function (res) {
 	        console.log('showModal success'); 
 	        if (res.confirm) {
-	          uni.reLaunch({ url: '/pages/login' })
+	          uni.reLaunch({ url: '/pages/login?type=autoLogin' })
 	          return
 	        }
 	        return