列表综合筛选
This commit is contained in:
@@ -22,6 +22,16 @@ interface ListState {
|
||||
error: string | null
|
||||
lastRefreshTime: string | null
|
||||
isShowFilterPopup: boolean
|
||||
filterOptions: IFilterOptions
|
||||
filterCount: number
|
||||
}
|
||||
|
||||
interface IFilterOptions {
|
||||
location: string
|
||||
time: string
|
||||
ntrp: [number, number]
|
||||
site: string
|
||||
wanfa: string
|
||||
}
|
||||
|
||||
// Store Actions 接口
|
||||
@@ -35,11 +45,21 @@ interface ListActions {
|
||||
refreshMatches: () => Promise<void>
|
||||
clearError: () => void
|
||||
updateState: (payload: Record<string, any>) => void
|
||||
updateFilterOptions: (payload: Record<string, any>) => void
|
||||
clearFilterOptions: () => void
|
||||
}
|
||||
|
||||
// 完整的 Store 类型
|
||||
type TennisStore = ListState & ListActions
|
||||
|
||||
const defaultFilterOptions: IFilterOptions = {
|
||||
location: '', // 位置
|
||||
time: '', // 时间
|
||||
ntrp: [1.0, 5.0], // NTRP 水平区间
|
||||
site: '', // 场地类型
|
||||
wanfa: '', // 玩法
|
||||
};
|
||||
|
||||
// 创建 store
|
||||
export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
// 初始状态
|
||||
@@ -49,6 +69,10 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
lastRefreshTime: null,
|
||||
// 是否展示综合筛选弹窗
|
||||
isShowFilterPopup: false,
|
||||
// 综合筛选项
|
||||
filterOptions: defaultFilterOptions,
|
||||
// 综合筛选 选择的筛选数量
|
||||
filterCount: 0,
|
||||
|
||||
// 获取比赛数据
|
||||
fetchMatches: async (params) => {
|
||||
@@ -98,8 +122,30 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
clearError: () => {
|
||||
set({ error: null })
|
||||
},
|
||||
|
||||
// 更新综合筛选项
|
||||
updateFilterOptions: (payload: Record<string, any>) => {
|
||||
const preFilterOptions = get()?.filterOptions || {}
|
||||
const filterOptions = { ...preFilterOptions, ...payload }
|
||||
const filterCount = Object.values(filterOptions).filter(Boolean).length
|
||||
set({
|
||||
filterOptions,
|
||||
filterCount
|
||||
})
|
||||
},
|
||||
|
||||
// 清空综合筛选选项
|
||||
clearFilterOptions: () => {
|
||||
set({
|
||||
filterOptions: defaultFilterOptions,
|
||||
filterCount: 0
|
||||
})
|
||||
},
|
||||
|
||||
// 更新store数据
|
||||
updateState: (payload: Record<string, any>) => {
|
||||
const state = get();
|
||||
console.log('Store: 更新数据:', state);
|
||||
set({
|
||||
...(payload || {})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user