This commit is contained in:
juguohong
2025-08-31 20:24:42 +08:00
parent d92419f3c5
commit 4e68db2476
28 changed files with 921 additions and 206 deletions

View File

@@ -1,5 +1,5 @@
import { create } from 'zustand'
import { getTennisMatches } from '../services/listApi'
import { getTennisMatches, getSearchHistory, clearHistory, searchSuggestion } from '../services/listApi'
import { ListActions, IFilterOptions, ListState } from '../../types/list/types'
// 完整的 Store 类型
@@ -21,7 +21,8 @@ export const useListStore = create<TennisStore>()((set, get) => ({
matches: [],
loading: false,
error: null,
lastRefreshTime: null,
// 搜索的value
searchValue: '',
// 是否展示综合筛选弹窗
isShowFilterPopup: false,
// 综合筛选项
@@ -77,6 +78,19 @@ export const useListStore = create<TennisStore>()((set, get) => ({
gamesNum: 124,
// 页面滚动距离顶部距离 是否大于0
isScrollTop: false,
// 搜索历史数据
searchHistory: ['上海', '黄浦', '上海', '静安', '徐汇', '黄浦', '普陀', '黄浦', '长宁', '黄浦'],
// 搜索历史数据默认 Top 15
searchHistoryParams: {
page: 1,
pageSize: 15,
},
// 联想词
suggestionList: [],
// 是否显示联想词
isShowSuggestion: false,
// 是否显示搜索框自定义导航
isShowInputCustomerNavBar: false,
// 获取比赛数据
fetchMatches: async (params) => {
@@ -135,12 +149,51 @@ export const useListStore = create<TennisStore>()((set, get) => ({
set({
matches: rows,
loading: false,
lastRefreshTime: new Date().toISOString()
})
} catch (error) {
}
},
// 获取历史搜索数据
getSearchHistory: async () => {
try {
const params = get()?.searchHistoryParams || {}
const resData = await getSearchHistory(params) || {};
console.log('===resData', resData)
} catch (error) {
}
},
// 清空历史记录
clearHistory: async () => {
try {
const resData = await clearHistory() || {};
} catch (error) {
}
set({
searchHistory: [],
})
},
// 获取联想
searchSuggestion: async (val: string) => {
try {
const resData = await searchSuggestion({ val }) || {};
console.log('===获取联想', resData)
// set({
// suggestionList: ['上海球局', '黄浦球局', '上海球局', '静安球局', '徐汇球局', '黄浦球局', '普陀球局', '黄浦球局', '长宁球局', '黄浦球局'],
// isShowSuggestion: true,
// })
} catch (error) {
set({
suggestionList: ['上海球局', '黄浦球局', '上海球局', '静安球局', '徐汇球局', '黄浦球局', '普陀球局', '黄浦球局', '长宁球局', '黄浦球局'],
isShowSuggestion: true,
})
}
},
// 清除错误信息
clearError: () => {
set({ error: null })