修改微信获取用户地址

This commit is contained in:
lccsw
2025-12-09 16:48:38 +08:00
parent 9f7b99b5fa
commit 07e41c56ba
+31 -25
View File
@@ -357,45 +357,51 @@ const getDictionaryList = async (dictCode = 'carProductLabel,priceRange,productL
* @returns {Promise<void>}
*/
const getCurrentLocation = async () => {
// 非微信环境从URL获取cityId
const urlParams = new URLSearchParams(window.location.search)
const urlCityId = urlParams.get('cityId')
try {
// 检查是否为微信浏览器
const isWechat = WechatAuth.isWechatBrowser();
const isWechat = WechatAuth.isWechatBrowser()
if (!isWechat) {
// 非微信环境从URL获取cityId
const urlParams = new URLSearchParams(window.location.search);
const urlCityId = urlParams.get('cityId');
if (urlCityId) {
try {
const cityResult = await api.get('/auto/config/city',{cityId:urlCityId});
const cityResult = await api.get('/auto/config/city', { cityId: urlCityId })
if (cityResult.code === 200 && cityResult.data) {
cacheLocationInfo("", cityResult.data);
await handleCityInfo(cityResult.data);
return;
cacheLocationInfo('', cityResult.data)
await handleCityInfo(cityResult.data)
return
}
} catch (cityError) {
console.error('通过cityId获取城市信息失败:', cityError);
console.error('通过cityId获取城市信息失败:', cityError)
}
}
}
// 微信环境或非微信环境未获取到cityId时使用定位逻辑
const location = await getUserLocation();
console.log('当前位置:', location);
const location = await getUserLocation()
console.log('当前位置:', location)
if (!(location && location.latitude && location.longitude)) {
return;
return
}
const cityInfoData = await getCityInfo(location);
const cityInfoData = await getCityInfo(location)
if (cityInfoData && cityInfoData.cityId) {
cacheLocationInfo(location, cityInfoData);
await handleCityInfo(cityInfoData);
cacheLocationInfo(location, cityInfoData)
await handleCityInfo(cityInfoData)
}
} catch (error) {
console.error('获取位置或解析城市失败:', error);
console.error('获取位置或解析城市失败:', error)
if (urlCityId) {
const cityResult = await api.get('/auto/config/city', { cityId: urlCityId })
if (cityResult.code === 200 && cityResult.data) {
cacheLocationInfo('', cityResult.data)
await handleCityInfo(cityResult.data)
}
}
}
}
/**
@@ -403,15 +409,15 @@ const getCurrentLocation = async () => {
* @param {Object} cityInfoData 城市信息数据
*/
const handleCityInfo = async (cityInfoData) => {
cityInfo.value = cityInfoData;
console.log('城市信息:', cityInfoData);
cityInfo.value = cityInfoData
console.log('城市信息:', cityInfoData)
const userStore = useUserStore();
userStore.setCity(cityInfoData);
query_data.cityId = cityInfoData.cityId;
const userStore = useUserStore()
userStore.setCity(cityInfoData)
query_data.cityId = cityInfoData.cityId
empty.value = false;
await getProductList();
empty.value = false
await getProductList()
}
/**
* 获取产品列表
@@ -550,7 +556,7 @@ const handleCityItem = (item) => {
// localStorage.setItem('cityInfo', JSON.stringify(cityInfo.value));
// 修改为使用 cookie 存储
// setCookie('cityInfo', cityInfo.value, 1)
cacheLocationInfo("", cityInfo.value);
cacheLocationInfo('', cityInfo.value)
getCityBrands()
getProductList()
}