列表
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { getTennisMatches } from '../services/listApi'
|
||||
import {ListActions, IFilterOptions, ListState } from '../../types/list/types'
|
||||
import { ListActions, IFilterOptions, ListState } from '../../types/list/types'
|
||||
|
||||
// 完整的 Store 类型
|
||||
type TennisStore = ListState & ListActions
|
||||
@@ -40,7 +40,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
{ id: 3, label: "10km", value: "10km" },
|
||||
],
|
||||
// 快捷筛选数据
|
||||
quickFilterData:[
|
||||
quickFilterData: [
|
||||
{ text: "默认排序", value: "0" },
|
||||
{ text: "好评排序", value: "1" },
|
||||
{ text: "销量排序", value: "2" },
|
||||
@@ -75,6 +75,8 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
],
|
||||
// 球局数量
|
||||
gamesNum: 124,
|
||||
// 页面滚动距离顶部距离 是否大于0
|
||||
isScrollTop: false,
|
||||
|
||||
// 获取比赛数据
|
||||
fetchMatches: async (params) => {
|
||||
@@ -83,15 +85,42 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
try {
|
||||
const resData = await getTennisMatches(params) || {};
|
||||
const { data = {}, code } = resData;
|
||||
if (code !== 0) {
|
||||
set({
|
||||
error: '1',
|
||||
matches: [],
|
||||
loading: false,
|
||||
})
|
||||
}
|
||||
const { count, rows } = data;
|
||||
const list = (rows || []).map(() => {
|
||||
return {
|
||||
id: "3",
|
||||
title: "黄浦区双打约球",
|
||||
dateTime: "7月20日(周日)下午6点 2小时",
|
||||
location: "仁恒河滨花园网球场",
|
||||
distance: "3.5km",
|
||||
registeredCount: 3,
|
||||
maxCount: 4,
|
||||
skillLevel: "2.0 至 2.5",
|
||||
matchType: "双打",
|
||||
images: [
|
||||
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
|
||||
],
|
||||
}
|
||||
})
|
||||
set({
|
||||
matches: rows || [],
|
||||
matches: list || rows || [],
|
||||
loading: false,
|
||||
// lastRefreshTime: new Date().toISOString()
|
||||
gamesNum: count,
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
|
||||
set({
|
||||
error,
|
||||
matches: [],
|
||||
loading: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -100,13 +129,14 @@ export const useListStore = create<TennisStore>()((set, get) => ({
|
||||
set({ loading: true, error: null })
|
||||
|
||||
try {
|
||||
const matches = await getTennisMatches()
|
||||
const resData = await getTennisMatches() || {};
|
||||
const { data = {}, code } = resData;
|
||||
const { count, rows } = data;
|
||||
set({
|
||||
matches,
|
||||
matches: rows,
|
||||
loading: false,
|
||||
lastRefreshTime: new Date().toISOString()
|
||||
})
|
||||
console.log('Store: 成功刷新网球比赛数据:', matches.length, '条')
|
||||
} catch (error) {
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user