feat: 切换城市
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
clearHistory,
|
||||
searchSuggestion,
|
||||
getGamesCount,
|
||||
getCities,
|
||||
getCityQrCode,
|
||||
} from "../services/listApi";
|
||||
import {
|
||||
ListActions,
|
||||
@@ -15,6 +17,19 @@ import {
|
||||
IPayload,
|
||||
} from "../../types/list/types";
|
||||
|
||||
function translateCityData(dataTree) {
|
||||
return dataTree.map((item) => {
|
||||
const { children, ...rest } = item;
|
||||
return {
|
||||
...rest,
|
||||
text: rest.name,
|
||||
label: rest.name,
|
||||
value: rest.name,
|
||||
children: children?.length > 0 ? translateCityData(children) : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 完整的 Store 类型
|
||||
type TennisStore = ListState & ListActions;
|
||||
@@ -138,6 +153,9 @@ const commonStateDefaultValue = {
|
||||
{ id: 5, label: "晚上 18:00-22:00", value: "18:00-22:00" },
|
||||
{ id: 6, label: "夜间 22:00-24:00", value: "22:00-24:00" },
|
||||
],
|
||||
cities: [],
|
||||
cityQrCode: [],
|
||||
area: ['', '', ''] as [string, string, string],
|
||||
}
|
||||
|
||||
// 创建 store
|
||||
@@ -486,6 +504,32 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
});
|
||||
console.log("===更新搜索页状态:", state);
|
||||
},
|
||||
|
||||
async getCities() {
|
||||
const res = await getCities();
|
||||
const state = get();
|
||||
set({
|
||||
...state,
|
||||
cities: translateCityData(res.data),
|
||||
})
|
||||
},
|
||||
|
||||
async getCityQrCode() {
|
||||
const res = await getCityQrCode();
|
||||
const state = get();
|
||||
set({
|
||||
...state,
|
||||
cityQrCode: res.data,
|
||||
})
|
||||
},
|
||||
|
||||
updateArea(payload: [string, string, string]) {
|
||||
const state = get();
|
||||
set({
|
||||
...state,
|
||||
area: payload,
|
||||
})
|
||||
},
|
||||
}));
|
||||
|
||||
// 导出便捷的 hooks
|
||||
|
||||
Reference in New Issue
Block a user