|
|
@@ -52,6 +52,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// 导入地理位置相关函数
|
|
|
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
|
import {
|
|
|
@@ -65,12 +66,15 @@
|
|
|
import {
|
|
|
useUserStore
|
|
|
} from '@/store/user';
|
|
|
+ import {createAttendance} from '@/api/mine/clockIn.js'
|
|
|
const userStore = useUserStore();
|
|
|
-
|
|
|
+ const thisUser=ref();
|
|
|
const userId = ref('')
|
|
|
|
|
|
// 组件挂载后初始化当前日期与位置
|
|
|
onMounted(() => {
|
|
|
+ thisUser.value=userStore.user;
|
|
|
+ console.log('thisUser',thisUser.value);
|
|
|
userId.value = userStore.user.useId;
|
|
|
dateInit();
|
|
|
getlocation();
|
|
|
@@ -102,12 +106,14 @@
|
|
|
|
|
|
//获取今天考勤状态
|
|
|
function getTodayAtt() {
|
|
|
+
|
|
|
const params = {
|
|
|
universalid: userId.value,
|
|
|
rizi: currentDate.value
|
|
|
}
|
|
|
CheckAttendance(params).then(res => {
|
|
|
if ("success" == res.returnMsg) {
|
|
|
+ // console.log("kaoqin",res);
|
|
|
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');
|
|
|
@@ -121,6 +127,7 @@
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+const attType=ref(0)
|
|
|
// 上班签到
|
|
|
function signIn() {
|
|
|
const now = getNowTime();
|
|
|
@@ -132,8 +139,9 @@
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
- getlocation(); // 获取当前位置
|
|
|
- tranAddress(); // 转换地址
|
|
|
+ attType.value=1;
|
|
|
+
|
|
|
+ getAddress();
|
|
|
clockIn(); // 执行打卡
|
|
|
};
|
|
|
|
|
|
@@ -148,8 +156,8 @@
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
- getlocation(); // 获取当前位置
|
|
|
- tranAddress(); // 转换地址
|
|
|
+ attType.value=2;
|
|
|
+ getAddress();
|
|
|
clockIn(); // 执行打卡并获取结果
|
|
|
};
|
|
|
|
|
|
@@ -200,8 +208,10 @@
|
|
|
// 获取当前定位经纬度
|
|
|
function getlocation() {
|
|
|
wx.getLocation({
|
|
|
- type: 'gcj02',
|
|
|
+ // type: 'gcj02',
|
|
|
success: (res) => {
|
|
|
+ // console.log('当前位置的经度:' + JSON.stringify(res));
|
|
|
+ // console.log('当前位置的经度:','gcj02' + JSON.stringify(res));
|
|
|
console.log('当前位置的经度:' + res.longitude);
|
|
|
console.log('当前位置的纬度:' + res.latitude);
|
|
|
longitude.value = res.longitude; // 保存经度
|
|
|
@@ -223,7 +233,7 @@
|
|
|
});
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
- console.log(err);
|
|
|
+ // console.log(err);
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
@@ -301,38 +311,47 @@
|
|
|
|
|
|
// 打卡
|
|
|
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 _polygon = polygon(_polygons); // 创建多边形
|
|
|
- const f = booleanPointInPolygon(_point, _polygon); // 判断点是否在多边形内
|
|
|
- if (f) {
|
|
|
- uni.showToast({
|
|
|
- title: "打卡成功",
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- getTodayAtt(); //更新今日考勤数据
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: "未在指定范围,打卡失败",
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
+ //TODO: 发起打卡请求相关业务逻辑
|
|
|
+ var now = new Date();
|
|
|
+ // 使用toISOString()获取一个ISO格式的字符串,然后替换T为空格,并去除最后的Z(表示UTC时间)
|
|
|
+ var formatted = now.toISOString().replace('T', ' ').replace('Z', '');
|
|
|
+ var localString = new Date(formatted + '+08:00').toISOString().replace('T', ' ').replace('Z', '');
|
|
|
+ const params = {
|
|
|
+ user_name: thisUser.value.userName,
|
|
|
+ user_id: thisUser.value.useId,
|
|
|
+ kaoqin_type: attType.value,
|
|
|
+ now_date: localString,
|
|
|
+ longitude: longitude.value,
|
|
|
+ latitude: latitude.value,
|
|
|
+ address: address.value,
|
|
|
+ unitId: thisUser.value.unitId
|
|
|
+ };
|
|
|
+ createAttendance(params).then(res=>{
|
|
|
+ // console.log('createAttendance',res);
|
|
|
+ if ("success"==res.returnMsg) {
|
|
|
+ uni.showToast({
|
|
|
+ title: "打卡成功",
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ getTodayAtt(); //更新今日考勤数据
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: "未在指定范围,打卡失败",
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // const _polygons = polygons.map((polygon) => {
|
|
|
+ // return polygon.points.map((i) => [
|
|
|
+ // Number(i.longitude),
|
|
|
+ // Number(i.latitude),
|
|
|
+ // ]);
|
|
|
+ // });
|
|
|
+ // const _point = point([longitude.value, latitude.value]); // 用当前坐标创建点
|
|
|
+ // const _polygon = polygon(_polygons); // 创建多边形
|
|
|
+ // const f = booleanPointInPolygon(_point, _polygon); // 判断点是否在多边形内
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
</script>
|
|
|
|