diff --git a/server/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/server/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md deleted file mode 100644 index 8153487..0000000 --- a/server/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/web/src/utils/lock.ts b/web/src/utils/lock.ts index 2f2cb1c..5cd9560 100644 --- a/web/src/utils/lock.ts +++ b/web/src/utils/lock.ts @@ -17,42 +17,52 @@ type Location = { longitude: number accuracy: number } + export const getCurrentLocation = async (): Promise => { if (appStore.isWorkWechat) { - const res = await ww.getLocation() - return { - latitude: res.latitude, - longitude: res.longitude, - accuracy: res.accuracy + try { + // 企业微信的 ww.getLocation 已经是 Promise-based,直接使用 + const res = await ww.getLocation(); + return { + latitude: res.latitude, + longitude: res.longitude, + accuracy: res.accuracy, + }; + } catch (error) { + ElMessage.error('在企业微信中获取位置失败'); + // 抛出错误,让调用者可以捕获 + return Promise.reject(error); } - } else if (window.navigator.geolocation) { + } + + if (window.navigator.geolocation) { return new Promise((resolve, reject) => { window.navigator.geolocation.getCurrentPosition( (position) => { resolve({ latitude: position.coords.latitude, longitude: position.coords.longitude, - accuracy: position.coords.accuracy - }) + accuracy: position.coords.accuracy, + }); }, (error) => { - ElMessage.error('获取位置失败') - resolve({ - latitude: 0, - longitude: 0, - accuracy: 0 - }) + // 在 Promise 中,错误情况应该调用 reject + ElMessage.error('获取位置失败'); + reject(error); // [9, 10, 12] + }, + // 可以增加一些选项来优化定位,例如超时设置 [13, 14] + { + timeout: 10000, // 10秒超时 + enableHighAccuracy: true, } - ) - }) - } else { - return Promise.resolve({ - latitude: 0, - longitude: 0, - accuracy: 0 - }) + ); + }); } -} + + // 如果环境完全不支持地理位置,也应该 reject + ElMessage.error('您的环境不支持获取地理位置'); + return Promise.reject(new Error('Geolocation is not supported.')); +}; // 统一执行绑定逻辑:校验锁状态 -> 获取位置 -> 记录工单 -> 批量更新状态 async function performBind(detail: any, lockId: number, operatorId: number): Promise { @@ -301,7 +311,7 @@ export const getPhoto = async () => { const file = await selectFile() const uploadRes = await updateFile({ file }) return uploadRes && uploadRes.data - } + } } catch (err) { ElMessage.error('文件上传失败') throw err