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

This commit is contained in:
zhanjunhao
2026-11-24 20:14:10 +08:00
parent 471d7843de
commit 2cbbf0839b
83 changed files with 2094 additions and 1355 deletions
+101 -88
View File
@@ -22,6 +22,8 @@ import { useIsMobile } from '../../hooks/common/useIsMobile';
import { createCardProPagination } from '../../helpers/utils';
import { Button as AntButton } from 'antd';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useFilterSearch } from '../../hooks/common/useFilterSearch';
import { useTableFilterQuery } from '../../hooks/common/useTableFilterQuery';
import { useEffectEvent } from '../../hooks/common/useEffectEvent';
import { useTranslation } from 'react-i18next';
import { formatCurrency } from '../../helpers/safeDisplay';
@@ -133,6 +135,12 @@ const Subscription = () => {
const [tiers, setTiers] = useState([]);
const [statuses, setStatuses] = useState([]);
const [endDateRange, setEndDateRange] = useState(null);
const [appliedFilters, setAppliedFilters] = useState({
planTypes: [],
tiers: [],
statuses: [],
endDateRange: null,
});
const [quickFilter, setQuickFilter] = useState(null); // expiring3 / expiring7 / overdue
// 操作弹窗
@@ -167,75 +175,85 @@ const Subscription = () => {
}
}, [t]);
const fetchList = useCallback(async () => {
setLoading(true);
try {
const params = { page, page_size: pageSize };
if (appliedKeyword) params.keyword = appliedKeyword;
if (appliedUserId) params.user_id = appliedUserId;
if (planTypes.length) params.plan_types = planTypes.join(',');
if (tiers.length) params.tiers = tiers.join(',');
if (statuses.length) params.statuses = statuses.join(',');
if (endDateRange && endDateRange[0]) {
params.end_date_from = Math.floor(endDateRange[0].getTime() / 1000);
}
if (endDateRange && endDateRange[1]) {
params.end_date_to = Math.floor(endDateRange[1].getTime() / 1000);
}
// 快捷筛选 (优先级覆盖 endDateRange)
const now = Math.floor(Date.now() / 1000);
if (quickFilter === 'expiring3') {
params.end_date_from = now;
params.end_date_to = now + 3 * 86400;
params.statuses = 'active';
} else if (quickFilter === 'expiring7') {
params.end_date_from = now;
params.end_date_to = now + 7 * 86400;
params.statuses = 'active';
} else if (quickFilter === 'overdue') {
params.end_date_to = now;
params.statuses = 'expired';
}
const fetchList = useCallback(
async (signal) => {
const { planTypes, tiers, statuses, endDateRange } = appliedFilters;
setLoading(true);
try {
const params = { page, page_size: pageSize };
if (appliedKeyword) params.keyword = appliedKeyword;
if (appliedUserId) params.user_id = appliedUserId;
if (planTypes.length) params.plan_types = planTypes.join(',');
if (tiers.length) params.tiers = tiers.join(',');
if (statuses.length) params.statuses = statuses.join(',');
if (endDateRange && endDateRange[0]) {
params.end_date_from = Math.floor(endDateRange[0].getTime() / 1000);
}
if (endDateRange && endDateRange[1]) {
params.end_date_to = Math.floor(endDateRange[1].getTime() / 1000);
}
// 快捷筛选 (优先级覆盖 endDateRange)
const now = Math.floor(Date.now() / 1000);
if (quickFilter === 'expiring3') {
params.end_date_from = now;
params.end_date_to = now + 3 * 86400;
params.statuses = 'active';
} else if (quickFilter === 'expiring7') {
params.end_date_from = now;
params.end_date_to = now + 7 * 86400;
params.statuses = 'active';
} else if (quickFilter === 'overdue') {
params.end_date_to = now;
params.statuses = 'expired';
}
const res = await API.get('/api/user/membership/manage/subscriptions', {
params,
});
if (res.data.success) {
setList(res.data.data?.list || []);
setTotal(res.data.data?.total || 0);
} else {
showError(res.data.message || t('查询失败'));
const res = await API.get('/api/user/membership/manage/subscriptions', {
params,
signal,
});
if (signal?.aborted) return;
if (res.data.success) {
setList(res.data.data?.list || []);
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,
appliedKeyword,
appliedUserId,
planTypes,
tiers,
statuses,
endDateRange,
quickFilter,
t,
]);
},
[
page,
pageSize,
appliedKeyword,
appliedUserId,
appliedFilters,
quickFilter,
t,
],
);
useEffect(() => {
fetchList();
}, [fetchList, refreshToken]);
const { cancelQuery } = useTableFilterQuery(fetchList, refreshToken);
const handleSearch = () => {
setPage(1);
setAppliedKeyword(keyword);
setAppliedUserId(userId);
setQuickFilter(null);
};
const { changeFilter, submitSearch, cancelPendingSearch } = useFilterSearch(
() => {
setAppliedKeyword(keyword);
setAppliedUserId(userId);
setAppliedFilters({ planTypes, tiers, statuses, endDateRange });
},
cancelQuery,
);
const handleReset = () => {
cancelPendingSearch();
setAppliedFilters({
planTypes: [],
tiers: [],
statuses: [],
endDateRange: null,
});
setPage(1);
setKeyword('');
setAppliedKeyword('');
@@ -249,7 +267,6 @@ const Subscription = () => {
};
const applyQuickFilter = (key) => {
setPage(1);
setQuickFilter((prev) => (prev === key ? null : key));
};
@@ -309,6 +326,12 @@ const Subscription = () => {
setTiers([]);
setStatuses([]);
setEndDateRange(null);
setAppliedFilters({
planTypes: [],
tiers: [],
statuses: [],
endDateRange: null,
});
setQuickFilter(null);
setPage(1);
}
@@ -325,7 +348,7 @@ const Subscription = () => {
);
if (res.data.success) {
showSuccess(t('补发成功'));
fetchList();
setRefreshToken((key) => key + 1);
} else {
showError(res.data.message);
}
@@ -488,7 +511,7 @@ const Subscription = () => {
searchArea={
<ConsoleFilterGrid
onReset={handleReset}
onSearch={handleSearch}
onSearch={submitSearch}
loading={loading}
>
<ConsoleFilterField
@@ -500,7 +523,7 @@ const Subscription = () => {
prefix={<Search size={14} />}
placeholder={t('搜索用户名/昵称/订单号')}
value={keyword}
onChange={setKeyword}
onChange={changeFilter(setKeyword)}
/>
</ConsoleFilterField>
<ConsoleFilterField label={t('用户ID')} id='subscription-user-id'>
@@ -508,7 +531,7 @@ const Subscription = () => {
id='subscription-user-id'
placeholder={t('用户ID')}
value={userId}
onChange={setUserId}
onChange={changeFilter(setUserId)}
min={0}
hideButtons
/>
@@ -521,10 +544,7 @@ const Subscription = () => {
id='subscription-plan-type'
placeholder={t('套餐类型')}
value={planTypes}
onChange={(v) => {
setPage(1);
setPlanTypes(v || []);
}}
onChange={changeFilter((value) => setPlanTypes(value || []))}
multiple
maxTagCount={2}
optionList={[
@@ -539,10 +559,7 @@ const Subscription = () => {
id='subscription-tier'
placeholder={t('档位')}
value={tiers}
onChange={(v) => {
setPage(1);
setTiers(v || []);
}}
onChange={changeFilter((value) => setTiers(value || []))}
multiple
maxTagCount={2}
optionList={[
@@ -556,10 +573,7 @@ const Subscription = () => {
id='subscription-status'
placeholder={t('状态')}
value={statuses}
onChange={(v) => {
setPage(1);
setStatuses(v || []);
}}
onChange={changeFilter((value) => setStatuses(value || []))}
multiple
maxTagCount={2}
optionList={[
@@ -579,12 +593,10 @@ const Subscription = () => {
start: 'subscription-end-date',
end: 'subscription-end-date-end',
}}
tableFilter
type='dateRange'
value={endDateRange}
onChange={(d) => {
setPage(1);
setEndDateRange(d || null);
}}
onChange={changeFilter(setEndDateRange)}
placeholder={[t('到期开始'), t('到期结束')]}
density='compact'
/>
@@ -633,6 +645,7 @@ const Subscription = () => {
</div>
}
paginationArea={createCardProPagination({
preservePage: true,
currentPage: page,
pageSize,
total,
@@ -661,7 +674,7 @@ const Subscription = () => {
onCancel={() => setBanVisible(false)}
onDone={() => {
setBanVisible(false);
fetchList();
setRefreshToken((key) => key + 1);
}}
t={t}
/>
@@ -673,7 +686,7 @@ const Subscription = () => {
onCancel={() => setUnbanVisible(false)}
onDone={() => {
setUnbanVisible(false);
fetchList();
setRefreshToken((key) => key + 1);
}}
t={t}
/>
@@ -685,7 +698,7 @@ const Subscription = () => {
onCancel={() => setExtendVisible(false)}
onDone={() => {
setExtendVisible(false);
fetchList();
setRefreshToken((key) => key + 1);
}}
t={t}
/>
@@ -697,7 +710,7 @@ const Subscription = () => {
onCancel={() => setEditVisible(false)}
onDone={() => {
setEditVisible(false);
fetchList();
setRefreshToken((key) => key + 1);
}}
t={t}
/>