From 8a1a2af1e9035e3455f28cdc9ed971b7f5f7fe96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=91=9E?= Date: Mon, 8 Sep 2025 23:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/FilterPopup/index.tsx | 57 ++++------------------------ src/components/Range/index.tsx | 4 +- src/store/global.ts | 3 +- src/store/listStore.ts | 14 +++---- types/list/types.ts | 3 +- 5 files changed, 19 insertions(+), 62 deletions(-) diff --git a/src/components/FilterPopup/index.tsx b/src/components/FilterPopup/index.tsx index 1aff3d9..9aedd48 100644 --- a/src/components/FilterPopup/index.tsx +++ b/src/components/FilterPopup/index.tsx @@ -6,7 +6,6 @@ import styles from "./index.module.scss"; import { Button } from "@nutui/nutui-react-taro"; import { useListStore } from "src/store/listStore"; import { BubbleOption, FilterPopupProps } from "../../../types/list/types"; -import dateRangeUtils from '@/utils/dateRange' import dayjs from "dayjs"; import { CalendarUI } from "@/components"; // 场地 @@ -16,13 +15,6 @@ import GamePlayType from "@/components/GamePlayType"; import { useDictionaryActions } from "@/store/dictionaryStore"; import { View } from "@tarojs/components"; - -const dateTrabseformMap = { - '1': dateRangeUtils.getThisWeekend, - '2': dateRangeUtils.getNextWeekRange, - '3': dateRangeUtils.getNextMonthRange -} - const FilterPopup = (props: FilterPopupProps) => { const { loading, @@ -44,12 +36,13 @@ const FilterPopup = (props: FilterPopupProps) => { * @param dictionaryValue 字典选项 * @returns 选项列表 */ - const [selectedDates, setSelectedDates] = useState([]) + // const [selectedDates, setSelectedDates] = useState([]) const handleDateChange = (dates: Date[]) => { const dateArray = dates.map(date => dayjs(date).format('YYYY-MM-DD')) - setSelectedDates(dateArray) - console.log('选中的日期:', dateArray) + onChange({ + 'dateRange': dateArray, + }) } const handleOptions = (dictionaryValue: []) => { @@ -89,29 +82,6 @@ const FilterPopup = (props: FilterPopupProps) => { onCancel(); }; - /** - * @description 日期选择 - * @param date 日期 - */ - const handleDateRangeChange = (date: Date) => { - onChange({ - 'dateRange': [date, date], - 'dateRangeQuick': '', - }) - } - - /** - * @description 点击 本周末 一周内 一月内 - */ - const handleDateRangeQuickClick = (name, value) => { - const date = dateTrabseformMap?.[value]() - onChange({ - 'dateRange': [date?.start, date?.end], - [name]: value, - }) - } - - return ( <> {
{/* 日历 */} - {/* 快捷选日期 */} - - - @@ -164,9 +122,10 @@ const FilterPopup = (props: FilterPopupProps) => { max={5.0} step={0.5} className={styles.filterPopupRange} - onChange={handleFilterChange} + onChange={(value) => { + handleFilterChange("ntrp", value) + }} value={filterOptions?.ntrp} - name="ntrp" /> {/* 场次气泡选项 */} diff --git a/src/components/Range/index.tsx b/src/components/Range/index.tsx index 53ae228..b3eda20 100644 --- a/src/components/Range/index.tsx +++ b/src/components/Range/index.tsx @@ -16,7 +16,7 @@ interface RangeProps { }; disabled?: boolean; className?: string; - name: string; + name?: string; showTitle?: boolean; } @@ -64,7 +64,7 @@ const NtrpRange: React.FC = ({ if (Number(start) === Number(min) && Number(end) === Number(max)) { return "不限"; } - return `${start.toFixed(1)} - ${end.toFixed(1)}之间`; + return `${start?.toFixed(1)} - ${end?.toFixed(1)}之间`; }, [JSON.stringify(currentValue || []), min, max]); return ( diff --git a/src/store/global.ts b/src/store/global.ts index 9c2a45e..05623a9 100644 --- a/src/store/global.ts +++ b/src/store/global.ts @@ -51,11 +51,12 @@ export const useGlobalStore = create()((set, get) => ({ // 获取位置信息 getCurrentLocationInfo: () => { - getCurrentLocation().then((res) => { + return getCurrentLocation().then((res) => { set({ getLocationLoading: false, location: res || {}, }); + return res; }); }, diff --git a/src/store/listStore.ts b/src/store/listStore.ts index 0b4050f..840ff74 100644 --- a/src/store/listStore.ts +++ b/src/store/listStore.ts @@ -18,9 +18,10 @@ import dateRangeUtils from '@/utils/dateRange' // 完整的 Store 类型 type TennisStore = ListState & ListActions; +const toDate = dateRangeUtils?.formatDate(new Date()) + const defaultFilterOptions: IFilterOptions = { - dateRange: [new Date(), new Date()], // 日期区间 - dateRangeQuick: '', + dateRange: [toDate, toDate], // 日期区间 timeSlot: "", // 时间段 ntrp: [1, 5], // NTRP 水平区间 venueType: "", // 场地类型 @@ -124,7 +125,6 @@ export const useListStore = create()((set, get) => ({ getSearchParams: () => { const state = get(); const filterOptions = state?.filterOptions || {}; - console.log('===1111filterOptions', filterOptions) const distanceQuickFilter = state?.distanceQuickFilter || {}; const params = { pageOption: state.pageOption, @@ -133,10 +133,7 @@ export const useListStore = create()((set, get) => ({ title: state.searchValue, ntrpMin: filterOptions?.ntrp?.[0], ntrpMax: filterOptions?.ntrp?.[1], - dateRange: [ - dateRangeUtils.formatDate(filterOptions?.dateRange?.[0]), - dateRangeUtils.formatDate(filterOptions?.dateRange?.[1]) - ], + dateRange: filterOptions?.dateRange, }, order: distanceQuickFilter?.quick, lat: state?.location?.latitude, @@ -152,7 +149,8 @@ export const useListStore = create()((set, get) => ({ const { error, data, loading, gamesNum } = payload; const saveKey = isSearchResult ? "searchResultData" : "matches"; const saveData = { error, loading, gamesNum, [saveKey]: data }; - set(saveData); + console.log('===saveData', saveData) + set({...saveData}); }, // 获取列表数据(常规搜索) diff --git a/types/list/types.ts b/types/list/types.ts index 1b36d8b..63e6787 100644 --- a/types/list/types.ts +++ b/types/list/types.ts @@ -13,8 +13,7 @@ export interface TennisMatch { shinei: string } export interface IFilterOptions { - dateRange: [Date, Date], // 日期区间 - dateRangeQuick?: string, // 日期快捷选择 + dateRange: [string, string], // 日期区间 timeSlot?: string, // 时间段 ntrp?: [number, number], // NTRP 水平区间 venueType?: string, // 场地类型