zhangwencui
2 天以前 7502e761d845348282bf72b17a4cc3f24572f013
打卡签到传参
已修改2个文件
77 ■■■■ 文件已修改
src/pages/humanResources/attendance/checkin.vue 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/request.ts 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/humanResources/attendance/checkin.vue
@@ -236,26 +236,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 +344,9 @@
    }
    // 调用打卡API
    createPersonalAttendanceRecord({})
    createPersonalAttendanceRecord({
      ...form.value,
    })
      .then(res => {
        // 记录打卡时间
        lastCheckInTime.value = Date.now();
@@ -331,7 +359,6 @@
        fetchTodayData();
      })
      .catch(error => {
        console.error("打卡失败:", error);
        uni.showToast({
          title: error.msg || "打卡失败,请重试",
          icon: "none",
@@ -347,7 +374,7 @@
    // 获取位置权限并检查位置
    try {
      await getLocationPermission();
      // await getLocationPermission();
      await getCurrentLocation();
    } catch (error) {
      console.error("位置权限获取失败:", error);
src/utils/request.ts
@@ -54,6 +54,11 @@
      //   code: code,
      //   data: data
      // })
      console.log('接收到的参数:', {
        url: (config.baseUrl || baseUrl) + config.url,
        code: code,
        data: data
      })
      if (code === 401) {
        showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
          if (res.confirm) {
@@ -65,7 +70,8 @@
        reject('无效的会话,或者会话已过期,请重新登录。')
      } else if (code === 500) {
        toast(msg)
        reject('500')
        console.error('500错误:', data)
        reject(data)
      } else if (code !== 200) {
        toast(msg)
        reject(code)