zhangwencui
2 天以前 5e6b7ee01aee58503a2449ecde4a3ac246198780
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">
@@ -149,7 +150,8 @@
            <el-tag v-else
                    type="danger"
                    size="small">
              {{ scope.row.status === 1 ? '迟到' : scope.row.status === 2 ? '早退' : '迟到、早退' }}
              <!-- {{ scope.row.status === 1 ? '迟到' : scope.row.status === 2 ? '早退' : '迟到、早退' }} -->
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
@@ -340,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(() => {