gaoluyang
昨天 fcf6e5286e72d2df817ac077b47acd2bfc1e0649
src/pages/humanResources/attendance/checkin.vue
@@ -129,7 +129,12 @@
    findTodayPersonalAttendanceRecord({}).then(res => {
      if (res.data) {
        todayRecord.value = res.data;
        noNeedCheckIn.value = false;
        // 检查startAt和endAt是否为空,为空则无需打卡
        if (!todayRecord.value.startAt || !todayRecord.value.endAt) {
          noNeedCheckIn.value = true;
        } else {
          noNeedCheckIn.value = false;
        }
      } else {
        // 页面显示“无需打卡”
        todayRecord.value = {};
@@ -236,26 +241,52 @@
      // #endif
    });
  };
  const form = ref({
    longitude: "",
    latitude: "",
  });
  // 获取当前位置
  const getCurrentLocation = () => {
    return new Promise((resolve, reject) => {
      uni.getLocation({
        type: "wgs84",
        success: res => {
          currentLocation.value = res;
          // 模拟检查是否在打卡范围内(实际项目中应根据公司位置和允许的半径进行计算)
          // 这里简单模拟为始终在范围内
          inCheckRange.value = true;
          resolve(res);
        },
        fail: err => {
          console.error("获取位置失败:", err);
          // 失败时默认允许打卡(实际项目中应根据业务需求处理)
          inCheckRange.value = true;
          reject(err);
        },
      });
    uni.showLoading({ title: "获取位置中..." });
    uni.getLocation({
      type: "gcj02",
      success: res => {
        uni.hideLoading();
        form.value.latitude = res.latitude;
        form.value.longitude = res.longitude;
      },
      fail: err => {
        uni.hideLoading();
        console.error("获取位置失败:", err);
        // 显示错误提示并引导用户检查权限
        showToast("获取位置失败,请检查定位权限");
        // 引导用户检查权限设置
        uni.showModal({
          title: "位置权限提示",
          content:
            "获取位置失败,可能是因为位置权限未开启,请在设备设置中检查并开启位置权限。",
          confirmText: "知道了",
          cancelText: "取消",
          success: res => {
            if (res.confirm) {
              // 可以尝试打开设置页面(如果支持)
              if (uni.openSetting) {
                uni.openSetting({
                  success: settingRes => {
                    console.log("设置结果:", settingRes);
                  },
                });
              }
            }
          },
        });
        // 失败时显示错误信息
        form.value.visitAddress = "位置获取失败";
      },
    });
  };
@@ -318,7 +349,9 @@
    }
    // 调用打卡API
    createPersonalAttendanceRecord({})
    createPersonalAttendanceRecord({
      ...form.value,
    })
      .then(res => {
        // 记录打卡时间
        lastCheckInTime.value = Date.now();
@@ -331,7 +364,6 @@
        fetchTodayData();
      })
      .catch(error => {
        console.error("打卡失败:", error);
        uni.showToast({
          title: error.msg || "打卡失败,请重试",
          icon: "none",
@@ -347,7 +379,7 @@
    // 获取位置权限并检查位置
    try {
      await getLocationPermission();
      // await getLocationPermission();
      await getCurrentLocation();
    } catch (error) {
      console.error("位置权限获取失败:", error);