perf(fulfillment): 优化本地能力选号查询与索引
This commit is contained in:
@@ -30,6 +30,8 @@ import {
|
||||
type TableProps,
|
||||
} from 'antd';
|
||||
import {
|
||||
ArrowDownOutlined,
|
||||
ArrowUpOutlined,
|
||||
CheckCircleOutlined,
|
||||
CopyOutlined,
|
||||
DeleteOutlined,
|
||||
@@ -44,6 +46,7 @@ import {
|
||||
RobotOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SearchOutlined,
|
||||
SettingOutlined,
|
||||
ShopOutlined,
|
||||
SyncOutlined,
|
||||
TagOutlined,
|
||||
@@ -94,6 +97,74 @@ function hasTextInputFocus(): boolean {
|
||||
/** 实时同步暂停开关按浏览器记住:刷新页面后仍保持暂停,直到手动恢复。 */
|
||||
const REALTIME_PAUSED_STORAGE_KEY = 'douyu.collab.realtime-paused';
|
||||
const REALTIME_WS_PATH = '/api/douyu/external-orders/ws';
|
||||
const COLUMN_LAYOUT_STORAGE_PREFIX = 'douyu.collab.columns';
|
||||
|
||||
const DEFAULT_COLUMN_LAYOUT = [
|
||||
{ key: 'sequence', visible: true },
|
||||
{ key: 'order_shop', visible: true },
|
||||
{ key: 'owner', visible: true },
|
||||
{ key: 'account', visible: true },
|
||||
{ key: 'bind_role', visible: true },
|
||||
{ key: 'home_images', visible: true },
|
||||
{ key: 'gift', visible: true },
|
||||
{ key: 'status', visible: true },
|
||||
{ key: 'balances', visible: true },
|
||||
{ key: 'last_query', visible: true },
|
||||
{ key: 'updated', visible: true },
|
||||
{ key: 'actions', visible: true },
|
||||
] as const;
|
||||
|
||||
const COLUMN_LABELS: Record<string, string> = {
|
||||
sequence: '序号',
|
||||
order_shop: '订单 / 店铺',
|
||||
owner: '负责人',
|
||||
account: '斗鱼账号',
|
||||
bind_role: '绑定角色',
|
||||
home_images: '主页截图',
|
||||
gift: '礼包 / 积分',
|
||||
status: '状态',
|
||||
balances: '鱼翅 / 积分',
|
||||
last_query: '最近查询',
|
||||
updated: '最后改动',
|
||||
actions: '操作',
|
||||
};
|
||||
|
||||
type ColumnPreference = { key: string; visible: boolean };
|
||||
|
||||
function normalizeColumnLayout(raw: unknown): ColumnPreference[] {
|
||||
const defaults = DEFAULT_COLUMN_LAYOUT.map((item) => ({ ...item }));
|
||||
if (!Array.isArray(raw)) return defaults;
|
||||
const known = new Set<string>(defaults.map((item) => item.key));
|
||||
const result: ColumnPreference[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const item of raw) {
|
||||
if (!item || typeof item !== 'object') continue;
|
||||
const row = item as { key?: unknown; visible?: unknown };
|
||||
const key = String(row.key || '');
|
||||
if (!known.has(key) || seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
result.push({
|
||||
key,
|
||||
visible: key === 'actions' ? true : row.visible !== false,
|
||||
});
|
||||
}
|
||||
for (const item of defaults) {
|
||||
if (!seen.has(item.key)) result.push(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function readColumnLayout(userId?: number): ColumnPreference[] {
|
||||
if (!userId) return normalizeColumnLayout(null);
|
||||
try {
|
||||
const raw = window.localStorage.getItem(
|
||||
`${COLUMN_LAYOUT_STORAGE_PREFIX}:${userId}`,
|
||||
);
|
||||
return normalizeColumnLayout(raw ? JSON.parse(raw) : null);
|
||||
} catch {
|
||||
return normalizeColumnLayout(null);
|
||||
}
|
||||
}
|
||||
|
||||
function readRealtimePaused(): boolean {
|
||||
try {
|
||||
@@ -445,6 +516,11 @@ export default function DouyuCollabPage() {
|
||||
canEdit && (user?.role === 'super_admin' || user?.role === 'operation');
|
||||
// 单行复制是一键带走凭据,和虎牙台账保持一致:只给超级管理员(后端再校验)
|
||||
const isAdmin = user?.role === 'super_admin';
|
||||
const [columnLayout, setColumnLayout] = useState<ColumnPreference[]>(
|
||||
() => readColumnLayout(user?.id),
|
||||
);
|
||||
const [columnSettingsOpen, setColumnSettingsOpen] = useState(false);
|
||||
const [columnDraft, setColumnDraft] = useState<ColumnPreference[]>([]);
|
||||
|
||||
const [orders, setOrders] = useState<DouyuCollabOrder[]>([]);
|
||||
const [summary, setSummary] = useState<DouyuCollabSummary>({
|
||||
@@ -508,6 +584,10 @@ export default function DouyuCollabPage() {
|
||||
const handledQueryOrderIdRef = useRef(0);
|
||||
const queryOrderId = Number(searchParams.get('orderId') || 0);
|
||||
|
||||
useEffect(() => {
|
||||
setColumnLayout(readColumnLayout(user?.id));
|
||||
}, [user?.id]);
|
||||
|
||||
const [statusTarget, setStatusTarget] = useState<DouyuCollabOrder | null>(null);
|
||||
const [batchStatusOpen, setBatchStatusOpen] = useState(false);
|
||||
const [statusValue, setStatusValue] = useState<DouyuCollabStatus>('to_recharge');
|
||||
@@ -1555,8 +1635,44 @@ export default function DouyuCollabPage() {
|
||||
})),
|
||||
];
|
||||
|
||||
const openColumnSettings = () => {
|
||||
setColumnDraft(columnLayout.map((item) => ({ ...item })));
|
||||
setColumnSettingsOpen(true);
|
||||
};
|
||||
|
||||
const moveColumn = (index: number, offset: number) => {
|
||||
setColumnDraft((current) => {
|
||||
const target = index + offset;
|
||||
if (target < 0 || target >= current.length) return current;
|
||||
const next = [...current];
|
||||
[next[index], next[target]] = [next[target], next[index]];
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const saveColumnSettings = () => {
|
||||
const normalized = normalizeColumnLayout(columnDraft);
|
||||
setColumnLayout(normalized);
|
||||
if (user?.id) {
|
||||
try {
|
||||
window.localStorage.setItem(
|
||||
`${COLUMN_LAYOUT_STORAGE_PREFIX}:${user.id}`,
|
||||
JSON.stringify(normalized),
|
||||
);
|
||||
} catch {
|
||||
// 隐私模式下仍保留本次页面会话的列设置。
|
||||
}
|
||||
}
|
||||
setColumnSettingsOpen(false);
|
||||
};
|
||||
|
||||
const resetColumnSettings = () => {
|
||||
setColumnDraft(normalizeColumnLayout(null));
|
||||
};
|
||||
|
||||
const columns: TableProps<DouyuCollabOrder>['columns'] = [
|
||||
{
|
||||
key: 'sequence',
|
||||
title: '序号',
|
||||
width: 72,
|
||||
fixed: 'left',
|
||||
@@ -1564,9 +1680,10 @@ export default function DouyuCollabPage() {
|
||||
render: (_, row) => <Text type="secondary">{row.id}</Text>,
|
||||
},
|
||||
{
|
||||
title: '订单编号',
|
||||
key: 'order_shop',
|
||||
title: '订单 / 店铺',
|
||||
dataIndex: 'order_no',
|
||||
width: 170,
|
||||
width: 260,
|
||||
fixed: 'left',
|
||||
render: (value: string, row) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
@@ -1577,16 +1694,21 @@ export default function DouyuCollabPage() {
|
||||
<Tag color="cyan">履约同步 · #{row.source_task_id}</Tag>
|
||||
)}
|
||||
{row.status === 'void' && <Tag color="error">已作废:{row.void_reason || '-'}</Tag>}
|
||||
<Space size={4} wrap>
|
||||
<Tag color={row.shop ? 'blue' : 'default'}>
|
||||
{row.shop || '未填店铺'}
|
||||
</Tag>
|
||||
{row.shop_original_name && row.shop_original_name !== row.shop && (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{row.shop_original_name}
|
||||
</Text>
|
||||
)}
|
||||
</Space>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '店铺',
|
||||
dataIndex: 'shop',
|
||||
width: 120,
|
||||
render: (value: string) => value || <Text type="secondary">未填</Text>,
|
||||
},
|
||||
{
|
||||
key: 'owner',
|
||||
title: '负责人',
|
||||
dataIndex: 'owner_id',
|
||||
width: 120,
|
||||
@@ -1617,6 +1739,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'account',
|
||||
title: '斗鱼账号',
|
||||
width: 210,
|
||||
render: (_, row) => (
|
||||
@@ -1666,6 +1789,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'bind_role',
|
||||
title: '绑定角色',
|
||||
width: 180,
|
||||
render: (_, row) => (
|
||||
@@ -1683,6 +1807,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'home_images',
|
||||
title: '主页截图',
|
||||
width: 110,
|
||||
align: 'center',
|
||||
@@ -1713,6 +1838,7 @@ export default function DouyuCollabPage() {
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'gift',
|
||||
title: '礼包 / 积分',
|
||||
width: 200,
|
||||
render: (_, row) => (
|
||||
@@ -1730,6 +1856,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'status',
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 130,
|
||||
@@ -1741,6 +1868,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'balances',
|
||||
title: '鱼翅 / 积分',
|
||||
width: 170,
|
||||
render: (_, row) => {
|
||||
@@ -1758,6 +1886,7 @@ export default function DouyuCollabPage() {
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'last_query',
|
||||
title: '最近查询',
|
||||
width: 160,
|
||||
render: (_, row) =>
|
||||
@@ -1775,6 +1904,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'updated',
|
||||
title: '最后改动',
|
||||
width: 150,
|
||||
render: (_, row) => (
|
||||
@@ -1787,6 +1917,7 @@ export default function DouyuCollabPage() {
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'actions',
|
||||
title: '操作',
|
||||
width: 500,
|
||||
fixed: 'right',
|
||||
@@ -1891,6 +2022,14 @@ export default function DouyuCollabPage() {
|
||||
},
|
||||
];
|
||||
|
||||
const columnByKey = new Map(
|
||||
(columns || []).map((column) => [String(column.key || ''), column]),
|
||||
);
|
||||
const visibleColumns = columnLayout
|
||||
.filter((item) => item.visible)
|
||||
.map((item) => columnByKey.get(item.key))
|
||||
.filter((column): column is NonNullable<typeof column> => Boolean(column));
|
||||
|
||||
const goodsPool = lookup?.goods?.length ? lookup.goods : goods;
|
||||
const giftNameOptions = (() => {
|
||||
const options: Array<{ value: string; label: string; disabled: boolean }> = [];
|
||||
@@ -2133,6 +2272,9 @@ export default function DouyuCollabPage() {
|
||||
<Button icon={<ReloadOutlined />} onClick={() => void loadOrders()} loading={loading}>
|
||||
刷新
|
||||
</Button>
|
||||
<Button icon={<SettingOutlined />} onClick={openColumnSettings}>
|
||||
列设置
|
||||
</Button>
|
||||
{realtimePending && <Tag color="processing">有更新待同步</Tag>}
|
||||
<Text type="secondary">已选 {selectedCount} 单</Text>
|
||||
{canView && (
|
||||
@@ -2238,7 +2380,7 @@ export default function DouyuCollabPage() {
|
||||
size="small"
|
||||
tableLayout="fixed"
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
columns={visibleColumns}
|
||||
dataSource={orders}
|
||||
scroll={{ x: 2190 }}
|
||||
rowSelection={{
|
||||
@@ -2262,6 +2404,64 @@ export default function DouyuCollabPage() {
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
title="表格列设置"
|
||||
open={columnSettingsOpen}
|
||||
onCancel={() => setColumnSettingsOpen(false)}
|
||||
onOk={saveColumnSettings}
|
||||
okText="保存"
|
||||
cancelText="取消"
|
||||
footer={(_, { OkBtn, CancelBtn }) => (
|
||||
<Space>
|
||||
<Button onClick={resetColumnSettings}>恢复默认</Button>
|
||||
<CancelBtn />
|
||||
<OkBtn />
|
||||
</Space>
|
||||
)}
|
||||
>
|
||||
<Space direction="vertical" size={8} style={{ width: '100%' }}>
|
||||
{columnDraft.map((item, index) => (
|
||||
<div
|
||||
key={item.key}
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'minmax(0, 1fr) auto auto',
|
||||
alignItems: 'center',
|
||||
gap: 8,
|
||||
padding: '4px 0',
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
checked={item.visible}
|
||||
disabled={item.key === 'actions'}
|
||||
onChange={(event) => {
|
||||
const visible = event.target.checked;
|
||||
setColumnDraft((current) => current.map((column) => (
|
||||
column.key === item.key ? { ...column, visible } : column
|
||||
)));
|
||||
}}
|
||||
>
|
||||
{COLUMN_LABELS[item.key] || item.key}
|
||||
</Checkbox>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowUpOutlined />}
|
||||
aria-label="上移"
|
||||
disabled={index === 0}
|
||||
onClick={() => moveColumn(index, -1)}
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowDownOutlined />}
|
||||
aria-label="下移"
|
||||
disabled={index === columnDraft.length - 1}
|
||||
onClick={() => moveColumn(index, 1)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<DouyuCollabShopModal
|
||||
open={shopModalOpen}
|
||||
shops={shopRecords}
|
||||
|
||||
@@ -128,7 +128,9 @@ const EVENT_LABELS: Record<string, string> = {
|
||||
binding_failed: '游戏角色绑定失败',
|
||||
binding_reset: '重置角色资料和绑定记录',
|
||||
binding_stale_role_ignored: '忽略账号旧角色',
|
||||
binding_synced_from_account: '同步账号最新角色绑定',
|
||||
eligibility_check_failed: '兑换资格查询失败',
|
||||
eligibility_auto_refresh_failed: '自动刷新兑换资格失败',
|
||||
exchange_eligibility_checked: '刷新兑换资格',
|
||||
manual_exchange_completed: '人工兑换完成',
|
||||
marked_manual_required: '转人工处理',
|
||||
@@ -166,6 +168,7 @@ const ISSUE_LABELS: Record<string, string> = {
|
||||
};
|
||||
|
||||
const DOUYU_ACTION_LABELS: Record<string, string> = {
|
||||
query_game_name: '刷新角色绑定',
|
||||
query_elite_status: '查询精英宝典',
|
||||
create_elite_qr: '开通精英宝典',
|
||||
create_gold_qr: '充值鱼翅',
|
||||
@@ -241,7 +244,8 @@ function eventColor(value: string) {
|
||||
value.includes('completed') ||
|
||||
value.includes('allocated') ||
|
||||
value.includes('restored') ||
|
||||
value.includes('succeeded')
|
||||
value.includes('succeeded') ||
|
||||
value.includes('binding_synced')
|
||||
) {
|
||||
return 'green';
|
||||
}
|
||||
@@ -294,6 +298,9 @@ function eventDescription(event: { eventType: string; detail: Record<string, unk
|
||||
if (event.eventType === 'eligibility_check_failed') {
|
||||
return '实时查询兑换资格失败,可稍后重试';
|
||||
}
|
||||
if (event.eventType === 'eligibility_auto_refresh_failed') {
|
||||
return '账号变化后的自动刷新失败,任务状态保持不变,可手动刷新重试';
|
||||
}
|
||||
if (event.eventType === 'account_released') {
|
||||
return `释放原因:${String(detail.reason || '人工释放')}`;
|
||||
}
|
||||
@@ -331,6 +338,10 @@ function eventDescription(event: { eventType: string; detail: Record<string, unk
|
||||
if (event.eventType === 'binding_reset') {
|
||||
return `${String(detail.reason || '客服重置角色绑定')};客户需重新填写角色资料`;
|
||||
}
|
||||
if (event.eventType === 'binding_synced_from_account') {
|
||||
const channel = String(detail.gameChannel || '');
|
||||
return `账号已确认角色 ${String(detail.roleName || '-')}${channel ? `(${channel})` : ''}`;
|
||||
}
|
||||
if (event.eventType === 'task_created') return '订单已进入直播账号履约工作台';
|
||||
return '履约状态已更新';
|
||||
}
|
||||
@@ -1651,6 +1662,14 @@ export default function PlatformFulfillmentPage() {
|
||||
直接复用斗鱼精英宝典工作台任务,作用于当前履约账号;开通和充值会在任务窗口展示支付二维码。
|
||||
</Text>
|
||||
<Space wrap>
|
||||
<Button
|
||||
icon={<SyncOutlined />}
|
||||
disabled={!selected.account || !can('douyu:task')}
|
||||
loading={douyuActionLoading === 'query_game_name'}
|
||||
onClick={() => void runDouyuAccountAction('query_game_name')}
|
||||
>
|
||||
刷新角色绑定
|
||||
</Button>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
disabled={!selected.account || !can('douyu:task')}
|
||||
|
||||
Reference in New Issue
Block a user