|
@ -17,42 +17,52 @@ type Location = { |
|
|
longitude: number |
|
|
longitude: number |
|
|
accuracy: number |
|
|
accuracy: number |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export const getCurrentLocation = async (): Promise<Location> => { |
|
|
export const getCurrentLocation = async (): Promise<Location> => { |
|
|
if (appStore.isWorkWechat) { |
|
|
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) => { |
|
|
return new Promise((resolve, reject) => { |
|
|
window.navigator.geolocation.getCurrentPosition( |
|
|
window.navigator.geolocation.getCurrentPosition( |
|
|
(position) => { |
|
|
(position) => { |
|
|
resolve({ |
|
|
resolve({ |
|
|
latitude: position.coords.latitude, |
|
|
latitude: position.coords.latitude, |
|
|
longitude: position.coords.longitude, |
|
|
longitude: position.coords.longitude, |
|
|
accuracy: position.coords.accuracy |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
accuracy: position.coords.accuracy, |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
(error) => { |
|
|
(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<void> { |
|
|
async function performBind(detail: any, lockId: number, operatorId: number): Promise<void> { |
|
@ -301,7 +311,7 @@ export const getPhoto = async () => { |
|
|
const file = await selectFile() |
|
|
const file = await selectFile() |
|
|
const uploadRes = await updateFile({ file }) |
|
|
const uploadRes = await updateFile({ file }) |
|
|
return uploadRes && uploadRes.data |
|
|
return uploadRes && uploadRes.data |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
ElMessage.error('文件上传失败') |
|
|
ElMessage.error('文件上传失败') |
|
|
throw err |
|
|
throw err |
|
|