列表综合筛选
This commit is contained in:
@@ -1,53 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { getTennisMatches } from '../services/listApi'
|
||||
|
||||
// 网球比赛数据接口
|
||||
export interface TennisMatch {
|
||||
id: string
|
||||
title: string
|
||||
dateTime: string
|
||||
location: string
|
||||
distance: string
|
||||
registeredCount: number
|
||||
maxCount: number
|
||||
skillLevel: string
|
||||
matchType: string
|
||||
images: string[]
|
||||
}
|
||||
|
||||
// Store 状态接口
|
||||
interface ListState {
|
||||
matches: TennisMatch[]
|
||||
loading: boolean
|
||||
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 接口
|
||||
interface ListActions {
|
||||
fetchMatches: (params?: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
location?: string
|
||||
skillLevel?: string
|
||||
}) => Promise<void>
|
||||
refreshMatches: () => Promise<void>
|
||||
clearError: () => void
|
||||
updateState: (payload: Record<string, any>) => void
|
||||
updateFilterOptions: (payload: Record<string, any>) => void
|
||||
clearFilterOptions: () => void
|
||||
}
|
||||
import {ListActions, IFilterOptions, ListState } from '../../types/list/types'
|
||||
|
||||
// 完整的 Store 类型
|
||||
type TennisStore = ListState & ListActions
|
||||
@@ -60,6 +13,8 @@ const defaultFilterOptions: IFilterOptions = {
|
||||
wanfa: '', // 玩法
|
||||
};
|
||||
|
||||
const defaultDistance = 'all'; // 默认距离
|
||||
|
||||
// 创建 store
|
||||
export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
// 初始状态
|
||||
@@ -73,6 +28,43 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
filterOptions: defaultFilterOptions,
|
||||
// 综合筛选 选择的筛选数量
|
||||
filterCount: 0,
|
||||
// 距离筛选
|
||||
distance: defaultDistance,
|
||||
// 快捷筛选
|
||||
quickFilter: 1, // 1: 默认 2: 好评 3: 销量
|
||||
// 距离筛选数据
|
||||
distanceData: [
|
||||
{ id: 0, label: "全城", value: "全城" },
|
||||
{ id: 1, label: "3km", value: "3km" },
|
||||
{ id: 2, label: "5km", value: "5km" },
|
||||
{ id: 3, label: "10km", value: "10km" },
|
||||
],
|
||||
// 快捷筛选数据
|
||||
quickFilterData:[
|
||||
{ text: "默认排序", value: "0" },
|
||||
{ text: "好评排序", value: "1" },
|
||||
{ text: "销量排序", value: "2" },
|
||||
],
|
||||
// 距离筛选和快捷筛选
|
||||
distanceQuickFilter: {
|
||||
distance: '全城',
|
||||
quick: '0',
|
||||
},
|
||||
// 时间气泡数据
|
||||
timeBubbleData: [
|
||||
{ id: 1, label: "晨间 6:00-10:00", value: "1" },
|
||||
{ id: 2, label: "上午 10:00-12:00", value: "2" },
|
||||
{ id: 3, label: "中午 12:00-14:00", value: "3" },
|
||||
{ id: 4, label: "下午 14:00-18:00", value: "4" },
|
||||
{ id: 5, label: "晚上 18:00-22:00", value: "5" },
|
||||
{ id: 6, label: "夜间 22:00-24:00", value: "6" },
|
||||
],
|
||||
// 场地类型数据
|
||||
locationOptions: [
|
||||
{ id: 1, label: "室内", value: "1" },
|
||||
{ id: 2, label: "室外", value: "2" },
|
||||
{ id: 3, label: "半室外", value: "3" },
|
||||
],
|
||||
|
||||
// 获取比赛数据
|
||||
fetchMatches: async (params) => {
|
||||
@@ -87,12 +79,12 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
})
|
||||
console.log('Store: 成功获取网球比赛数据:', matches.length, '条')
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : '未知错误'
|
||||
set({
|
||||
error: errorMessage,
|
||||
loading: false
|
||||
})
|
||||
console.error('Store: 获取网球比赛数据失败:', errorMessage)
|
||||
// const errorMessage = error instanceof Error ? error.message : '未知错误'
|
||||
// set({
|
||||
// error: errorMessage,
|
||||
// loading: false
|
||||
// })
|
||||
// console.error('Store: 获取网球比赛数据失败:', errorMessage)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -109,12 +101,12 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
})
|
||||
console.log('Store: 成功刷新网球比赛数据:', matches.length, '条')
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : '未知错误'
|
||||
set({
|
||||
error: errorMessage,
|
||||
loading: false
|
||||
})
|
||||
console.error('Store: 刷新网球比赛数据失败:', errorMessage)
|
||||
// const errorMessage = error instanceof Error ? error.message : '未知错误'
|
||||
// set({
|
||||
// error: errorMessage,
|
||||
// loading: false
|
||||
// })
|
||||
// console.error('Store: 刷新网球比赛数据失败:', errorMessage)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user