Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca7c3f27f0 | |||
| c564e9df12 |
@@ -1,7 +1,18 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Button, Card, InputNumber, Space, Spin, Switch, Tag, Typography, Upload, message } from 'antd';
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
InputNumber,
|
||||||
|
Space,
|
||||||
|
Spin,
|
||||||
|
Switch,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
Upload,
|
||||||
|
message,
|
||||||
|
} from 'antd';
|
||||||
import { DeleteOutlined, UploadOutlined } from '@ant-design/icons';
|
import { DeleteOutlined, UploadOutlined } from '@ant-design/icons';
|
||||||
import { api, errMsg } from '@/lib/api';
|
import { api, errMsg } from '@/lib/api';
|
||||||
import { canDo } from '@/lib/auth';
|
import { canDo } from '@/lib/auth';
|
||||||
@@ -38,7 +49,9 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
const load = async () => {
|
const load = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<GuideCfg>('/admin/api/guide-video', { params: { scene } });
|
const { data } = await api.get<GuideCfg>('/admin/api/guide-video', {
|
||||||
|
params: { scene },
|
||||||
|
});
|
||||||
sync(data);
|
sync(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error(errMsg(e));
|
message.error(errMsg(e));
|
||||||
@@ -56,7 +69,11 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
try {
|
try {
|
||||||
const { data } = await api.patch<GuideCfg>(
|
const { data } = await api.patch<GuideCfg>(
|
||||||
'/admin/api/guide-video',
|
'/admin/api/guide-video',
|
||||||
{ enabled, max_plays: maxPlays, reward_coin: rewardCoin },
|
{
|
||||||
|
enabled,
|
||||||
|
reward_coin: rewardCoin,
|
||||||
|
...(scene === 'comparison' ? { max_plays: maxPlays } : {}),
|
||||||
|
},
|
||||||
{ params: { scene } },
|
{ params: { scene } },
|
||||||
);
|
);
|
||||||
sync(data);
|
sync(data);
|
||||||
@@ -121,11 +138,20 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
size="small"
|
size="small"
|
||||||
title={meta.title}
|
title={meta.title}
|
||||||
style={{ marginBottom: 16 }}
|
style={{ marginBottom: 16 }}
|
||||||
extra={cfg?.updated_at ? <Text type="secondary">更新于 {new Date(cfg.updated_at).toLocaleString('zh-CN')}</Text> : null}
|
extra={
|
||||||
|
cfg?.updated_at ? (
|
||||||
|
<Text type="secondary">
|
||||||
|
更新于 {new Date(cfg.updated_at).toLocaleString('zh-CN')}
|
||||||
|
</Text>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<p style={{ color: '#777', marginTop: 0 }}>
|
<p style={{ color: '#777', marginTop: 0 }}>
|
||||||
Android 用户点击「{meta.action}」后,前若干次在等候浮层广告位播放本视频并奖励金币。
|
Android 用户点击「{meta.action}」后,前 {cfg?.max_plays ?? 3}{' '}
|
||||||
次数按账号、按功能分别计算;开播即计次,播完或中途关闭均发放当次配置的金币。
|
次在等候浮层广告位播放本视频并奖励金币。次数按账号、按功能分别计算;
|
||||||
|
开播即计次,播完或中途关闭均发放当次配置的金币。
|
||||||
|
{scene === 'coupon' &&
|
||||||
|
'领券引导视频的播放次数上限请在「监控审计 → 限制策略」中调整。'}
|
||||||
</p>
|
</p>
|
||||||
{loading || !cfg ? (
|
{loading || !cfg ? (
|
||||||
<Spin style={{ display: 'block', margin: '24px 0' }} />
|
<Spin style={{ display: 'block', margin: '24px 0' }} />
|
||||||
@@ -137,10 +163,24 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
<video
|
<video
|
||||||
src={mediaUrl(cfg.video_url)}
|
src={mediaUrl(cfg.video_url)}
|
||||||
controls
|
controls
|
||||||
style={{ width: 240, maxHeight: 420, borderRadius: 12, background: '#000' }}
|
style={{
|
||||||
|
width: 240,
|
||||||
|
maxHeight: 420,
|
||||||
|
borderRadius: 12,
|
||||||
|
background: '#000',
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div style={{ height: 280, border: '1px dashed #d9d9d9', borderRadius: 12, display: 'grid', placeItems: 'center', color: '#aaa' }}>
|
<div
|
||||||
|
style={{
|
||||||
|
height: 280,
|
||||||
|
border: '1px dashed #d9d9d9',
|
||||||
|
borderRadius: 12,
|
||||||
|
display: 'grid',
|
||||||
|
placeItems: 'center',
|
||||||
|
color: '#aaa',
|
||||||
|
}}
|
||||||
|
>
|
||||||
未上传视频
|
未上传视频
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -148,22 +188,51 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
|
<Space direction="vertical" size="middle" style={{ minWidth: 390 }}>
|
||||||
<Space>
|
<Space>
|
||||||
<span>启用:</span>
|
<span>启用:</span>
|
||||||
<Switch checked={enabled} disabled={!canEdit} onChange={setEnabled} />
|
<Switch
|
||||||
|
checked={enabled}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onChange={setEnabled}
|
||||||
|
/>
|
||||||
{!enabled && <Tag color="orange">已关闭</Tag>}
|
{!enabled && <Tag color="orange">已关闭</Tag>}
|
||||||
</Space>
|
</Space>
|
||||||
<Space>
|
{scene === 'comparison' && (
|
||||||
<span>播放次数:</span>
|
<Space>
|
||||||
<InputNumber min={0} max={50} precision={0} value={maxPlays} disabled={!canEdit} onChange={(v) => setMaxPlays(v ?? 0)} />
|
<span>播放次数:</span>
|
||||||
<Text type="secondary">每个账号前 N 次(默认 3)</Text>
|
<InputNumber
|
||||||
</Space>
|
min={0}
|
||||||
|
max={50}
|
||||||
|
precision={0}
|
||||||
|
value={maxPlays}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onChange={(value) => setMaxPlays(value ?? 0)}
|
||||||
|
/>
|
||||||
|
<Text type="secondary">每个账号前 N 次(默认 3)</Text>
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
<Space>
|
<Space>
|
||||||
<span>每次金币:</span>
|
<span>每次金币:</span>
|
||||||
<InputNumber min={0} max={10000} precision={0} value={rewardCoin} disabled={!canEdit} onChange={(v) => setRewardCoin(v ?? 0)} />
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
max={10000}
|
||||||
|
precision={0}
|
||||||
|
value={rewardCoin}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onChange={(value) => setRewardCoin(value ?? 0)}
|
||||||
|
/>
|
||||||
<Text type="secondary">默认 100</Text>
|
<Text type="secondary">默认 100</Text>
|
||||||
</Space>
|
</Space>
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
<Upload accept="video/mp4,.mp4" showUploadList={false} beforeUpload={beforeUpload} disabled={!canEdit}>
|
<Upload
|
||||||
<Button icon={<UploadOutlined />} loading={uploading} disabled={!canEdit}>
|
accept="video/mp4,.mp4"
|
||||||
|
showUploadList={false}
|
||||||
|
beforeUpload={beforeUpload}
|
||||||
|
disabled={!canEdit}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<UploadOutlined />}
|
||||||
|
loading={uploading}
|
||||||
|
disabled={!canEdit}
|
||||||
|
>
|
||||||
{cfg.video_url ? '更换视频' : '上传视频'}
|
{cfg.video_url ? '更换视频' : '上传视频'}
|
||||||
</Button>
|
</Button>
|
||||||
</Upload>
|
</Upload>
|
||||||
@@ -174,8 +243,17 @@ function SceneConfig({ scene }: { scene: Scene }) {
|
|||||||
)}
|
)}
|
||||||
<Text type="secondary">MP4(H.264),≤100MB</Text>
|
<Text type="secondary">MP4(H.264),≤100MB</Text>
|
||||||
</Space>
|
</Space>
|
||||||
<Button type="primary" loading={saving} disabled={!canEdit} onClick={save}>保存配置</Button>
|
<Button
|
||||||
<Text type="secondary">累计播放 {cfg.total_plays} 次,已发币 {cfg.granted_plays} 次</Text>
|
type="primary"
|
||||||
|
loading={saving}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onClick={save}
|
||||||
|
>
|
||||||
|
保存配置
|
||||||
|
</Button>
|
||||||
|
<Text type="secondary">
|
||||||
|
累计播放 {cfg.total_plays} 次,已发币 {cfg.granted_plays} 次
|
||||||
|
</Text>
|
||||||
</Space>
|
</Space>
|
||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import { usePathname, useRouter } from 'next/navigation';
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
import {
|
import {
|
||||||
BarChartOutlined,
|
BarChartOutlined,
|
||||||
|
ControlOutlined,
|
||||||
DashboardOutlined,
|
DashboardOutlined,
|
||||||
DatabaseOutlined,
|
DatabaseOutlined,
|
||||||
FileSearchOutlined,
|
FileSearchOutlined,
|
||||||
@@ -105,6 +106,7 @@ const NAV_GROUPS: NavGroup[] = [
|
|||||||
{ key: '/analytics-health', icon: <LineChartOutlined />, label: '埋点成功率' },
|
{ key: '/analytics-health', icon: <LineChartOutlined />, label: '埋点成功率' },
|
||||||
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
|
{ key: '/event-logs', icon: <DatabaseOutlined />, label: '埋点日志' },
|
||||||
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
|
{ key: '/audit-logs', icon: <FileSearchOutlined />, label: '审计日志' },
|
||||||
|
{ key: '/limit-whitelist', icon: <ControlOutlined />, label: '限制策略' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -19,10 +19,12 @@ import {
|
|||||||
CopyOutlined,
|
CopyOutlined,
|
||||||
DownOutlined,
|
DownOutlined,
|
||||||
EditOutlined,
|
EditOutlined,
|
||||||
|
PlusCircleOutlined,
|
||||||
ReloadOutlined,
|
ReloadOutlined,
|
||||||
RightOutlined,
|
RightOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
import { api, errMsg } from '@/lib/api';
|
import { api, errMsg } from '@/lib/api';
|
||||||
import { formatUtcTime, utcDayjs } from '@/lib/format';
|
import { formatUtcTime, utcDayjs } from '@/lib/format';
|
||||||
import type {
|
import type {
|
||||||
@@ -69,8 +71,8 @@ type IncidentStatus = 'open' | 'blocked';
|
|||||||
const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }> = {
|
const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }> = {
|
||||||
sms: {
|
sms: {
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 5,
|
max: 100000,
|
||||||
help: '统计成功下发;最高5次,与现有每设备每小时发送上限一致。',
|
help: '统计成功下发;告警阈值与短信硬限制分别配置。',
|
||||||
},
|
},
|
||||||
oneclick: {
|
oneclick: {
|
||||||
min: 1,
|
min: 1,
|
||||||
@@ -79,8 +81,8 @@ const RULE_LIMITS: Record<RiskKind, { min: number; max: number; help: string }>
|
|||||||
},
|
},
|
||||||
compare: {
|
compare: {
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 100,
|
max: 100000,
|
||||||
help: '同一账户按北京时间自然日累计;最高100次,与比价每日上限一致。',
|
help: '同一账户按北京时间自然日累计;告警阈值与比价硬限制分别配置。',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const utcTime = (value: string | null, withDate = true) =>
|
const utcTime = (value: string | null, withDate = true) =>
|
||||||
@@ -271,6 +273,7 @@ function DetailTable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function RiskMonitorPage() {
|
export default function RiskMonitorPage() {
|
||||||
|
const router = useRouter();
|
||||||
const { message, modal } = App.useApp();
|
const { message, modal } = App.useApp();
|
||||||
const [summary, setSummary] = useState<RiskMonitorSummary | null>(null);
|
const [summary, setSummary] = useState<RiskMonitorSummary | null>(null);
|
||||||
const [lists, setLists] = useState<Partial<Record<RiskKind, RiskIncidentPage>>>({});
|
const [lists, setLists] = useState<Partial<Record<RiskKind, RiskIncidentPage>>>({});
|
||||||
@@ -597,6 +600,40 @@ export default function RiskMonitorPage() {
|
|||||||
[lists, loadAll, message, modal],
|
[lists, loadAll, message, modal],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const addToWhitelist = useCallback(
|
||||||
|
(row: RiskIncidentItem) => {
|
||||||
|
const isCompare = row.kind === 'compare';
|
||||||
|
const subjectValue = isCompare ? row.phone : row.subject_id;
|
||||||
|
if (!isCompare && subjectValue?.startsWith('legacy-ip:')) {
|
||||||
|
void message.error(
|
||||||
|
'旧客户端未上报真实设备 ID,无法加入设备白名单,请升级客户端后重试',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!subjectValue) {
|
||||||
|
void message.error(
|
||||||
|
isCompare
|
||||||
|
? '该风险记录没有关联手机号,暂时无法加入白名单'
|
||||||
|
: '该风险记录没有设备 ID,暂时无法加入白名单',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ruleCode: Record<RiskKind, string> = {
|
||||||
|
sms: 'risk.sms.hourly',
|
||||||
|
oneclick: 'risk.oneclick.daily',
|
||||||
|
compare: 'risk.compare.daily',
|
||||||
|
};
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
create: '1',
|
||||||
|
subject_type: isCompare ? 'phone' : 'device',
|
||||||
|
subject_value: subjectValue,
|
||||||
|
rule_code: ruleCode[row.kind],
|
||||||
|
});
|
||||||
|
router.push(`/limit-whitelist?${params.toString()}`);
|
||||||
|
},
|
||||||
|
[message, router],
|
||||||
|
);
|
||||||
|
|
||||||
const columns = useCallback(
|
const columns = useCallback(
|
||||||
(kind: RiskKind): ColumnsType<RiskIncidentItem> => {
|
(kind: RiskKind): ColumnsType<RiskIncidentItem> => {
|
||||||
const actionColumn = {
|
const actionColumn = {
|
||||||
@@ -604,9 +641,18 @@ export default function RiskMonitorPage() {
|
|||||||
key: 'actions',
|
key: 'actions',
|
||||||
align: 'right' as const,
|
align: 'right' as const,
|
||||||
fixed: 'right' as const,
|
fixed: 'right' as const,
|
||||||
width: 180,
|
width: 280,
|
||||||
render: (_: unknown, row: RiskIncidentItem) => {
|
render: (_: unknown, row: RiskIncidentItem) => {
|
||||||
const open = expanded.has(row.incident_id);
|
const open = expanded.has(row.incident_id);
|
||||||
|
const whitelistUnavailableReason =
|
||||||
|
row.kind === 'compare'
|
||||||
|
? row.phone
|
||||||
|
? undefined
|
||||||
|
: '该风险记录没有关联手机号,暂时无法加入白名单'
|
||||||
|
: row.subject_id.startsWith('legacy-ip:')
|
||||||
|
? '旧客户端未上报真实设备 ID,无法加入设备白名单'
|
||||||
|
: undefined;
|
||||||
|
const canAddToWhitelist = !whitelistUnavailableReason;
|
||||||
return (
|
return (
|
||||||
<span className={styles.actionGroup}>
|
<span className={styles.actionGroup}>
|
||||||
<Button
|
<Button
|
||||||
@@ -618,6 +664,20 @@ export default function RiskMonitorPage() {
|
|||||||
>
|
>
|
||||||
{open ? '收起' : '展开'}
|
{open ? '收起' : '展开'}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Tooltip
|
||||||
|
title={whitelistUnavailableReason}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
icon={<PlusCircleOutlined />}
|
||||||
|
disabled={!canAddToWhitelist}
|
||||||
|
onClick={() => addToWhitelist(row)}
|
||||||
|
>
|
||||||
|
加入白名单
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
{row.status === 'open' && (
|
{row.status === 'open' && (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
@@ -700,7 +760,16 @@ export default function RiskMonitorPage() {
|
|||||||
actionColumn,
|
actionColumn,
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
[acting, copy, detailLoading, expanded, revokeRestriction, runAction, toggle],
|
[
|
||||||
|
acting,
|
||||||
|
addToWhitelist,
|
||||||
|
copy,
|
||||||
|
detailLoading,
|
||||||
|
expanded,
|
||||||
|
revokeRestriction,
|
||||||
|
runAction,
|
||||||
|
toggle,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
const cards = useMemo(() => {
|
const cards = useMemo(() => {
|
||||||
|
|||||||
+79
-2
@@ -414,14 +414,14 @@ export interface FeedbackQrConfig {
|
|||||||
updated_at: string | null;
|
updated_at: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 领券等候浮层的「新手引导视频」配置(前 3 次用它替代广告,每次固定 120 金币)。
|
/** 领券等候浮层的「新手引导视频」配置(前 3 次用它替代广告,默认每次固定 100 金币)。
|
||||||
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
|
* 后台只开放 enabled + 换片;下面几个字段接口仍返回,但页面不展示、也不回传。 */
|
||||||
export interface GuideVideoConfig {
|
export interface GuideVideoConfig {
|
||||||
scene: 'coupon' | 'comparison';
|
scene: 'coupon' | 'comparison';
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告)
|
video_url: string | null; // /media/guide_video/xxx.mp4;null = 未配片(浮层照旧只放广告)
|
||||||
max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整)
|
max_plays: number; // 每个账号前 N 次浮层放引导视频(服务端默认 3,后台不开放调整)
|
||||||
reward_coin: number; // 每次固定金币(服务端默认 120,播完 / 中途关闭都发)
|
reward_coin: number; // 每次固定金币(服务端默认 100,播完 / 中途关闭都发)
|
||||||
updated_at: string | null;
|
updated_at: string | null;
|
||||||
total_plays: number; // 只读统计:全站已播次数(后台不再展示)
|
total_plays: number; // 只读统计:全站已播次数(后台不再展示)
|
||||||
granted_plays: number; // 只读统计:其中已发币次数(后台不再展示)
|
granted_plays: number; // 只读统计:其中已发币次数(后台不再展示)
|
||||||
@@ -895,3 +895,80 @@ export interface HealthTrendPoint extends HealthMetrics {
|
|||||||
export interface HealthBreakdownRow extends HealthMetrics {
|
export interface HealthBreakdownRow extends HealthMetrics {
|
||||||
key: string; // 维度值(event 名 / app_ver / oem);缺失为 "(unknown)"
|
key: string; // 维度值(event 名 / app_ver / oem);缺失为 "(unknown)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== 统一限制策略 / 白名单 =====
|
||||||
|
export type LimitSubjectType = 'phone' | 'device';
|
||||||
|
export type LimitPolicyMode =
|
||||||
|
| 'inherit'
|
||||||
|
| 'override'
|
||||||
|
| 'unlimited'
|
||||||
|
| 'suppress_alert';
|
||||||
|
|
||||||
|
export interface LimitRule {
|
||||||
|
code: string;
|
||||||
|
label: string;
|
||||||
|
group: string;
|
||||||
|
global_limit: number;
|
||||||
|
default_limit: number;
|
||||||
|
window_label: string;
|
||||||
|
subject_types: LimitSubjectType[];
|
||||||
|
allowed_modes: LimitPolicyMode[];
|
||||||
|
min_value: number;
|
||||||
|
max_value: number;
|
||||||
|
supports_reset: boolean;
|
||||||
|
alert_only: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LimitDeviceCandidate {
|
||||||
|
device_id: string;
|
||||||
|
source: string;
|
||||||
|
source_label: string;
|
||||||
|
user_id: number | null;
|
||||||
|
username: string | null;
|
||||||
|
phone: string | null;
|
||||||
|
nickname: string | null;
|
||||||
|
device_model: string | null;
|
||||||
|
last_active_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LimitOverride {
|
||||||
|
id: number;
|
||||||
|
subject_type: LimitSubjectType;
|
||||||
|
subject_value: string;
|
||||||
|
rule_code: string;
|
||||||
|
rule_label: string;
|
||||||
|
rule_group: string;
|
||||||
|
mode: LimitPolicyMode;
|
||||||
|
limit_value: number | null;
|
||||||
|
global_limit: number;
|
||||||
|
effective_limit: number | null;
|
||||||
|
enabled: boolean;
|
||||||
|
starts_at: string | null;
|
||||||
|
expires_at: string | null;
|
||||||
|
reset_at: string | null;
|
||||||
|
reason: string | null;
|
||||||
|
status: 'active' | 'scheduled' | 'expired' | 'disabled';
|
||||||
|
created_by_admin_id: number | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LimitOverrideList {
|
||||||
|
items: LimitOverride[];
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LimitSubject {
|
||||||
|
subject_type: LimitSubjectType;
|
||||||
|
subject_value: string;
|
||||||
|
group_counts: Record<string, number>;
|
||||||
|
total_rules: number;
|
||||||
|
items: LimitOverride[];
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LimitSubjectList {
|
||||||
|
items: LimitSubject[];
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export function usePagedList<T>(
|
|||||||
url: string,
|
url: string,
|
||||||
filters: Record<string, unknown>,
|
filters: Record<string, unknown>,
|
||||||
initialPageSize = 20,
|
initialPageSize = 20,
|
||||||
|
offsetParam: 'cursor' | 'offset' = 'cursor',
|
||||||
) {
|
) {
|
||||||
const [items, setItems] = useState<T[]>([]);
|
const [items, setItems] = useState<T[]>([]);
|
||||||
const [total, setTotal] = useState(0);
|
const [total, setTotal] = useState(0);
|
||||||
@@ -31,7 +32,11 @@ export function usePagedList<T>(
|
|||||||
requestSeq.current = seq;
|
requestSeq.current = seq;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const params = { ...JSON.parse(filtersKey), limit: ps, cursor: (p - 1) * ps };
|
const params = {
|
||||||
|
...JSON.parse(filtersKey),
|
||||||
|
limit: ps,
|
||||||
|
[offsetParam]: (p - 1) * ps,
|
||||||
|
};
|
||||||
const { data } = await api.get<CursorPage<T>>(url, { params });
|
const { data } = await api.get<CursorPage<T>>(url, { params });
|
||||||
if (requestSeq.current !== seq) return; // 丢弃过期响应(快速切页/筛选)
|
if (requestSeq.current !== seq) return; // 丢弃过期响应(快速切页/筛选)
|
||||||
setItems(data.items);
|
setItems(data.items);
|
||||||
@@ -40,7 +45,7 @@ export function usePagedList<T>(
|
|||||||
if (requestSeq.current === seq) setLoading(false);
|
if (requestSeq.current === seq) setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[url, filtersKey],
|
[url, filtersKey, offsetParam],
|
||||||
);
|
);
|
||||||
|
|
||||||
// 筛选变化:回第 1 页重载
|
// 筛选变化:回第 1 页重载
|
||||||
|
|||||||
Reference in New Issue
Block a user