优化展示逻辑

This commit is contained in:
李瑞
2025-10-13 00:07:31 +08:00
parent 12600ebdfb
commit 99671667f3
5 changed files with 10 additions and 31 deletions

View File

@@ -13,6 +13,7 @@ import { useRef, useEffect } from "react";
const ListContainer = (props) => { const ListContainer = (props) => {
const { const {
loading, loading,
isShowNoData,
data = [], data = [],
error, error,
reload, reload,
@@ -84,7 +85,7 @@ const ListContainer = (props) => {
// 渲染列表 // 渲染列表
const renderList = (list) => { const renderList = (list) => {
// 请求数据为空 // 请求数据为空
if (!loading && (!list || list?.length === 0)) { if (isShowNoData) {
return <ListLoadError reload={reload} errorImg={errorImg} btnText={btnText} btnImg={btnImg} text={emptyText || "暂无数据"} />; return <ListLoadError reload={reload} errorImg={errorImg} btnText={btnText} btnImg={btnImg} text={emptyText || "暂无数据"} />;
} }

View File

@@ -58,6 +58,7 @@ const ListPage = () => {
distanceQuickFilter, distanceQuickFilter,
isShowInputCustomerNavBar, isShowInputCustomerNavBar,
pageOption, pageOption,
isShowNoData,
} = listPageState || {}; } = listPageState || {};
// 防抖的滚动处理函数 // 防抖的滚动处理函数
@@ -376,6 +377,7 @@ const ListPage = () => {
data={matches} data={matches}
recommendList={recommendList} recommendList={recommendList}
loading={loading} loading={loading}
isShowNoData={isShowNoData}
error={error} error={error}
reload={refreshMatches} reload={refreshMatches}
loadMoreMatches={loadMoreMatches} loadMoreMatches={loadMoreMatches}

View File

@@ -35,6 +35,7 @@ const SearchResult = () => {
recommendList, recommendList,
filterCount, filterCount,
filterOptions, filterOptions,
isShowNoData,
} = searchPageState || {}; } = searchPageState || {};
const { statusNavbarHeightInfo } = useGlobalState() || {}; const { statusNavbarHeightInfo } = useGlobalState() || {};
const { totalHeight } = statusNavbarHeightInfo || {}; const { totalHeight } = statusNavbarHeightInfo || {};
@@ -166,6 +167,7 @@ const SearchResult = () => {
data={data} data={data}
recommendList={recommendList} recommendList={recommendList}
loading={loading} loading={loading}
isShowNoData={isShowNoData}
error={error} error={error}
reload={refreshMatches} reload={refreshMatches}
loadMoreMatches={loadMoreMatches} loadMoreMatches={loadMoreMatches}

View File

@@ -60,6 +60,8 @@ const pageStateDefaultValue = {
gamesNum: 0, gamesNum: 0,
// 是否还有更多数据 // 是否还有更多数据
isHasMoreData: true, isHasMoreData: true,
// 是否展示无数据
isShowNoData: false,
} }
// 列表页状态 // 列表页状态
@@ -187,40 +189,13 @@ export const useListStore = create<TennisStore>()((set, get) => ({
state.updateCurrentPageState({ state.updateCurrentPageState({
data: newData, data: newData,
isHasMoreData, isHasMoreData,
isShowNoData: newData?.length === 0,
}); });
set({ set({
error, error,
loading, loading,
}); });
if (state.isSearchResult) {
// 更新搜索页状态
// const currentData = state.searchPageState?.data || [];
// const newData = isAppend ? [...currentData, ...(data || [])] : (data || []);
// set({
// searchPageState: {
// ...state.searchPageState,
// data: newData,
// isHasMoreData,
// },
// error,
// loading,
// });
} else {
// 更新列表页状态
// const currentData = state.listPageState?.data || [];
// const newData = isAppend ? [...currentData, ...(data || [])] : (data || []);
// set({
// listPageState: {
// ...state.listPageState,
// data: newData,
// isHasMoreData,
// },
// error,
// loading,
// });
}
}, },
// 获取列表数据(常规搜索) // 获取列表数据(常规搜索)
@@ -241,7 +216,6 @@ export const useListStore = create<TennisStore>()((set, get) => ({
// 获取当前页面的距离筛选 // 获取当前页面的距离筛选
const state = get(); const state = get();
const currentPageState = state.isSearchResult ? state.searchPageState : state.listPageState; const currentPageState = state.isSearchResult ? state.searchPageState : state.listPageState;
console.log("===获取列表数据=当前页面状态:", state.isSearchResult, currentPageState);
const distanceQuickFilter = currentPageState?.distanceQuickFilter || {}; const distanceQuickFilter = currentPageState?.distanceQuickFilter || {};
// 是否选择了智能排序 // 是否选择了智能排序
@@ -258,7 +232,6 @@ export const useListStore = create<TennisStore>()((set, get) => ({
} }
} }
console.log("===获取列表数据参数:", reqParams);
const resData = (await fetchFn(reqParams)) || {}; const resData = (await fetchFn(reqParams)) || {};
const { data = {}, code } = resData; const { data = {}, code } = resData;
if (code !== 0) { if (code !== 0) {

View File

@@ -38,6 +38,7 @@ export interface PageState {
} }
gamesNum: number gamesNum: number
isHasMoreData: boolean isHasMoreData: boolean
isShowNoData: boolean
} }
// 列表页状态 // 列表页状态