| | |
| | | }); |
| | | }; |
| | | |
| | | // 获取当前位置 |
| | | const getCurrentLocation = () => { |
| | | return new Promise((resolve, reject) => { |
| | | if (navigator.geolocation) { |
| | | navigator.geolocation.getCurrentPosition( |
| | | position => { |
| | | const { longitude, latitude } = position.coords; |
| | | resolve({ longitude, latitude }); |
| | | }, |
| | | error => { |
| | | console.log("获取位置失败:", error); |
| | | reject(error); |
| | | } |
| | | ); |
| | | } else { |
| | | reject(new Error("浏览器不支持地理定位")); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // 打卡 |
| | | const handleCheckInOut = () => { |
| | | createPersonalAttendanceRecord({}).then(res => { |
| | | fetchData(); |
| | | fetchTodayData(); |
| | | ElMessage.success("打卡成功!"); |
| | | }); |
| | | getCurrentLocation() |
| | | .then(location => { |
| | | createPersonalAttendanceRecord(location).then(res => { |
| | | fetchData(); |
| | | fetchTodayData(); |
| | | ElMessage.success("打卡成功!"); |
| | | }); |
| | | }) |
| | | .catch(error => { |
| | | // 获取位置失败时,仍允许打卡 |
| | | ElMessage.warning("获取位置失败,将使用默认位置打卡"); |
| | | createPersonalAttendanceRecord({}).then(res => { |
| | | fetchData(); |
| | | fetchTodayData(); |
| | | ElMessage.success("打卡成功!"); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |