|
|
@@ -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;
|