列表联调

This commit is contained in:
李瑞
2025-09-07 18:54:36 +08:00
parent 2d0d728969
commit 6feb7057af
28 changed files with 1225 additions and 740 deletions

View File

@@ -1,38 +1,40 @@
import { create } from 'zustand'
import { getNavbarHeight } from '@/utils/getNavbarHeight'
import { create } from "zustand";
import { getNavbarHeight } from "@/utils/getNavbarHeight";
import { getCurrentLocation } from "@/utils/locationUtils";
interface GlobalState {
location: Record<string, any>
getLocationLoading: boolean
getLocationText: string
location: Record<string, any>;
getLocationLoading: boolean;
getLocationText: string;
statusNavbarHeightInfo: {
statusBarHeight: number
navbarHeight: number
totalHeight: number
}
statusBarHeight: number;
navbarHeight: number;
totalHeight: number;
};
}
interface GlobalActions {
updateState: (payload: Record<string, any>) => void
getNavbarHeightInfo: () => void
updateState: (payload: Record<string, any>) => void;
getNavbarHeightInfo: () => void;
getCurrentLocationInfo: () => void;
}
// 完整的 Store 类型
type GlobalStore = GlobalState & GlobalActions
type GlobalStore = GlobalState & GlobalActions;
// 创建 store
export const useGlobalStore = create<GlobalStore>()((set, get) => ({
// 位置信息
location: {},
// 正在获取位置信息
getLocationLoading: false,
getLocationLoading: true,
// 获取位置信息文本
getLocationText: '定位中...',
getLocationText: "定位中...",
// 状态栏和导航栏高度信息
statusNavbarHeightInfo: {
statusBarHeight: 0,
navbarHeight: 0,
totalHeight: 0
totalHeight: 0,
},
// 获取导航栏高度信息
@@ -42,9 +44,19 @@ export const useGlobalStore = create<GlobalStore>()((set, get) => ({
statusNavbarHeightInfo: {
statusBarHeight,
navbarHeight,
totalHeight: statusBarHeight + navbarHeight
}
})
totalHeight: statusBarHeight + navbarHeight,
},
});
},
// 获取位置信息
getCurrentLocationInfo: () => {
getCurrentLocation().then((res) => {
set({
getLocationLoading: false,
location: res || {},
});
});
},
// 更新store数据
@@ -52,10 +64,10 @@ export const useGlobalStore = create<GlobalStore>()((set, get) => ({
const state = get();
set({
...state,
...(payload || {})
})
}
}))
...(payload || {}),
});
},
}));
// 导出便捷的 hooks
export const useGlobalState = () => useGlobalStore((state) => state)
export const useGlobalState = () => useGlobalStore((state) => state);