This commit is contained in:
张成
2026-02-06 00:26:31 +08:00
parent 969066591c
commit d149de1f42
9 changed files with 91 additions and 73 deletions

View File

@@ -48,10 +48,10 @@ export const useUser = create<UserState>()((set) => ({
// 优先使用缓存中的城市,不使用用户信息中的位置
// 检查是否有缓存的城市
const cachedCity = (Taro as any).getStorageSync?.(CITY_CACHE_KEY);
if (cachedCity && Array.isArray(cachedCity) && cachedCity.length === 2) {
// 如果有缓存的城市,使用缓存,不更新 area
@@ -63,10 +63,10 @@ export const useUser = create<UserState>()((set) => ({
if (userData?.last_location_province) {
const listStore = useListStore.getState();
const currentArea = listStore.area;
// 只有当 area 不存在时才使用用户信息中的位置
if (!currentArea) {
const newArea: [string, string] = ["中国", userData.last_location_province];
const newArea: [string, string] = [userData.last_location_province||"", userData.last_location_city||""];
listStore.updateArea(newArea);
// 保存到缓存
useUser.getState().updateCache(newArea);
@@ -103,7 +103,7 @@ export const useUser = create<UserState>()((set) => ({
const currentArea = listStore.area;
// 只有当 area 不存在或与 userLastLocationProvince 不一致时才更新
if (!currentArea || currentArea[1] !== userInfo.last_location_province) {
const newArea: [string, string] = ["中国", userInfo.last_location_province];
const newArea: [string, string] = [userInfo.last_location_province || "", userInfo.last_location_city || ""];
listStore.updateArea(newArea);
}
}