优化省市区和占位图片
This commit is contained in:
@@ -8,7 +8,9 @@ import {
|
||||
NicknameChangeStatus,
|
||||
updateNickname as updateNicknameApi,
|
||||
} from "@/services/userService";
|
||||
import evaluateService, { LastTimeTestResult } from "@/services/evaluateService";
|
||||
import evaluateService, {
|
||||
LastTimeTestResult,
|
||||
} from "@/services/evaluateService";
|
||||
import { useListStore } from "./listStore";
|
||||
|
||||
export interface UserState {
|
||||
@@ -23,7 +25,6 @@ export interface UserState {
|
||||
fetchLastTestResult: () => Promise<LastTimeTestResult | null>;
|
||||
}
|
||||
|
||||
|
||||
const getTimeNextDate = (time: string) => {
|
||||
const date = new Date(time);
|
||||
date.setDate(date.getDate() + 1);
|
||||
@@ -51,8 +52,6 @@ export const useUser = create<UserState>()((set) => ({
|
||||
|
||||
const cachedCity = (Taro as any).getStorageSync?.(CITY_CACHE_KEY);
|
||||
|
||||
|
||||
|
||||
if (cachedCity && Array.isArray(cachedCity) && cachedCity.length === 2) {
|
||||
// 如果有缓存的城市,使用缓存,不更新 area
|
||||
console.log("[userStore] 检测到缓存的城市,使用缓存,不更新 area");
|
||||
@@ -66,7 +65,10 @@ export const useUser = create<UserState>()((set) => ({
|
||||
|
||||
// 只有当 area 不存在时才使用用户信息中的位置
|
||||
if (!currentArea) {
|
||||
const newArea: [string, string] = [userData.last_location_province||"", userData.last_location_city||""];
|
||||
const newArea: [string, string] = [
|
||||
userData.last_location_province || "",
|
||||
userData.last_location_city || "",
|
||||
];
|
||||
listStore.updateArea(newArea);
|
||||
// 保存到缓存
|
||||
useUser.getState().updateCache(newArea);
|
||||
@@ -102,8 +104,14 @@ export const useUser = create<UserState>()((set) => ({
|
||||
const listStore = useListStore.getState();
|
||||
const currentArea = listStore.area;
|
||||
// 只有当 area 不存在或与 userLastLocationProvince 不一致时才更新
|
||||
if (!currentArea || currentArea[1] !== userInfo.last_location_province) {
|
||||
const newArea: [string, string] = [userInfo.last_location_province || "", userInfo.last_location_city || ""];
|
||||
if (
|
||||
!currentArea ||
|
||||
currentArea[1] !== userInfo.last_location_province
|
||||
) {
|
||||
const newArea: [string, string] = [
|
||||
userInfo.last_location_province || "",
|
||||
userInfo.last_location_city || "",
|
||||
];
|
||||
listStore.updateArea(newArea);
|
||||
}
|
||||
}
|
||||
@@ -127,7 +135,10 @@ export const useUser = create<UserState>()((set) => ({
|
||||
// 如果已经有状态数据且不是强制更新,跳过,避免重复调用
|
||||
if (!force) {
|
||||
const currentState = useUser.getState();
|
||||
if (currentState.nicknameChangeStatus && Object.keys(currentState.nicknameChangeStatus).length > 0) {
|
||||
if (
|
||||
currentState.nicknameChangeStatus &&
|
||||
Object.keys(currentState.nicknameChangeStatus).length > 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user