fix(table): 统一筛选交互并补齐移动视口覆盖

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 437a0345e8
commit dd4da99f1d
83 changed files with 2094 additions and 1355 deletions
+76 -80
View File
@@ -9,7 +9,9 @@ import {
ConsoleCard,
ConsoleSearchBar,
} from '../../components/console/ConsolePrimitives';
import React, { useEffect, useState, useCallback } from 'react';
import React, { useState, useCallback } from 'react';
import { useFilterSearch } from '../../hooks/common/useFilterSearch';
import { useTableFilterQuery } from '../../hooks/common/useTableFilterQuery';
import { useTranslation } from 'react-i18next';
import { Search } from 'lucide-react';
import {
@@ -85,59 +87,64 @@ const AdminOrder = () => {
const [copiedId, setCopiedId] = useState(null);
const [paymentMethodFilter, setPaymentMethodFilter] = useState('');
const [dateRange, setDateRange] = useState(null);
const [appliedDateRange, setAppliedDateRange] = useState(null);
const [appliedStatus, setAppliedStatus] = useState('');
const [appliedPaymentMethod, setAppliedPaymentMethod] = useState('');
const [minMoney, setMinMoney] = useState(undefined);
const [maxMoney, setMaxMoney] = useState(undefined);
const [appliedMinMoney, setAppliedMinMoney] = useState(undefined);
const [appliedMaxMoney, setAppliedMaxMoney] = useState(undefined);
const fetchOrders = useCallback(async () => {
setLoading(true);
try {
const params = { p: page, page_size: pageSize };
if (searchKeyword) params.keyword = searchKeyword;
if (appliedOrderId) params.order_id = appliedOrderId;
if (appliedUserId) params.user_id = appliedUserId;
if (statusFilter) params.status = statusFilter;
if (paymentMethodFilter) params.payment_method = paymentMethodFilter;
if (dateRange && dateRange[0])
params.start_time = Math.floor(dateRange[0].getTime() / 1000);
if (dateRange && dateRange[1])
params.end_time = Math.floor(dateRange[1].getTime() / 1000);
if (appliedMinMoney !== undefined && appliedMinMoney !== null)
params.min_money = appliedMinMoney;
if (appliedMaxMoney !== undefined && appliedMaxMoney !== null)
params.max_money = appliedMaxMoney;
const res = await API.get('/api/order/search', { params });
if (res.data.success) {
setOrders(res.data.data?.items || []);
setTotal(res.data.data?.total || 0);
} else {
showError(res.data.message || t('查询失败'));
const fetchOrders = useCallback(
async (signal) => {
setLoading(true);
try {
const params = { p: page, page_size: pageSize };
if (searchKeyword) params.keyword = searchKeyword;
if (appliedOrderId) params.order_id = appliedOrderId;
if (appliedUserId) params.user_id = appliedUserId;
if (appliedStatus) params.status = appliedStatus;
if (appliedPaymentMethod) params.payment_method = appliedPaymentMethod;
if (appliedDateRange?.[0])
params.start_time = Math.floor(appliedDateRange[0].getTime() / 1000);
if (appliedDateRange?.[1])
params.end_time = Math.floor(appliedDateRange[1].getTime() / 1000);
if (appliedMinMoney !== undefined && appliedMinMoney !== null)
params.min_money = appliedMinMoney;
if (appliedMaxMoney !== undefined && appliedMaxMoney !== null)
params.max_money = appliedMaxMoney;
const res = await API.get('/api/order/search', { params, signal });
if (signal?.aborted) return;
if (res.data.success) {
setOrders(res.data.data?.items || []);
setTotal(res.data.data?.total || 0);
} else {
showError(res.data.message || t('查询失败'));
}
} catch (err) {
if (!signal?.aborted && !err.isAxiosError) showError(err.message);
} finally {
if (!signal?.aborted) setLoading(false);
}
} catch (err) {
showError(err.message);
} finally {
setLoading(false);
}
}, [
page,
pageSize,
searchKeyword,
appliedOrderId,
appliedUserId,
statusFilter,
paymentMethodFilter,
dateRange,
appliedMinMoney,
appliedMaxMoney,
t,
]);
},
[
page,
pageSize,
searchKeyword,
appliedOrderId,
appliedUserId,
appliedStatus,
appliedPaymentMethod,
appliedDateRange,
appliedMinMoney,
appliedMaxMoney,
t,
],
);
useEffect(() => {
fetchOrders();
}, [fetchOrders, queryVersion]);
const { cancelQuery } = useTableFilterQuery(fetchOrders, queryVersion);
const handleSearch = () => {
const applyFilters = () => {
const trimmedKeyword = keyword.trim();
const normalizedOrderId =
orderId && Number(orderId) > 0 ? Math.floor(Number(orderId)) : undefined;
@@ -149,7 +156,6 @@ const AdminOrder = () => {
: undefined;
const ignoreNumericKeyword =
normalizedOrderId && /^\d+$/.test(trimmedKeyword);
setPage(1);
setSearchKeyword(
numericKeywordAsOrderId || ignoreNumericKeyword ? '' : trimmedKeyword,
);
@@ -157,33 +163,22 @@ const AdminOrder = () => {
setAppliedUserId(normalizedUserId);
setAppliedMinMoney(minMoney);
setAppliedMaxMoney(maxMoney);
setAppliedStatus(statusFilter || '');
setAppliedPaymentMethod(paymentMethodFilter || '');
setAppliedDateRange(dateRange);
setQueryVersion((version) => version + 1);
};
const handleStatusFilterChange = (value) => {
setPage(1);
setStatusFilter(value || '');
};
const handlePaymentMethodChange = (value) => {
setPage(1);
setPaymentMethodFilter(value || '');
};
const handleDateRangeChange = (dates) => {
setPage(1);
setDateRange(dates || null);
};
const handleMinMoneyChange = (value) => {
setMinMoney(value);
};
const handleMaxMoneyChange = (value) => {
setMaxMoney(value);
};
const { changeFilter, submitSearch, cancelPendingSearch } = useFilterSearch(
applyFilters,
cancelQuery,
);
const handleReset = () => {
cancelPendingSearch();
setAppliedStatus('');
setAppliedPaymentMethod('');
setAppliedDateRange(null);
setQueryVersion((version) => version + 1);
setPage(1);
setKeyword('');
@@ -407,7 +402,7 @@ const AdminOrder = () => {
<ConsoleSearchBar
formProps={{
layout: 'vertical',
onFinish: handleSearch,
onFinish: submitSearch,
className: 'console-module-filter-form',
}}
>
@@ -417,15 +412,14 @@ const AdminOrder = () => {
prefix={<Search size={14} />}
placeholder={t('搜索昵称/订单号')}
value={keyword}
onChange={setKeyword}
onEnterPress={handleSearch}
onChange={changeFilter(setKeyword)}
/>
</ConsoleFilterField>
<ConsoleFilterField label={t('订单ID')}>
<InputNumber
placeholder={t('订单ID')}
value={orderId}
onChange={setOrderId}
onChange={changeFilter(setOrderId)}
min={1}
hideButtons
/>
@@ -434,7 +428,7 @@ const AdminOrder = () => {
<InputNumber
placeholder={t('用户ID')}
value={userId}
onChange={setUserId}
onChange={changeFilter(setUserId)}
min={1}
hideButtons
/>
@@ -443,7 +437,7 @@ const AdminOrder = () => {
<Select
placeholder={t('状态')}
value={statusFilter || undefined}
onChange={handleStatusFilterChange}
onChange={changeFilter(setStatusFilter)}
allowClear
optionList={[
{ label: t('待支付'), value: 'pending' },
@@ -456,7 +450,7 @@ const AdminOrder = () => {
<Select
placeholder={t('支付方式')}
value={paymentMethodFilter || undefined}
onChange={handlePaymentMethodChange}
onChange={changeFilter(setPaymentMethodFilter)}
allowClear
optionList={Object.entries(paymentMethodMap).map(
([value, label]) => ({ label, value }),
@@ -465,9 +459,10 @@ const AdminOrder = () => {
</ConsoleFilterField>
<ConsoleFilterField label={t('创建时间')}>
<DatePicker
tableFilter
type='dateTimeRange'
value={dateRange}
onChange={handleDateRangeChange}
onChange={changeFilter(setDateRange)}
placeholder={[t('开始时间'), t('结束时间')]}
density='compact'
/>
@@ -477,7 +472,7 @@ const AdminOrder = () => {
<InputNumber
placeholder={t('最小金额')}
value={minMoney}
onChange={handleMinMoneyChange}
onChange={changeFilter(setMinMoney)}
min={0}
precision={2}
prefix='¥'
@@ -486,7 +481,7 @@ const AdminOrder = () => {
<InputNumber
placeholder={t('最大金额')}
value={maxMoney}
onChange={handleMaxMoneyChange}
onChange={changeFilter(setMaxMoney)}
min={0}
precision={2}
prefix='¥'
@@ -496,7 +491,7 @@ const AdminOrder = () => {
</div>
<ConsoleFilterActions
onReset={handleReset}
onSearch={handleSearch}
onSearch={submitSearch}
loading={loading}
/>
</ConsoleSearchBar>
@@ -510,6 +505,7 @@ const AdminOrder = () => {
loading={loading}
rowKey='id'
pagination={{
preservePage: true,
currentPage: page,
total,
pageSize,