906 lines
28 KiB
TypeScript
906 lines
28 KiB
TypeScript
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
import {
|
|
Alert,
|
|
Button,
|
|
Card,
|
|
Col,
|
|
Collapse,
|
|
Empty,
|
|
Form,
|
|
Input,
|
|
InputNumber,
|
|
Modal,
|
|
Progress,
|
|
Row,
|
|
Select,
|
|
Space,
|
|
Statistic,
|
|
Switch,
|
|
Table,
|
|
Tag,
|
|
Typography,
|
|
} from 'antd';
|
|
import type { TableProps } from 'antd';
|
|
import {
|
|
EditOutlined,
|
|
PlusOutlined,
|
|
ReloadOutlined,
|
|
SafetyCertificateOutlined,
|
|
} from '@ant-design/icons';
|
|
import {
|
|
douyuApi,
|
|
type DouyuAccountProtectionTarget,
|
|
type DouyuAccountPlatformStatus,
|
|
type DouyuPlatformAlert,
|
|
type DouyuPlatformTrends,
|
|
type DouyuSupplyTarget,
|
|
type DouyuSupplyTargetConfig,
|
|
type DouyuSupplyTargetStatus,
|
|
} from '../../api/modules';
|
|
import { usePermissions } from '../../hooks/usePermissions';
|
|
import { message } from '../../utils/antdMessage';
|
|
import { getErrorMessage } from '../../utils/error';
|
|
import { formatTime } from '../../utils/time';
|
|
|
|
const { Text } = Typography;
|
|
|
|
const VALUE_LABELS: Record<string, string> = {
|
|
high_value: '高价值',
|
|
ordinary: '普通',
|
|
};
|
|
|
|
function targetTotal(actual: number, target: number, buffer: number) {
|
|
const effectiveTarget = target + buffer;
|
|
return `${actual}/${effectiveTarget || '-'}`;
|
|
}
|
|
|
|
interface TargetFormValues {
|
|
scope: string;
|
|
commodity_id?: string;
|
|
value_class: 'high_value' | 'ordinary';
|
|
target_covered: number;
|
|
target_available: number;
|
|
target_allocatable: number;
|
|
safety_buffer: number;
|
|
enabled: boolean;
|
|
}
|
|
|
|
interface ProtectionFormValues {
|
|
enabled: boolean;
|
|
target_count: number;
|
|
probe_interval_minutes: number;
|
|
auto_relogin: boolean;
|
|
}
|
|
|
|
interface TrendRow {
|
|
date: string;
|
|
queryTotal: number;
|
|
queryRate: number;
|
|
loginTotal: number;
|
|
loginRate: number;
|
|
ckInvalid: number;
|
|
reloginOk: number;
|
|
}
|
|
|
|
function MiniTrend({
|
|
title,
|
|
values,
|
|
dates,
|
|
color,
|
|
suffix = '',
|
|
}: {
|
|
title: string;
|
|
values: number[];
|
|
dates: string[];
|
|
color: string;
|
|
suffix?: string;
|
|
}) {
|
|
const width = 260;
|
|
const height = 64;
|
|
const padding = 5;
|
|
const max = Math.max(...values, 1);
|
|
const step = values.length > 1 ? (width - padding * 2) / (values.length - 1) : 0;
|
|
const points = values.map((value, index) => {
|
|
const x = padding + step * index;
|
|
const y = height - padding - (Math.max(0, value) / max) * (height - padding * 2);
|
|
return `${x},${y}`;
|
|
}).join(' ');
|
|
const latest = values.at(-1) || 0;
|
|
|
|
return (
|
|
<div style={{ minWidth: 0 }}>
|
|
<Space size={8} align="baseline">
|
|
<Text strong>{title}</Text>
|
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
最近 {latest}{suffix}
|
|
</Text>
|
|
</Space>
|
|
<svg
|
|
viewBox={`0 0 ${width} ${height}`}
|
|
width="100%"
|
|
height={74}
|
|
role="img"
|
|
aria-label={`${title}趋势`}
|
|
preserveAspectRatio="none"
|
|
style={{ display: 'block', marginTop: 6 }}
|
|
>
|
|
<line
|
|
x1={padding}
|
|
y1={height - padding}
|
|
x2={width - padding}
|
|
y2={height - padding}
|
|
stroke="currentColor"
|
|
opacity={0.12}
|
|
/>
|
|
{points ? (
|
|
<polyline
|
|
points={points}
|
|
fill="none"
|
|
stroke={color}
|
|
strokeWidth={2.5}
|
|
strokeLinecap="round"
|
|
strokeLinejoin="round"
|
|
vectorEffect="non-scaling-stroke"
|
|
/>
|
|
) : null}
|
|
</svg>
|
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
<Text type="secondary" style={{ fontSize: 11 }}>{dates[0]?.slice(5) || '-'}</Text>
|
|
<Text type="secondary" style={{ fontSize: 11 }}>{dates.at(-1)?.slice(5) || '-'}</Text>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function AccountPlatformStatusPanel() {
|
|
const { can } = usePermissions();
|
|
const canManage = can('douyu:config');
|
|
const [form] = Form.useForm<TargetFormValues>();
|
|
const [protectionForm] = Form.useForm<ProtectionFormValues>();
|
|
const [status, setStatus] = useState<DouyuAccountPlatformStatus | null>(null);
|
|
const [targetConfigs, setTargetConfigs] = useState<DouyuSupplyTargetConfig[]>([]);
|
|
const [supplyTargets, setSupplyTargets] = useState<DouyuSupplyTargetStatus[]>([]);
|
|
const [supplyAlerts, setSupplyAlerts] = useState<DouyuPlatformAlert[]>([]);
|
|
const [trends, setTrends] = useState<DouyuPlatformTrends | null>(null);
|
|
const [trendAlerts, setTrendAlerts] = useState<DouyuPlatformAlert[]>([]);
|
|
const [statusLoading, setStatusLoading] = useState(false);
|
|
const [supplyLoading, setSupplyLoading] = useState(false);
|
|
const [trendsLoading, setTrendsLoading] = useState(false);
|
|
const [error, setError] = useState('');
|
|
const [modalOpen, setModalOpen] = useState(false);
|
|
const [saving, setSaving] = useState(false);
|
|
const [editing, setEditing] = useState<DouyuSupplyTarget | null>(null);
|
|
const [protectionModalOpen, setProtectionModalOpen] = useState(false);
|
|
const [protectionSaving, setProtectionSaving] = useState(false);
|
|
const [editingProtection, setEditingProtection] =
|
|
useState<DouyuAccountProtectionTarget | null>(null);
|
|
|
|
const loadStatus = useCallback(async () => {
|
|
setStatusLoading(true);
|
|
setError('');
|
|
const statusPromise = douyuApi
|
|
.getAccountPlatformStatus({
|
|
includeTrends: false,
|
|
includeSupply: false,
|
|
includeDiagnostics: false,
|
|
})
|
|
.then((platformStatus) => {
|
|
setStatus(platformStatus);
|
|
})
|
|
.catch((loadError: unknown) => {
|
|
setError(getErrorMessage(loadError));
|
|
})
|
|
.finally(() => {
|
|
setStatusLoading(false);
|
|
});
|
|
const targetsPromise = canManage
|
|
? douyuApi.listSupplyTargetConfigs()
|
|
.then(setTargetConfigs)
|
|
.catch((loadError: unknown) => {
|
|
setError((current) => current || getErrorMessage(loadError));
|
|
})
|
|
: Promise.resolve();
|
|
await Promise.allSettled([statusPromise, targetsPromise]);
|
|
}, [canManage]);
|
|
|
|
const loadSupply = useCallback(async () => {
|
|
setSupplyLoading(true);
|
|
try {
|
|
const response = await douyuApi.getAccountPlatformSupply();
|
|
setSupplyTargets(response.supply_targets);
|
|
setSupplyAlerts(response.alerts);
|
|
} catch (loadError: unknown) {
|
|
setSupplyAlerts([{
|
|
code: 'account_supply_load_failed',
|
|
severity: 'warning',
|
|
message: `供给库存加载失败:${getErrorMessage(loadError)}`,
|
|
}]);
|
|
} finally {
|
|
setSupplyLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
const loadTrends = useCallback(async () => {
|
|
setTrendsLoading(true);
|
|
try {
|
|
const response = await douyuApi.getAccountPlatformTrends();
|
|
setTrends(response.trends);
|
|
setTrendAlerts(response.alerts);
|
|
} catch (loadError: unknown) {
|
|
setTrendAlerts([{
|
|
code: 'account_trends_load_failed',
|
|
severity: 'info',
|
|
message: `趋势加载失败:${getErrorMessage(loadError)}`,
|
|
}]);
|
|
} finally {
|
|
setTrendsLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
const load = useCallback(async () => {
|
|
await loadStatus();
|
|
// 首屏状态已经可交互;供给和趋势较重,按顺序加载,避免同时争抢数据库。
|
|
await loadSupply();
|
|
await loadTrends();
|
|
}, [loadStatus, loadSupply, loadTrends]);
|
|
|
|
useEffect(() => {
|
|
void load();
|
|
}, [load]);
|
|
|
|
const pendingWork = useMemo(
|
|
() => Object.values(status?.work_queue || {}).reduce(
|
|
(total, bucket) => total + Number(bucket.pending || 0),
|
|
0,
|
|
),
|
|
[status?.work_queue],
|
|
);
|
|
const targets = useMemo<DouyuSupplyTarget[]>(() => {
|
|
const inventoryByTarget = new Map(
|
|
supplyTargets.map((row) => [row.target_id, row]),
|
|
);
|
|
const statusConfigs: DouyuSupplyTargetConfig[] = supplyTargets.map(
|
|
(row) => ({
|
|
id: row.target_id,
|
|
target_id: row.target_id,
|
|
platform: 'douyu',
|
|
scope: row.scope,
|
|
commodity_id: row.commodity_id,
|
|
value_class: row.value_class,
|
|
target_covered: row.target_covered,
|
|
target_available: row.target_available,
|
|
target_allocatable: row.target_allocatable,
|
|
safety_buffer: row.safety_buffer,
|
|
enabled: true,
|
|
updated_by: null,
|
|
updated_at: null,
|
|
}),
|
|
);
|
|
const sourceConfigs = canManage && targetConfigs.length > 0
|
|
? targetConfigs
|
|
: statusConfigs;
|
|
return sourceConfigs.map((config) => {
|
|
const inventory = inventoryByTarget.get(config.target_id);
|
|
return {
|
|
...config,
|
|
covered: inventory?.covered || 0,
|
|
available: inventory?.available || 0,
|
|
allocatable: inventory?.allocatable || 0,
|
|
covered_shortage: inventory?.covered_shortage || 0,
|
|
available_shortage: inventory?.available_shortage || 0,
|
|
allocatable_shortage: inventory?.allocatable_shortage || 0,
|
|
needs_replenishment: inventory?.needs_replenishment || false,
|
|
};
|
|
});
|
|
}, [canManage, supplyTargets, targetConfigs]);
|
|
const trendRows = useMemo(() => {
|
|
if (!trends) return [];
|
|
const rows = new Map<string, TrendRow>();
|
|
for (const item of trends.query) {
|
|
rows.set(item.date, {
|
|
date: item.date,
|
|
queryTotal: item.total,
|
|
queryRate: item.success_rate,
|
|
loginTotal: 0,
|
|
loginRate: 0,
|
|
ckInvalid: 0,
|
|
reloginOk: 0,
|
|
});
|
|
}
|
|
for (const item of trends.login) {
|
|
const row = rows.get(item.date) || {
|
|
date: item.date,
|
|
queryTotal: 0,
|
|
queryRate: 0,
|
|
loginTotal: 0,
|
|
loginRate: 0,
|
|
ckInvalid: 0,
|
|
reloginOk: 0,
|
|
};
|
|
row.loginTotal = item.total;
|
|
row.loginRate = item.success_rate;
|
|
rows.set(item.date, row);
|
|
}
|
|
for (const item of trends.lifecycle) {
|
|
const row = rows.get(item.date) || {
|
|
date: item.date,
|
|
queryTotal: 0,
|
|
queryRate: 0,
|
|
loginTotal: 0,
|
|
loginRate: 0,
|
|
ckInvalid: 0,
|
|
reloginOk: 0,
|
|
};
|
|
row.ckInvalid = item.ck_invalid;
|
|
row.reloginOk = item.relogin_ok;
|
|
rows.set(item.date, row);
|
|
}
|
|
return [...rows.values()].sort((left, right) => left.date.localeCompare(right.date));
|
|
}, [trends]);
|
|
const visibleAlerts = useMemo(
|
|
() => [...(status?.alerts || []), ...supplyAlerts, ...trendAlerts],
|
|
[status?.alerts, supplyAlerts, trendAlerts],
|
|
);
|
|
const loading = statusLoading || supplyLoading || trendsLoading;
|
|
|
|
const openCreate = () => {
|
|
setEditing(null);
|
|
form.setFieldsValue({
|
|
scope: 'elite',
|
|
commodity_id: '',
|
|
value_class: 'high_value',
|
|
target_covered: 30,
|
|
target_available: 20,
|
|
target_allocatable: 10,
|
|
safety_buffer: 3,
|
|
enabled: true,
|
|
});
|
|
setModalOpen(true);
|
|
};
|
|
|
|
const openEdit = (target: DouyuSupplyTarget) => {
|
|
setEditing(target);
|
|
form.setFieldsValue({
|
|
scope: target.scope,
|
|
commodity_id: target.commodity_id,
|
|
value_class: target.value_class,
|
|
target_covered: target.target_covered,
|
|
target_available: target.target_available,
|
|
target_allocatable: target.target_allocatable,
|
|
safety_buffer: target.safety_buffer,
|
|
enabled: target.enabled,
|
|
});
|
|
setModalOpen(true);
|
|
};
|
|
|
|
const saveTarget = async () => {
|
|
const values = await form.validateFields();
|
|
setSaving(true);
|
|
try {
|
|
const payload = {
|
|
target_covered: Number(values.target_covered || 0),
|
|
target_available: Number(values.target_available || 0),
|
|
target_allocatable: Number(values.target_allocatable || 0),
|
|
safety_buffer: Number(values.safety_buffer || 0),
|
|
enabled: Boolean(values.enabled),
|
|
};
|
|
if (editing) {
|
|
await douyuApi.updateSupplyTarget(editing.target_id, payload);
|
|
} else {
|
|
await douyuApi.createSupplyTarget({
|
|
platform: 'douyu',
|
|
scope: values.scope,
|
|
commodity_id: (values.commodity_id || '').trim(),
|
|
value_class: values.value_class,
|
|
...payload,
|
|
});
|
|
}
|
|
message.success(editing ? '供给目标已更新' : '供给目标已创建');
|
|
setModalOpen(false);
|
|
await load();
|
|
} catch (saveError: unknown) {
|
|
message.error(getErrorMessage(saveError));
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
};
|
|
|
|
const openProtectionEdit = (target: DouyuAccountProtectionTarget) => {
|
|
setEditingProtection(target);
|
|
protectionForm.setFieldsValue({
|
|
enabled: target.enabled,
|
|
target_count: target.target_count,
|
|
probe_interval_minutes: target.probe_interval_minutes,
|
|
auto_relogin: target.auto_relogin,
|
|
});
|
|
setProtectionModalOpen(true);
|
|
};
|
|
|
|
const saveProtectionTarget = async () => {
|
|
if (!editingProtection) return;
|
|
const values = await protectionForm.validateFields();
|
|
setProtectionSaving(true);
|
|
try {
|
|
await douyuApi.updateAccountProtectionTarget(editingProtection.group_key, {
|
|
enabled: Boolean(values.enabled),
|
|
target_count: Number(values.target_count || 0),
|
|
probe_interval_minutes: Number(values.probe_interval_minutes || 60),
|
|
auto_relogin: Boolean(values.auto_relogin),
|
|
});
|
|
message.success('履约保护目标已更新');
|
|
setProtectionModalOpen(false);
|
|
await load();
|
|
} catch (saveError: unknown) {
|
|
message.error(getErrorMessage(saveError));
|
|
} finally {
|
|
setProtectionSaving(false);
|
|
}
|
|
};
|
|
|
|
const protectionColumns: TableProps<DouyuAccountProtectionTarget>['columns'] = [
|
|
{
|
|
title: '保护分类',
|
|
width: 190,
|
|
render: (_, row) => (
|
|
<Space size={6}>
|
|
<SafetyCertificateOutlined />
|
|
<Space size={0} orientation="vertical">
|
|
<Text strong>{row.label}</Text>
|
|
<Text type="secondary" style={{ fontSize: 12 }}>{row.description}</Text>
|
|
</Space>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: '当前绑定',
|
|
dataIndex: 'bound_count',
|
|
width: 90,
|
|
},
|
|
{
|
|
title: '有效 CK / 目标',
|
|
width: 130,
|
|
render: (_, row) => (
|
|
<Space size={4}>
|
|
<Text type={row.ck_invalid + row.ck_error > 0 ? 'danger' : undefined}>
|
|
{row.ck_valid}
|
|
</Text>
|
|
<Text type="secondary">/</Text>
|
|
<Text>{row.target_count || '未设'}</Text>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: '失效 / 异常',
|
|
width: 110,
|
|
render: (_, row) => {
|
|
const affected = row.ck_invalid + row.ck_error + row.without_cookie;
|
|
return affected > 0
|
|
? <Text type="danger">{affected}</Text>
|
|
: <Text type="success">0</Text>;
|
|
},
|
|
},
|
|
{
|
|
title: '巡检间隔',
|
|
width: 100,
|
|
render: (_, row) => `${row.probe_interval_minutes} 分钟`,
|
|
},
|
|
{
|
|
title: '自动重登',
|
|
width: 90,
|
|
render: (_, row) => (
|
|
row.auto_relogin
|
|
? <Tag color="blue">优先</Tag>
|
|
: <Tag>不处理</Tag>
|
|
),
|
|
},
|
|
{
|
|
title: '状态',
|
|
width: 100,
|
|
render: (_, row) => {
|
|
if (!row.enabled) return <Tag>已停用</Tag>;
|
|
if (row.needs_attention) return <Tag color="warning">需关注</Tag>;
|
|
return <Tag color="success">正常</Tag>;
|
|
},
|
|
},
|
|
...(canManage ? [{
|
|
title: '操作',
|
|
width: 110,
|
|
render: (_: unknown, row: DouyuAccountProtectionTarget) => (
|
|
<Button
|
|
type="link"
|
|
size="small"
|
|
icon={<EditOutlined />}
|
|
onClick={() => openProtectionEdit(row)}
|
|
>
|
|
设置目标
|
|
</Button>
|
|
),
|
|
}] : []),
|
|
];
|
|
|
|
const columns: TableProps<DouyuSupplyTarget>['columns'] = [
|
|
{
|
|
title: '分类',
|
|
width: 130,
|
|
render: (_, row) => (
|
|
<Space size={4}>
|
|
<Tag color={row.value_class === 'high_value' ? 'gold' : 'blue'}>
|
|
{VALUE_LABELS[row.value_class] || row.value_class}
|
|
</Tag>
|
|
<Text type="secondary">{row.scope}</Text>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: '覆盖',
|
|
width: 110,
|
|
render: (_, row) => targetTotal(row.covered, row.target_covered, row.safety_buffer),
|
|
},
|
|
{
|
|
title: '可兑换',
|
|
width: 110,
|
|
render: (_, row) => targetTotal(row.available, row.target_available, row.safety_buffer),
|
|
},
|
|
{
|
|
title: '可分配',
|
|
width: 110,
|
|
render: (_, row) => targetTotal(row.allocatable, row.target_allocatable, row.safety_buffer),
|
|
},
|
|
{
|
|
title: '缺口',
|
|
width: 90,
|
|
render: (_, row) => {
|
|
const shortage = Math.max(
|
|
row.covered_shortage,
|
|
row.available_shortage,
|
|
row.allocatable_shortage,
|
|
);
|
|
return shortage > 0
|
|
? <Text type="danger">{shortage}</Text>
|
|
: <Text type="success">0</Text>;
|
|
},
|
|
},
|
|
{
|
|
title: '状态',
|
|
width: 110,
|
|
render: (_, row) => (
|
|
!row.enabled
|
|
? <Tag>已停用</Tag>
|
|
: row.needs_replenishment
|
|
? <Tag color="warning">需补货</Tag>
|
|
: <Tag color="success">达标</Tag>
|
|
),
|
|
},
|
|
...(canManage ? [{
|
|
title: '操作',
|
|
width: 80,
|
|
render: (_: unknown, row: DouyuSupplyTarget) => (
|
|
<Button
|
|
type="link"
|
|
size="small"
|
|
icon={<EditOutlined />}
|
|
onClick={() => openEdit(row)}
|
|
>
|
|
编辑
|
|
</Button>
|
|
),
|
|
}] : []),
|
|
];
|
|
|
|
const trendColumns: TableProps<TrendRow>['columns'] = [
|
|
{
|
|
title: '日期',
|
|
dataIndex: 'date',
|
|
width: 100,
|
|
render: (value: string) => value.slice(5),
|
|
},
|
|
{
|
|
title: '查询成功率',
|
|
width: 140,
|
|
render: (_, row) => (
|
|
<Progress
|
|
percent={row.queryRate}
|
|
size="small"
|
|
status={row.queryRate < 70 ? 'exception' : 'normal'}
|
|
/>
|
|
),
|
|
},
|
|
{ title: '查询量', dataIndex: 'queryTotal', width: 80 },
|
|
{
|
|
title: '登录成功率',
|
|
width: 140,
|
|
render: (_, row) => (
|
|
<Progress
|
|
percent={row.loginRate}
|
|
size="small"
|
|
status={row.loginRate < 50 ? 'exception' : 'normal'}
|
|
/>
|
|
),
|
|
},
|
|
{ title: '登录量', dataIndex: 'loginTotal', width: 80 },
|
|
{
|
|
title: 'CK 失效',
|
|
dataIndex: 'ckInvalid',
|
|
width: 90,
|
|
render: (value: number) => value > 0 ? <Text type="danger">{value}</Text> : 0,
|
|
},
|
|
{ title: '重登成功', dataIndex: 'reloginOk', width: 90 },
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<Card
|
|
title="账号平台状态"
|
|
extra={(
|
|
<Space size={8}>
|
|
<Text type="secondary">
|
|
{status?.checked_at ? formatTime(status.checked_at) : '-'}
|
|
</Text>
|
|
{canManage ? (
|
|
<Button icon={<PlusOutlined />} onClick={openCreate}>
|
|
新增目标
|
|
</Button>
|
|
) : null}
|
|
<Button icon={<ReloadOutlined />} loading={loading} onClick={() => void load()}>
|
|
刷新
|
|
</Button>
|
|
</Space>
|
|
)}
|
|
>
|
|
{error ? <Alert type="error" showIcon message={error} style={{ marginBottom: 16 }} /> : null}
|
|
<Row gutter={[16, 16]}>
|
|
<Col xs={12} md={6}><Statistic title="CK 有效" value={status ? status.accounts.ck_valid : '--'} /></Col>
|
|
<Col xs={12} md={6}><Statistic title="24h 预计到期" value={status ? status.accounts.ck_expiring_24h : '--'} /></Col>
|
|
<Col xs={12} md={6}><Statistic title="新鲜兑换资格商品" value={status ? status.commodities.fresh_eligible : '--'} /></Col>
|
|
<Col xs={12} md={6}><Statistic title="待处理账号工作" value={status ? pendingWork : '--'} /></Col>
|
|
</Row>
|
|
|
|
{visibleAlerts.length ? (
|
|
<Space orientation="vertical" size={8} style={{ width: '100%', marginTop: 16 }}>
|
|
{visibleAlerts.map((alert) => (
|
|
<Alert
|
|
key={`${alert.code}-${alert.scope || ''}-${alert.value_class || ''}-${alert.message}`}
|
|
type={alert.severity === 'critical' ? 'error' : alert.severity === 'warning' ? 'warning' : 'info'}
|
|
showIcon
|
|
message={alert.message}
|
|
/>
|
|
))}
|
|
</Space>
|
|
) : null}
|
|
|
|
<Space orientation="vertical" size={2} style={{ width: '100%', marginTop: 20 }}>
|
|
<Text strong>履约保护目标</Text>
|
|
<Text type="secondary">
|
|
保持预售与外部协作单绑定账号的 CK 有效,失效后优先进入自动重登队列
|
|
</Text>
|
|
</Space>
|
|
<Table
|
|
rowKey="group_key"
|
|
size="small"
|
|
style={{ marginTop: 8 }}
|
|
columns={protectionColumns}
|
|
dataSource={status?.protection_targets || []}
|
|
loading={statusLoading}
|
|
pagination={false}
|
|
scroll={{ x: 950 }}
|
|
locale={{
|
|
emptyText: (
|
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无履约保护目标" />
|
|
),
|
|
}}
|
|
/>
|
|
|
|
<Space orientation="vertical" size={2} style={{ width: '100%', marginTop: 20 }}>
|
|
<Text strong>账号供给目标</Text>
|
|
<Text type="secondary">按高价值、普通账号和商品维度维护可兑换与可分配库存</Text>
|
|
</Space>
|
|
<Table
|
|
rowKey="target_id"
|
|
size="small"
|
|
style={{ marginTop: 8 }}
|
|
columns={columns}
|
|
dataSource={targets}
|
|
loading={supplyLoading}
|
|
pagination={false}
|
|
scroll={{ x: 750 }}
|
|
locale={{
|
|
emptyText: (
|
|
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无供给目标" />
|
|
),
|
|
}}
|
|
/>
|
|
|
|
<Space orientation="vertical" size={12} style={{ width: '100%', marginTop: 20 }}>
|
|
<div>
|
|
<Text strong>{`近 ${trends?.days || 7} 天运行趋势`}</Text>
|
|
<Text type="secondary" style={{ marginLeft: 8 }}>
|
|
查询、登录、CK 失效和重登结果
|
|
</Text>
|
|
</div>
|
|
<Row gutter={[24, 16]}>
|
|
<Col xs={24} md={12} xl={6}>
|
|
<MiniTrend
|
|
title="查询量"
|
|
values={trendRows.map((row) => row.queryTotal)}
|
|
dates={trendRows.map((row) => row.date)}
|
|
color="#1677ff"
|
|
/>
|
|
</Col>
|
|
<Col xs={24} md={12} xl={6}>
|
|
<MiniTrend
|
|
title="登录量"
|
|
values={trendRows.map((row) => row.loginTotal)}
|
|
dates={trendRows.map((row) => row.date)}
|
|
color="#13c2c2"
|
|
/>
|
|
</Col>
|
|
<Col xs={24} md={12} xl={6}>
|
|
<MiniTrend
|
|
title="CK 失效"
|
|
values={trendRows.map((row) => row.ckInvalid)}
|
|
dates={trendRows.map((row) => row.date)}
|
|
color="#ff4d4f"
|
|
/>
|
|
</Col>
|
|
<Col xs={24} md={12} xl={6}>
|
|
<MiniTrend
|
|
title="重登成功"
|
|
values={trendRows.map((row) => row.reloginOk)}
|
|
dates={trendRows.map((row) => row.date)}
|
|
color="#52c41a"
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
<Collapse
|
|
ghost
|
|
defaultActiveKey={['trend-detail']}
|
|
items={[
|
|
{
|
|
key: 'trend-detail',
|
|
label: '查看每日趋势明细',
|
|
children: (
|
|
<Table
|
|
rowKey="date"
|
|
size="small"
|
|
columns={trendColumns}
|
|
dataSource={trendRows}
|
|
loading={trendsLoading}
|
|
pagination={false}
|
|
scroll={{ x: 750 }}
|
|
/>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
</Space>
|
|
</Card>
|
|
|
|
<Modal
|
|
title={editing ? '编辑供给目标' : '新增供给目标'}
|
|
open={modalOpen}
|
|
confirmLoading={saving}
|
|
onOk={() => void saveTarget()}
|
|
onCancel={() => setModalOpen(false)}
|
|
okText="保存"
|
|
cancelText="取消"
|
|
destroyOnHidden
|
|
>
|
|
<Form form={form} layout="vertical">
|
|
<Row gutter={12}>
|
|
<Col span={12}>
|
|
<Form.Item name="scope" label="作用域" rules={[{ required: true }]}>
|
|
<Select
|
|
disabled={Boolean(editing)}
|
|
options={[
|
|
{ value: 'elite', label: '精英宝典' },
|
|
{ value: 'esports', label: '电竞手册' },
|
|
{ value: 'peace', label: '和平小店' },
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item name="value_class" label="账号价值" rules={[{ required: true }]}>
|
|
<Select
|
|
disabled={Boolean(editing)}
|
|
options={[
|
|
{ value: 'high_value', label: '高价值' },
|
|
{ value: 'ordinary', label: '普通' },
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Form.Item name="commodity_id" label="商品 ID">
|
|
<Input disabled={Boolean(editing)} placeholder="留空表示该作用域全部商品" />
|
|
</Form.Item>
|
|
<Row gutter={12}>
|
|
<Col span={12}>
|
|
<Form.Item name="target_covered" label="覆盖目标">
|
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item name="target_available" label="可兑换目标">
|
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Row gutter={12}>
|
|
<Col span={12}>
|
|
<Form.Item name="target_allocatable" label="可分配目标">
|
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item name="safety_buffer" label="安全缓冲">
|
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Form.Item name="enabled" label="启用" valuePropName="checked">
|
|
<Switch />
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
|
|
<Modal
|
|
title={editingProtection ? `设置${editingProtection.label}目标` : '设置履约保护目标'}
|
|
open={protectionModalOpen}
|
|
confirmLoading={protectionSaving}
|
|
onOk={() => void saveProtectionTarget()}
|
|
onCancel={() => setProtectionModalOpen(false)}
|
|
okText="保存"
|
|
cancelText="取消"
|
|
destroyOnHidden
|
|
>
|
|
<Form form={protectionForm} layout="vertical">
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
message={editingProtection?.description}
|
|
style={{ marginBottom: 16 }}
|
|
/>
|
|
<Row gutter={12}>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
name="target_count"
|
|
label="目标有效 CK"
|
|
tooltip="用于缺口预警;组内当前全部绑定账号都会纳入保护巡检"
|
|
>
|
|
<InputNumber min={0} precision={0} style={{ width: '100%' }} />
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
name="probe_interval_minutes"
|
|
label="保护巡检间隔"
|
|
tooltip="启用后,组内账号至少按此间隔检测一次 CK"
|
|
>
|
|
<InputNumber
|
|
min={15}
|
|
max={1440}
|
|
precision={0}
|
|
addonAfter="分钟"
|
|
style={{ width: '100%' }}
|
|
/>
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Form.Item name="enabled" label="启用保护" valuePropName="checked">
|
|
<Switch />
|
|
</Form.Item>
|
|
<Form.Item
|
|
name="auto_relogin"
|
|
label="失效后自动重登"
|
|
valuePropName="checked"
|
|
tooltip="仍受自动化页面中的 CK 自动重登总开关控制"
|
|
>
|
|
<Switch />
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|