| | |
| | | // #endif |
| | | }); |
| | | }; |
| | | const form = ref({ |
| | | longitude: "", |
| | | latitude: "", |
| | | }); |
| | | |
| | | // 获取当前位置 |
| | | const getCurrentLocation = () => { |
| | | return new Promise((resolve, reject) => { |
| | | uni.showLoading({ title: "获取位置中..." }); |
| | | |
| | | uni.getLocation({ |
| | | type: "wgs84", |
| | | type: "gcj02", |
| | | success: res => { |
| | | currentLocation.value = res; |
| | | // 模拟检查是否在打卡范围内(实际项目中应根据公司位置和允许的半径进行计算) |
| | | // 这里简单模拟为始终在范围内 |
| | | inCheckRange.value = true; |
| | | resolve(res); |
| | | uni.hideLoading(); |
| | | form.value.latitude = res.latitude; |
| | | form.value.longitude = res.longitude; |
| | | }, |
| | | fail: err => { |
| | | uni.hideLoading(); |
| | | console.error("获取位置失败:", err); |
| | | // 失败时默认允许打卡(实际项目中应根据业务需求处理) |
| | | inCheckRange.value = true; |
| | | reject(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 = "位置获取失败"; |
| | | }, |
| | | }); |
| | | }; |
| | | |
| | |
| | | } |
| | | |
| | | // 调用打卡API |
| | | createPersonalAttendanceRecord({}) |
| | | createPersonalAttendanceRecord({ |
| | | ...form.value, |
| | | }) |
| | | .then(res => { |
| | | // 记录打卡时间 |
| | | lastCheckInTime.value = Date.now(); |
| | |
| | | fetchTodayData(); |
| | | }) |
| | | .catch(error => { |
| | | console.error("打卡失败:", error); |
| | | uni.showToast({ |
| | | title: error.msg || "打卡失败,请重试", |
| | | icon: "none", |
| | |
| | | |
| | | // 获取位置权限并检查位置 |
| | | try { |
| | | await getLocationPermission(); |
| | | // await getLocationPermission(); |
| | | await getCurrentLocation(); |
| | | } catch (error) { |
| | | console.error("位置权限获取失败:", error); |
| | |
| | | // 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) { |
| | |
| | | reject('无效的会话,或者会话已过期,请重新登录。') |
| | | } else if (code === 500) { |
| | | toast(msg) |
| | | reject('500') |
| | | console.error('500错误:', data) |
| | | reject(data) |
| | | } else if (code !== 200) { |
| | | toast(msg) |
| | | reject(code) |