zhangwencui
2026-02-12 ab8c184a629b4e92f7b472e2e5cbb870120afee4
src/views/personnelManagement/attendanceCheckin/index.vue
@@ -5,7 +5,8 @@
             class="mb16">
      <div class="attendance-header">
        <div>
          <div class="title">打卡签到</div>
          <div class="title">打卡签到
          </div>
          <div class="sub-title">支持一键打卡,自动记录上下班时间</div>
        </div>
        <div class="attendance-actions">
@@ -341,13 +342,45 @@
      });
  };
  // 获取当前位置
  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(() => {