2025-03-28 15:19:42 +08:00
|
|
|
import {
|
|
|
|
|
defineStore
|
|
|
|
|
} from 'pinia';
|
|
|
|
|
import {
|
|
|
|
|
ref
|
|
|
|
|
} from 'vue'
|
|
|
|
|
import {
|
|
|
|
|
msg
|
|
|
|
|
} from '@/common/globalFunction.js'
|
2025-06-20 10:10:46 +08:00
|
|
|
import config from '../config';
|
|
|
|
|
|
2025-03-28 15:19:42 +08:00
|
|
|
const useLocationStore = defineStore("location", () => {
|
|
|
|
|
// 定义状态
|
2025-05-13 11:10:38 +08:00
|
|
|
const longitudeVal = ref(null) // 经度
|
|
|
|
|
const latitudeVal = ref(null) //纬度
|
2025-03-28 15:19:42 +08:00
|
|
|
|
|
|
|
|
function getLocation() {
|
|
|
|
|
return new Promise((resole, reject) => {
|
2025-11-24 18:40:59 +08:00
|
|
|
try {
|
|
|
|
|
lightAppJssdk.map.getLocation({
|
|
|
|
|
success: function(data) {
|
|
|
|
|
longitudeVal.value = Number(data.longitude)
|
|
|
|
|
latitudeVal.value = Number(data.latitude)
|
|
|
|
|
resole(data)
|
|
|
|
|
},
|
|
|
|
|
fail: function(data) {
|
|
|
|
|
longitudeVal.value = 120.382665
|
|
|
|
|
latitudeVal.value = 36.066938
|
|
|
|
|
resole({
|
|
|
|
|
longitude: 120.382665,
|
|
|
|
|
latitude: 36.066938
|
|
|
|
|
})
|
|
|
|
|
msg('用户位置获取失败')
|
|
|
|
|
console.log('失败', data)
|
2025-03-28 15:19:42 +08:00
|
|
|
}
|
2025-11-24 18:40:59 +08:00
|
|
|
})
|
|
|
|
|
} catch (e) {
|
|
|
|
|
longitudeVal.value = 120.382665
|
|
|
|
|
latitudeVal.value = 36.066938
|
|
|
|
|
resole({
|
|
|
|
|
longitude: 120.382665,
|
|
|
|
|
latitude: 36.066938
|
|
|
|
|
})
|
|
|
|
|
msg('测试环境,使用模拟定位')
|
|
|
|
|
console.log('失败', data)
|
|
|
|
|
}
|
2025-03-28 15:19:42 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function longitude() {
|
|
|
|
|
return longitudeVal.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function latitude() {
|
|
|
|
|
return latitudeVal.value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 导入
|
|
|
|
|
return {
|
|
|
|
|
getLocation,
|
2025-05-13 11:10:38 +08:00
|
|
|
longitudeVal,
|
|
|
|
|
latitudeVal
|
|
|
|
|
|
2025-03-28 15:19:42 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default useLocationStore;
|