瀏覽代碼

Merge branch 'master' of http://118.195.146.34:3000/ygtx/ygoa_miniapp

wangpx 1 年之前
父節點
當前提交
c64d5e4544
共有 4 個文件被更改,包括 168 次插入72 次删除
  1. 2 1
      api/mine/checkIn.js
  2. 11 0
      api/mine/clockIn.js
  3. 32 45
      pages/mine/checkIn/checkIn.vue
  4. 123 26
      pages/mine/clockIn/clockIn.vue

+ 2 - 1
api/mine/checkIn.js

@@ -1,5 +1,5 @@
 import request from '@/utils/request.js'
-
+//检查今日考勤状况
 export function CheckAttendance(params) {
 	return request({
     method: 'post',
@@ -10,6 +10,7 @@ export function CheckAttendance(params) {
 	})
 }
 
+//获取我的考勤数据统计
 export function getMyTotalCount(params) {
 	return request({
     method: 'post',

+ 11 - 0
api/mine/clockIn.js

@@ -0,0 +1,11 @@
+import request from '@/utils/request.js'
+//考勤打卡
+export function CreateAttendance(params) {
+	return request({
+		'method':'post',
+		'data': {
+			'serviceId': 'hr_2018V01CreateAttendance',
+			'params': params
+		}
+	})
+}

+ 32 - 45
pages/mine/checkIn/checkIn.vue

@@ -13,7 +13,7 @@
 		<!-- 数据统计区域 -->
 		<view class="statistics" :class="{'show': chartShow}">
 			<view class="statistic-card">
-				<view class="statistic-title">考勤统计</view>
+				<view class="statistic-title">{{selectedTimeRange}}考勤统计</view>
 				<view class="statistic-item">
 					<view>
 						<text class="ygoa-icon icon-attendance"></text>
@@ -23,32 +23,32 @@
 				</view>
 				<view class="statistic-item">
 					<view>
-						<text class="ygoa-icon icon-leave"></text>
-						<text class="label">请假:</text>
+						<text class="ygoa-icon icon-goOut"></text>
+						<text class="label">外出:</text>
 					</view>
-					<text class="value">{{ leaveCount }}</text>
+					<text class="value">{{ goOutCount }}</text>
 				</view>
 				<view class="statistic-item">
 					<view>
-						<text class="ygoa-icon icon-businessTrip"></text>
-						<text class="label">出差:</text>
+						<text class="ygoa-icon icon-late"></text>
+						<text class="label">迟到:</text>
 					</view>
 
-					<text class="value">{{ businessTripCount }}</text>
+					<text class="value">{{ lateCount }}</text>
 				</view>
 				<view class="statistic-item">
 					<view>
-						<text class="ygoa-icon icon-clockIn1"></text>
-						<text class="label">打卡:</text>
+						<text class="ygoa-icon icon-leaveEarly"></text>
+						<text class="label">早退:</text>
 					</view>
-					<text class="value">{{ clockInCount }}</text>
+					<text class="value">{{ leaveEarlyCount }}</text>
 				</view>
 				<view class="statistic-item">
 					<view>
-						<text class="ygoa-icon icon-makeUp"></text>
-						<text class="label">补卡:</text>
+						<text class="ygoa-icon icon-absenteeism"></text>
+						<text class="label">缺勤:</text>
 					</view>
-					<text class="value">{{ makeUpCount }}</text>
+					<text class="value">{{ absenteeismCount }}</text>
 				</view>
 			</view>
 		</view>
@@ -105,15 +105,10 @@
 </template>
 
 <script setup>
-	import {
-		ref,
-		onMounted,
-		reactive
-	} from 'vue';
-	import {
-		CheckAttendance,
-		getMyTotalCount
-	} from "../../../api/mine/checkIn.js"
+	import {ref,onMounted,reactive} from 'vue';
+	import {CheckAttendance,getMyTotalCount} from "@/api/mine/checkIn.js"
+	import { useUserStore } from '@/store/user.js';
+	const userStore = useUserStore();
 
 	// 创建一个响应式对象记录今天的考勤数据
 	const todayData = reactive({
@@ -165,26 +160,18 @@
 
 	// 考勤相关统计数据
 	const attendanceCount = ref(0); // 出勤次数
-	const leaveCount = ref(0); // 请假次数
-	const businessTripCount = ref(0); // 出差次数
-	const clockInCount = ref(0); // 打卡次数
-	const makeUpCount = ref(0); // 补卡次数
-
-
-	const currentData = ref({
-		attendance: 0, // 出勤
-		leave: 0, // 请假
-		businessTrip: 0, // 出差
-		clockIn: 0, // 打卡
-		makeUp: 0, // 补卡
-		res: {}, // 记录详细数据
-	});
+	const goOutCount = ref(0); // 外出次数
+	const lateCount = ref(0); // 迟到次数
+	const leaveEarlyCount = ref(0); // 早退次数
+	const absenteeismCount = ref(0); // 缺勤次数
+
+	//用户id
 	const userId = ref('');
 	//当前周的周一日期
 	const thisMondayDate = ref('');
 
 	onMounted(() => {
-		userId.value = '511341581866278';
+		userId.value = userStore.user.useId;//拿到用户id
 		initAttData(); //初始化日考勤数据
 	});
 
@@ -344,10 +331,10 @@
 				};
 				const weekData = mockData.series[0].data;
 				attendanceCount.value = weekData[0].value;
-				leaveCount.value = weekData[1].value;
-				businessTripCount.value = weekData[2].value;
-				clockInCount.value = weekData[3].value;
-				makeUpCount.value = weekData[4].value;
+				goOutCount.value = weekData[2].value;
+				lateCount.value = weekData[4].value;
+				leaveEarlyCount.value = weekData[5].value;
+				absenteeismCount.value = weekData[6].value;
 				resolve(mockData)
 			}).catch(error => {
 				reject(error)
@@ -402,10 +389,10 @@ function fetchMonthAttData() {
 		}).then(res => {
 			const myMonthAttData = res.returnParams;
 			attendanceCount.value = myMonthAttData.type0;
-			leaveCount.value = myMonthAttData.type1;
-			businessTripCount.value = myMonthAttData.type2;
-			clockInCount.value = myMonthAttData.type3;
-			makeUpCount.value = myMonthAttData.type4;
+			goOutCount.value = myMonthAttData.type2;
+			lateCount.value = myMonthAttData.type4;
+			leaveEarlyCount.value = myMonthAttData.type5;
+			absenteeismCount.value = myMonthAttData.type6;
 
 			const mockData = {
 				categories: ["第1周", "第2周", "第3周", "第4周"],

+ 123 - 26
pages/mine/clockIn/clockIn.vue

@@ -54,28 +54,40 @@
 
 	// 导入地理位置相关函数
 	import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
-	import { point, polygon } from "@turf/helpers";
+	import {
+		point,
+		polygon
+	} from "@turf/helpers";
+
+	import {
+		CheckAttendance
+	} from '@/api/mine/checkIn';
+	import {
+		useUserStore
+	} from '@/store/user';
+	const userStore = useUserStore();
 
-	
+	const userId = ref('')
 
 	// 组件挂载后初始化当前日期与位置
 	onMounted(() => {
-		dateInit(); 
-		getlocation(); 
+		userId.value = userStore.user.useId;
+		dateInit();
+		getlocation();
 	});
 
 
 	// 当前日期和时间相关信息
 	const currentDate = ref('2023-04-01');
-	const currentDay = ref('星期三'); 
+	const currentDay = ref('星期三');
 	const clockInStatus = ref(''); // 打卡状态
 	const weekArr = reactive(['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']); // 星期数组
-	const signInTime = ref('09:00'); // 上班签到时间
+	const signInTime = ref(''); // 上班签到时间
 	const signOutTime = ref(''); // 下班签到时间
 
 	// 初始化日期
 	function dateInit() {
-		const nowDate = new Date(); 
+		const nowDate = new Date();
 		const year = nowDate.getFullYear(); // 获取年份
 		const month = nowDate.getMonth() + 1; // 获取月份
 		const day = nowDate.getDate(); // 获取日期
@@ -85,10 +97,41 @@
 		currentDate.value = `${year}-${formattedMonth}-${formattedDay}`; // 设置当前日期
 		const dayOfWeek = nowDate.getDay(); // 获取当前星期
 		currentDay.value = weekArr[dayOfWeek]; // 设置当前星期
+		getTodayAtt();
+	}
+
+	//获取今天考勤状态
+	function getTodayAtt() {
+		const params = {
+			universalid: userId.value,
+			rizi: currentDate.value
+		}
+		CheckAttendance(params).then(res => {
+			if ("success" == res.returnMsg) {
+				const attList = res.returnParams.list;
+				const time1 = attList.find(item => item.att_type_id === '1');
+				const time2 = attList.find(item => item.att_type_id === '2');
+				if (time1 !== undefined) {
+					signInTime.value = time1.att_time.split(' ')[1];
+				}
+				if (time2 !== undefined) {
+					signOutTime.value = time2.att_time.split(' ')[1];
+				}
+			}
+		})
 	}
 
 	// 上班签到
 	function signIn() {
+		const now = getNowTime();
+		//判断打卡时间是否符合
+		if (!isTimeInRange(now, '08:30:00', '10:00:00')) {
+			uni.showToast({
+				title: "不在签到时间8:30--10:00内",
+				icon: 'none'
+			});
+			return;
+		}
 		getlocation(); // 获取当前位置
 		tranAddress(); // 转换地址
 		clockIn(); // 执行打卡
@@ -96,17 +139,44 @@
 
 	// 下班签退
 	function signOut() {
+		const now = getNowTime();
+		//判断打卡时间是否符合
+		if (!isTimeInRange(now, '15:00:00', '20:00:00')) {
+			uni.showToast({
+				title: "不在签退时间15:00--20:00内",
+				icon: 'none'
+			});
+			return;
+		}
 		getlocation(); // 获取当前位置
 		tranAddress(); // 转换地址
-		const flag = clockIn(); // 执行打卡并获取结果
-		if (flag) {
-			var now = new Date();
-			var hours = now.getHours();
-			var minutes = now.getMinutes();
-			signOutTime.value = hours + ':' + minutes; // 获取当前时间作为下班时间
-		}
+		clockIn(); // 执行打卡并获取结果
 	};
 
+	//获取当前时间
+	function getNowTime() {
+		var now = new Date();
+		// 获取小时、分钟和秒
+		var hours = now.getHours(); // 获取小时(0-23)
+		var minutes = now.getMinutes(); // 获取分钟(0-59)
+		var seconds = now.getSeconds(); // 获取秒(0-59)
+		// 将小时、分钟或秒格式化为两位数
+		hours = hours < 10 ? '0' + hours : hours;
+		minutes = minutes < 10 ? '0' + minutes : minutes;
+		seconds = seconds < 10 ? '0' + seconds : seconds;
+		return `${hours}:${minutes}:${seconds}`;
+	}
+
+	//判断时间是否在区间内
+	function isTimeInRange(time, startTime, endTime) {
+		// 将时间字符串转换为Date对象
+		var timeObj = new Date('1970-01-01T' + time + 'Z');
+		var startObj = new Date('1970-01-01T' + startTime + 'Z');
+		var endObj = new Date('1970-01-01T' + endTime + 'Z');
+		// 比较时间
+		return timeObj >= startObj && timeObj <= endObj;
+	}
+
 
 	// 地图配置信息
 	const mapKey = ref('KJBBZ-5JCLZ-3NLXD-742CK-Y26UZ-X7BJN'); // 地图API密钥
@@ -182,12 +252,13 @@
 		getlocation(); // 获取当前位置
 		tranAddress(); // 执行地址转换
 	}
-	
+
 	// 经纬度转地址
 	function tranAddress() {
 		let locationStr = latitude.value + ',' + longitude.value; // 组合经纬度
 		uni.request({
-			url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + locationStr + '&key=' + mapKey.value + '&get_poi=1',
+			url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + locationStr + '&key=' + mapKey.value +
+				'&get_poi=1',
 			method: 'GET',
 			success: function(res) {
 				console.log('请求成功', res.data);
@@ -202,12 +273,26 @@
 
 	// 多边形区域设置
 	const polygons = reactive([{
-		points: [
-			{ latitude: 25.9591401, longitude: 119.21292356 },
-			{ latitude: 25.95828592, longitude: 119.21261955 },
-			{ latitude: 25.9576709, longitude: 119.21458294 },
-			{ latitude: 25.95845106, longitude: 119.21486162 },
-			{ latitude: 25.9591401, longitude: 119.21292356 }
+		points: [{
+				latitude: 25.9591401,
+				longitude: 119.21292356
+			},
+			{
+				latitude: 25.95828592,
+				longitude: 119.21261955
+			},
+			{
+				latitude: 25.9576709,
+				longitude: 119.21458294
+			},
+			{
+				latitude: 25.95845106,
+				longitude: 119.21486162
+			},
+			{
+				latitude: 25.9591401,
+				longitude: 119.21292356
+			}
 		],
 		strokeWidth: 1, // 边框宽度
 		strokeColor: "#ff000066", // 边框颜色
@@ -216,13 +301,24 @@
 
 	// 打卡
 	function clockIn() {
+		//发起打卡请求相关业务逻辑(暂未实现)
+		// const params = {
+		// 	user_name: user_name,
+		// 	user_id: staffId,
+		// 	kaoqin_type: kaoqin_type,
+		// 	now_date: now_date,
+		// 	longitude: longitude,
+		// 	latitude: latitude,
+		// 	address: address,
+		// 	unitId: unitId
+		// };
 		const _polygons = polygons.map((polygon) => {
 			return polygon.points.map((i) => [
 				Number(i.longitude),
 				Number(i.latitude),
 			]);
 		});
-		const _point = point([longitude.value, latitude.value]); // 创建点
+		const _point = point([longitude.value, latitude.value]); // 用当前坐标创建点
 		const _polygon = polygon(_polygons); // 创建多边形
 		const f = booleanPointInPolygon(_point, _polygon); // 判断点是否在多边形内
 		if (f) {
@@ -230,7 +326,7 @@
 				title: "打卡成功",
 				icon: 'none'
 			});
-			return true; // 打卡成功
+			getTodayAtt(); //更新今日考勤数据
 		} else {
 			uni.showToast({
 				title: "未在指定范围,打卡失败",
@@ -242,11 +338,12 @@
 
 <style>
 	@import "@/static/font/ygoa/iconfont.css";
-	
-	.ygoa-icon{
+
+	.ygoa-icon {
 		margin-right: 20rpx;
 		font-size: 50rpx;
 	}
+
 	.container {
 		display: flex;
 		flex-direction: column;