refactor(collab): 拆分斗鱼虎牙协作服务与页面配置
This commit is contained in:
@@ -79,430 +79,35 @@ import { useCollabRealtime, type CollabRealtimeEvent } from '../hooks/useCollabR
|
||||
import { message } from '../utils/antdMessage';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
import { copyTextToClipboard } from '../utils/clipboard';
|
||||
import {
|
||||
CK_META,
|
||||
COLUMN_LABELS,
|
||||
COLUMN_LAYOUT_STORAGE_PREFIX,
|
||||
EMPTY_FORM,
|
||||
FLOW_ORDER,
|
||||
REALTIME_PAUSED_STORAGE_KEY,
|
||||
REALTIME_WS_PATH,
|
||||
STATUS_META,
|
||||
STATUS_ORDER,
|
||||
cardStyle,
|
||||
collabActionLabel,
|
||||
collabCkLabel,
|
||||
collabTimelineDetailLines,
|
||||
errorCodeOf,
|
||||
formatTime,
|
||||
goodsOptions,
|
||||
hasTextInputFocus,
|
||||
normalizeColumnLayout,
|
||||
pointsReasonMeta,
|
||||
readColumnLayout,
|
||||
readRealtimePaused,
|
||||
successfulPurchaseChanges,
|
||||
type ColumnPreference,
|
||||
type OrderFormState,
|
||||
} from './DouyuCollabPageConfig';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
function errorCodeOf(error: unknown): string {
|
||||
return (error as { errorCode?: string } | null)?.errorCode || '';
|
||||
}
|
||||
|
||||
function hasTextInputFocus(): boolean {
|
||||
const active = document.activeElement;
|
||||
return (
|
||||
active instanceof HTMLElement &&
|
||||
(active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable)
|
||||
);
|
||||
}
|
||||
|
||||
/** 实时同步暂停开关按浏览器记住:刷新页面后仍保持暂停,直到手动恢复。 */
|
||||
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 {
|
||||
return window.localStorage.getItem(REALTIME_PAUSED_STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function cardStyle(active: boolean) {
|
||||
return {
|
||||
borderColor: active ? '#1677ff' : undefined,
|
||||
cursor: 'pointer',
|
||||
} as const;
|
||||
}
|
||||
|
||||
const STATUS_META: Record<DouyuCollabStatus, { label: string; color: string }> = {
|
||||
incomplete: { label: '待补资料', color: 'default' },
|
||||
to_recharge: { label: '待充值', color: 'blue' },
|
||||
recharged: { label: '已充值', color: 'cyan' },
|
||||
scripted: { label: '已上脚本', color: 'purple' },
|
||||
done: { label: '抢购成功', color: 'green' },
|
||||
points_error: { label: '积分异常', color: 'orange' },
|
||||
role_error: { label: '账号角色异常', color: 'volcano' },
|
||||
failed: { label: '抢购失败', color: 'red' },
|
||||
void: { label: '已作废', color: 'default' },
|
||||
};
|
||||
|
||||
const STATUS_ORDER: DouyuCollabStatus[] = [
|
||||
'incomplete',
|
||||
'to_recharge',
|
||||
'recharged',
|
||||
'scripted',
|
||||
'done',
|
||||
'points_error',
|
||||
'role_error',
|
||||
'failed',
|
||||
'void',
|
||||
];
|
||||
|
||||
const FLOW_ORDER: DouyuCollabStatus[] = [
|
||||
'incomplete',
|
||||
'to_recharge',
|
||||
'recharged',
|
||||
'scripted',
|
||||
'done',
|
||||
];
|
||||
|
||||
const CK_META: Record<string, { label: string; color: string }> = {
|
||||
unverified: { label: '未检测', color: 'default' },
|
||||
valid: { label: 'CK 正常', color: 'green' },
|
||||
invalid: { label: 'CK 异常', color: 'red' },
|
||||
error: { label: 'CK 异常', color: 'red' },
|
||||
'': { label: '未检测', color: 'default' },
|
||||
};
|
||||
|
||||
const COLLAB_ACTION_LABELS: Record<string, string> = {
|
||||
'douyu:collab:create': '新建协作单',
|
||||
'douyu:collab:update': '编辑订单资料',
|
||||
'douyu:collab:account': '更换账号',
|
||||
'douyu:collab:account_unlink': '解除账号关联',
|
||||
'douyu:collab:verify': '校验账号',
|
||||
'douyu:collab:status': '修改订单状态',
|
||||
'douyu:collab:status_auto': '自动推进订单状态',
|
||||
'douyu:collab:void': '作废订单',
|
||||
'douyu:collab:void_restore': '恢复作废订单',
|
||||
'douyu:collab:points_error': '标记积分异常',
|
||||
'douyu:collab:role_error': '标记角色异常',
|
||||
'douyu:collab:activity': '查询兑换记录',
|
||||
'douyu:collab:ck_export': '导出账号与登录凭据',
|
||||
'douyu:collab:archive': '归档订单',
|
||||
'douyu:collab:unarchive': '取消归档',
|
||||
'douyu:collab:sync_from_platform_fulfillment': '同步直播履约单',
|
||||
'douyu:collab:lease_acquired': '建立账号占用',
|
||||
'douyu:collab:lease_released': '释放账号占用',
|
||||
'douyu:collab:lease_takeover': '接管账号占用',
|
||||
'douyu:collab:goods_refresh': '刷新活动商品',
|
||||
'douyu:collab:shop_update': '修改店铺',
|
||||
'douyu:collab:shop_delete': '删除店铺',
|
||||
'douyu:collab:gift_update': '修改礼包',
|
||||
'douyu:collab:gift_delete': '删除礼包',
|
||||
};
|
||||
|
||||
const COLLAB_DETAIL_LABELS: Record<string, string> = {
|
||||
order_no: '订单编号',
|
||||
orderNo: '平台订单编号',
|
||||
shop: '店铺',
|
||||
owner_id: '负责人编号',
|
||||
account_id: '内部账号编号',
|
||||
accountId: '内部账号编号',
|
||||
account_username: '斗鱼账号',
|
||||
accountName: '账号名称',
|
||||
account_uid: '斗鱼用户编号',
|
||||
account_nickname: '账号昵称',
|
||||
gift_name: '礼包',
|
||||
commodity_id: '商品编号',
|
||||
required_points: '所需积分',
|
||||
requiredPoints: '所需积分',
|
||||
home_images: '主页截图',
|
||||
bind_game_role: '绑定角色',
|
||||
role: '当前角色',
|
||||
ck_status: '登录凭据状态',
|
||||
ck: '登录凭据状态',
|
||||
fish_fin_balance: '鱼翅',
|
||||
points: '积分',
|
||||
points_balance: '当前积分',
|
||||
required_total: '同账号所需积分',
|
||||
surplus: '积分结余',
|
||||
message: '说明',
|
||||
scope: '查询范围',
|
||||
verdict: '查询判定',
|
||||
records: '兑换记录',
|
||||
records_matched: '命中记录',
|
||||
records_total: '记录总数',
|
||||
from: '原状态',
|
||||
to: '新状态',
|
||||
status: '状态',
|
||||
rollback: '是否回退',
|
||||
reason: '原因',
|
||||
taskId: '履约任务编号',
|
||||
created: '是否新建',
|
||||
released_lease: '是否释放账号占用',
|
||||
previous: '原账号信息',
|
||||
lease_id: '账号占用编号',
|
||||
purpose: '占用用途',
|
||||
batch_id: '批次编号',
|
||||
draft: '是否草稿',
|
||||
exchangeStatus: '兑换资格',
|
||||
softReasons: '后续处理',
|
||||
eliteOpened: '精英宝典已开通',
|
||||
limited: '是否达到限兑上限',
|
||||
limitedCount: '限兑商品数量',
|
||||
};
|
||||
|
||||
const COLLAB_DETAIL_VALUE_LABELS: Record<string, string> = {
|
||||
valid: '正常',
|
||||
invalid: '异常',
|
||||
error: '异常',
|
||||
unverified: '未检测',
|
||||
unknown: '无法判定',
|
||||
success: '成功',
|
||||
failed: '失败',
|
||||
incomplete: '待补资料',
|
||||
to_recharge: '待充值',
|
||||
recharged: '已充值',
|
||||
scripted: '已上脚本',
|
||||
done: '抢购成功',
|
||||
points_error: '积分异常',
|
||||
role_error: '账号角色异常',
|
||||
void: '已作废',
|
||||
allocated: '已分配',
|
||||
bound: '已绑定',
|
||||
ready: '待分配',
|
||||
manual_required: '已转人工',
|
||||
eligible: '资格正常',
|
||||
points_short: '积分不足',
|
||||
not_opened: '精英宝典未开通',
|
||||
activity: '兑换记录',
|
||||
balances: '鱼翅与积分',
|
||||
balance_manual: '人工查询鱼翅与积分',
|
||||
balance_batch: '批量查询鱼翅与积分',
|
||||
batch: '批量查询',
|
||||
platform_fulfillment: '直播账号履约',
|
||||
douyu_collab: '外部单协作',
|
||||
};
|
||||
|
||||
const COLLAB_DETAIL_PREFERRED_KEYS = Object.keys(COLLAB_DETAIL_LABELS);
|
||||
|
||||
function collabActionLabel(action: string): string {
|
||||
return COLLAB_ACTION_LABELS[action] || '其他操作';
|
||||
}
|
||||
|
||||
function collabCkLabel(status: string): string {
|
||||
if (status === 'valid') return '正常';
|
||||
if (status === 'invalid' || status === 'error') return '异常';
|
||||
return '未检测';
|
||||
}
|
||||
|
||||
function collabValueLabel(value: unknown): string {
|
||||
if (typeof value === 'boolean') return value ? '是' : '否';
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
if (typeof value === 'number') return String(value);
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => collabValueLabel(item)).filter((item) => item !== '-').join('、') || '-';
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
const row = value as Record<string, unknown>;
|
||||
if ('old' in row || 'new' in row) {
|
||||
return `${collabValueLabel(row.old)} → ${collabValueLabel(row.new)}`;
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
const text = String(value);
|
||||
return COLLAB_DETAIL_VALUE_LABELS[text] || collabText(text);
|
||||
}
|
||||
|
||||
function collabText(value: string): string {
|
||||
return value
|
||||
.replace(/\bCookie\b/gi, '登录凭据')
|
||||
.replace(/\bCK\b/gi, '登录凭据')
|
||||
.replace(/\s*act=[^,,;;\s]+/gi, '')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function collabTimelineDetailLines(detail: string): string[] {
|
||||
if (!detail) return [];
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(detail);
|
||||
} catch {
|
||||
return ['明细格式无法识别'];
|
||||
}
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
return [collabValueLabel(parsed)];
|
||||
}
|
||||
const data = parsed as Record<string, unknown>;
|
||||
const lines: string[] = [];
|
||||
for (const key of COLLAB_DETAIL_PREFERRED_KEYS) {
|
||||
if (!(key in data)) continue;
|
||||
const value = data[key];
|
||||
if (key === 'previous' && value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
const previous = value as Record<string, unknown>;
|
||||
const parts = [
|
||||
previous.account_username ? `账号 ${collabValueLabel(previous.account_username)}` : '',
|
||||
previous.bind_game_role ? `角色 ${collabValueLabel(previous.bind_game_role)}` : '',
|
||||
previous.status ? `状态 ${collabValueLabel(previous.status)}` : '',
|
||||
].filter(Boolean);
|
||||
if (parts.length) lines.push(`${COLLAB_DETAIL_LABELS[key]}:${parts.join(';')}`);
|
||||
continue;
|
||||
}
|
||||
if (key === 'ck_status' || key === 'ck') {
|
||||
lines.push(`${COLLAB_DETAIL_LABELS[key]}:${collabCkLabel(String(value || ''))}`);
|
||||
continue;
|
||||
}
|
||||
if (key === 'home_images') {
|
||||
const count = Array.isArray(value) ? value.length : Number(value || 0);
|
||||
lines.push(`${COLLAB_DETAIL_LABELS[key]}:${Number.isFinite(count) ? count : 0} 张`);
|
||||
continue;
|
||||
}
|
||||
const text = collabValueLabel(value);
|
||||
if (text !== '-') lines.push(`${COLLAB_DETAIL_LABELS[key]}:${text}`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
function formatTime(value?: string | null): string {
|
||||
if (!value) return '-';
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||||
}
|
||||
|
||||
function pointsReasonMeta(reason: string): { label: string; color: string } {
|
||||
if (reason === 'shortage') return { label: '积分不足', color: 'red' };
|
||||
if (reason === 'excess') return { label: '积分超阈值', color: 'orange' };
|
||||
if (reason === 'ok') return { label: '积分正常', color: 'green' };
|
||||
return { label: '未核账', color: 'default' };
|
||||
}
|
||||
|
||||
function goodsOptions(goods: DouyuCollabGoods[], accountSpecific = false) {
|
||||
return goods
|
||||
.filter((item) => item.commodity_id && item.name)
|
||||
.map((item) => {
|
||||
const time = item.is_limited ? ' · 23返场/限时' : '';
|
||||
const accountState =
|
||||
accountSpecific && item.status === '1'
|
||||
? ' · 该账号已兑换'
|
||||
: item.open_status === 0
|
||||
? ' · 未开始'
|
||||
: '';
|
||||
return {
|
||||
value: item.commodity_id,
|
||||
label: `${item.name} · ${item.score ?? '-'} 积分${time}${accountState}`,
|
||||
goods: item,
|
||||
disabled: accountSpecific && item.status === '1',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
interface OrderFormState {
|
||||
order_no: string;
|
||||
shop: string;
|
||||
owner_id: number | null;
|
||||
account_username: string;
|
||||
gift_name: string;
|
||||
commodity_id: string;
|
||||
required_points: number | null;
|
||||
home_images: string[];
|
||||
remark: string;
|
||||
}
|
||||
|
||||
const EMPTY_FORM: OrderFormState = {
|
||||
order_no: '',
|
||||
shop: '',
|
||||
owner_id: null,
|
||||
account_username: '',
|
||||
gift_name: '',
|
||||
commodity_id: '',
|
||||
required_points: null,
|
||||
home_images: [],
|
||||
remark: '',
|
||||
};
|
||||
|
||||
const SUCCESS_PURCHASE_FIELD_LABELS: Record<string, string> = {
|
||||
order_no: '订单编号',
|
||||
account_username: '斗鱼用户名',
|
||||
gift_name: '礼包',
|
||||
commodity_id: '商品编号',
|
||||
required_points: '所需积分',
|
||||
};
|
||||
|
||||
interface SuccessfulPurchaseChange {
|
||||
field: string;
|
||||
label: string;
|
||||
before: string;
|
||||
after: string;
|
||||
}
|
||||
|
||||
function successfulPurchaseChanges(
|
||||
order: DouyuCollabOrder,
|
||||
form: OrderFormState,
|
||||
): SuccessfulPurchaseChange[] {
|
||||
const pairs: Array<[string, string | number | null, string | number | null]> = [
|
||||
['order_no', order.order_no, form.order_no.trim()],
|
||||
['account_username', order.account_username, form.account_username.trim()],
|
||||
['gift_name', order.gift_name, form.gift_name.trim()],
|
||||
['commodity_id', order.commodity_id, form.commodity_id.trim()],
|
||||
['required_points', order.required_points, form.required_points],
|
||||
];
|
||||
return pairs
|
||||
.filter(([, before, after]) => (before ?? '') !== (after ?? ''))
|
||||
.map(([field, before, after]) => ({
|
||||
field,
|
||||
label: SUCCESS_PURCHASE_FIELD_LABELS[field] || field,
|
||||
before: before == null || before === '' ? '未填写' : String(before),
|
||||
after: after == null || after === '' ? '未填写' : String(after),
|
||||
}));
|
||||
}
|
||||
|
||||
export default function DouyuCollabPage() {
|
||||
const navigate = useNavigate();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
import type {
|
||||
DouyuCollabGoods,
|
||||
DouyuCollabOrder,
|
||||
DouyuCollabStatus,
|
||||
} from '../api/douyuCollab';
|
||||
|
||||
export function errorCodeOf(error: unknown): string {
|
||||
return (error as { errorCode?: string } | null)?.errorCode || '';
|
||||
}
|
||||
|
||||
export function hasTextInputFocus(): boolean {
|
||||
const active = document.activeElement;
|
||||
return (
|
||||
active instanceof HTMLElement &&
|
||||
(active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable)
|
||||
);
|
||||
}
|
||||
|
||||
/** 实时同步暂停开关按浏览器记住:刷新页面后仍保持暂停,直到手动恢复。 */
|
||||
export const REALTIME_PAUSED_STORAGE_KEY = 'douyu.collab.realtime-paused';
|
||||
export const REALTIME_WS_PATH = '/api/douyu/external-orders/ws';
|
||||
export const COLUMN_LAYOUT_STORAGE_PREFIX = 'douyu.collab.columns';
|
||||
|
||||
export 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;
|
||||
|
||||
export const COLUMN_LABELS: Record<string, string> = {
|
||||
sequence: '序号',
|
||||
order_shop: '订单 / 店铺',
|
||||
owner: '负责人',
|
||||
account: '斗鱼账号',
|
||||
bind_role: '绑定角色',
|
||||
home_images: '主页截图',
|
||||
gift: '礼包 / 积分',
|
||||
status: '状态',
|
||||
balances: '鱼翅 / 积分',
|
||||
last_query: '最近查询',
|
||||
updated: '最后改动',
|
||||
actions: '操作',
|
||||
};
|
||||
|
||||
export type ColumnPreference = { key: string; visible: boolean };
|
||||
|
||||
export 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;
|
||||
}
|
||||
|
||||
export 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);
|
||||
}
|
||||
}
|
||||
|
||||
export function readRealtimePaused(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(REALTIME_PAUSED_STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function cardStyle(active: boolean) {
|
||||
return {
|
||||
borderColor: active ? '#1677ff' : undefined,
|
||||
cursor: 'pointer',
|
||||
} as const;
|
||||
}
|
||||
|
||||
export const STATUS_META: Record<DouyuCollabStatus, { label: string; color: string }> = {
|
||||
incomplete: { label: '待补资料', color: 'default' },
|
||||
to_recharge: { label: '待充值', color: 'blue' },
|
||||
recharged: { label: '已充值', color: 'cyan' },
|
||||
scripted: { label: '已上脚本', color: 'purple' },
|
||||
done: { label: '抢购成功', color: 'green' },
|
||||
points_error: { label: '积分异常', color: 'orange' },
|
||||
role_error: { label: '账号角色异常', color: 'volcano' },
|
||||
failed: { label: '抢购失败', color: 'red' },
|
||||
void: { label: '已作废', color: 'default' },
|
||||
};
|
||||
|
||||
export const STATUS_ORDER: DouyuCollabStatus[] = [
|
||||
'incomplete',
|
||||
'to_recharge',
|
||||
'recharged',
|
||||
'scripted',
|
||||
'done',
|
||||
'points_error',
|
||||
'role_error',
|
||||
'failed',
|
||||
'void',
|
||||
];
|
||||
|
||||
export const FLOW_ORDER: DouyuCollabStatus[] = [
|
||||
'incomplete',
|
||||
'to_recharge',
|
||||
'recharged',
|
||||
'scripted',
|
||||
'done',
|
||||
];
|
||||
|
||||
export const CK_META: Record<string, { label: string; color: string }> = {
|
||||
unverified: { label: '未检测', color: 'default' },
|
||||
valid: { label: 'CK 正常', color: 'green' },
|
||||
invalid: { label: 'CK 异常', color: 'red' },
|
||||
error: { label: 'CK 异常', color: 'red' },
|
||||
'': { label: '未检测', color: 'default' },
|
||||
};
|
||||
|
||||
export const COLLAB_ACTION_LABELS: Record<string, string> = {
|
||||
'douyu:collab:create': '新建协作单',
|
||||
'douyu:collab:update': '编辑订单资料',
|
||||
'douyu:collab:account': '更换账号',
|
||||
'douyu:collab:account_unlink': '解除账号关联',
|
||||
'douyu:collab:verify': '校验账号',
|
||||
'douyu:collab:status': '修改订单状态',
|
||||
'douyu:collab:status_auto': '自动推进订单状态',
|
||||
'douyu:collab:void': '作废订单',
|
||||
'douyu:collab:void_restore': '恢复作废订单',
|
||||
'douyu:collab:points_error': '标记积分异常',
|
||||
'douyu:collab:role_error': '标记角色异常',
|
||||
'douyu:collab:activity': '查询兑换记录',
|
||||
'douyu:collab:ck_export': '导出账号与登录凭据',
|
||||
'douyu:collab:archive': '归档订单',
|
||||
'douyu:collab:unarchive': '取消归档',
|
||||
'douyu:collab:sync_from_platform_fulfillment': '同步直播履约单',
|
||||
'douyu:collab:lease_acquired': '建立账号占用',
|
||||
'douyu:collab:lease_released': '释放账号占用',
|
||||
'douyu:collab:lease_takeover': '接管账号占用',
|
||||
'douyu:collab:goods_refresh': '刷新活动商品',
|
||||
'douyu:collab:shop_update': '修改店铺',
|
||||
'douyu:collab:shop_delete': '删除店铺',
|
||||
'douyu:collab:gift_update': '修改礼包',
|
||||
'douyu:collab:gift_delete': '删除礼包',
|
||||
};
|
||||
|
||||
export const COLLAB_DETAIL_LABELS: Record<string, string> = {
|
||||
order_no: '订单编号',
|
||||
orderNo: '平台订单编号',
|
||||
shop: '店铺',
|
||||
owner_id: '负责人编号',
|
||||
account_id: '内部账号编号',
|
||||
accountId: '内部账号编号',
|
||||
account_username: '斗鱼账号',
|
||||
accountName: '账号名称',
|
||||
account_uid: '斗鱼用户编号',
|
||||
account_nickname: '账号昵称',
|
||||
gift_name: '礼包',
|
||||
commodity_id: '商品编号',
|
||||
required_points: '所需积分',
|
||||
requiredPoints: '所需积分',
|
||||
home_images: '主页截图',
|
||||
bind_game_role: '绑定角色',
|
||||
role: '当前角色',
|
||||
ck_status: '登录凭据状态',
|
||||
ck: '登录凭据状态',
|
||||
fish_fin_balance: '鱼翅',
|
||||
points: '积分',
|
||||
points_balance: '当前积分',
|
||||
required_total: '同账号所需积分',
|
||||
surplus: '积分结余',
|
||||
message: '说明',
|
||||
scope: '查询范围',
|
||||
verdict: '查询判定',
|
||||
records: '兑换记录',
|
||||
records_matched: '命中记录',
|
||||
records_total: '记录总数',
|
||||
from: '原状态',
|
||||
to: '新状态',
|
||||
status: '状态',
|
||||
rollback: '是否回退',
|
||||
reason: '原因',
|
||||
taskId: '履约任务编号',
|
||||
created: '是否新建',
|
||||
released_lease: '是否释放账号占用',
|
||||
previous: '原账号信息',
|
||||
lease_id: '账号占用编号',
|
||||
purpose: '占用用途',
|
||||
batch_id: '批次编号',
|
||||
draft: '是否草稿',
|
||||
exchangeStatus: '兑换资格',
|
||||
softReasons: '后续处理',
|
||||
eliteOpened: '精英宝典已开通',
|
||||
limited: '是否达到限兑上限',
|
||||
limitedCount: '限兑商品数量',
|
||||
};
|
||||
|
||||
export const COLLAB_DETAIL_VALUE_LABELS: Record<string, string> = {
|
||||
valid: '正常',
|
||||
invalid: '异常',
|
||||
error: '异常',
|
||||
unverified: '未检测',
|
||||
unknown: '无法判定',
|
||||
success: '成功',
|
||||
failed: '失败',
|
||||
incomplete: '待补资料',
|
||||
to_recharge: '待充值',
|
||||
recharged: '已充值',
|
||||
scripted: '已上脚本',
|
||||
done: '抢购成功',
|
||||
points_error: '积分异常',
|
||||
role_error: '账号角色异常',
|
||||
void: '已作废',
|
||||
allocated: '已分配',
|
||||
bound: '已绑定',
|
||||
ready: '待分配',
|
||||
manual_required: '已转人工',
|
||||
eligible: '资格正常',
|
||||
points_short: '积分不足',
|
||||
not_opened: '精英宝典未开通',
|
||||
activity: '兑换记录',
|
||||
balances: '鱼翅与积分',
|
||||
balance_manual: '人工查询鱼翅与积分',
|
||||
balance_batch: '批量查询鱼翅与积分',
|
||||
batch: '批量查询',
|
||||
platform_fulfillment: '直播账号履约',
|
||||
douyu_collab: '外部单协作',
|
||||
};
|
||||
|
||||
export const COLLAB_DETAIL_PREFERRED_KEYS = Object.keys(COLLAB_DETAIL_LABELS);
|
||||
|
||||
export function collabActionLabel(action: string): string {
|
||||
return COLLAB_ACTION_LABELS[action] || '其他操作';
|
||||
}
|
||||
|
||||
export function collabCkLabel(status: string): string {
|
||||
if (status === 'valid') return '正常';
|
||||
if (status === 'invalid' || status === 'error') return '异常';
|
||||
return '未检测';
|
||||
}
|
||||
|
||||
export function collabValueLabel(value: unknown): string {
|
||||
if (typeof value === 'boolean') return value ? '是' : '否';
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
if (typeof value === 'number') return String(value);
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => collabValueLabel(item)).filter((item) => item !== '-').join('、') || '-';
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
const row = value as Record<string, unknown>;
|
||||
if ('old' in row || 'new' in row) {
|
||||
return `${collabValueLabel(row.old)} → ${collabValueLabel(row.new)}`;
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
const text = String(value);
|
||||
return COLLAB_DETAIL_VALUE_LABELS[text] || collabText(text);
|
||||
}
|
||||
|
||||
export function collabText(value: string): string {
|
||||
return value
|
||||
.replace(/\bCookie\b/gi, '登录凭据')
|
||||
.replace(/\bCK\b/gi, '登录凭据')
|
||||
.replace(/\s*act=[^,,;;\s]+/gi, '')
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function collabTimelineDetailLines(detail: string): string[] {
|
||||
if (!detail) return [];
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(detail);
|
||||
} catch {
|
||||
return ['明细格式无法识别'];
|
||||
}
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
return [collabValueLabel(parsed)];
|
||||
}
|
||||
const data = parsed as Record<string, unknown>;
|
||||
const lines: string[] = [];
|
||||
for (const key of COLLAB_DETAIL_PREFERRED_KEYS) {
|
||||
if (!(key in data)) continue;
|
||||
const value = data[key];
|
||||
if (key === 'previous' && value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
const previous = value as Record<string, unknown>;
|
||||
const parts = [
|
||||
previous.account_username ? `账号 ${collabValueLabel(previous.account_username)}` : '',
|
||||
previous.bind_game_role ? `角色 ${collabValueLabel(previous.bind_game_role)}` : '',
|
||||
previous.status ? `状态 ${collabValueLabel(previous.status)}` : '',
|
||||
].filter(Boolean);
|
||||
if (parts.length) lines.push(`${COLLAB_DETAIL_LABELS[key]}:${parts.join(';')}`);
|
||||
continue;
|
||||
}
|
||||
if (key === 'ck_status' || key === 'ck') {
|
||||
lines.push(`${COLLAB_DETAIL_LABELS[key]}:${collabCkLabel(String(value || ''))}`);
|
||||
continue;
|
||||
}
|
||||
if (key === 'home_images') {
|
||||
const count = Array.isArray(value) ? value.length : Number(value || 0);
|
||||
lines.push(`${COLLAB_DETAIL_LABELS[key]}:${Number.isFinite(count) ? count : 0} 张`);
|
||||
continue;
|
||||
}
|
||||
const text = collabValueLabel(value);
|
||||
if (text !== '-') lines.push(`${COLLAB_DETAIL_LABELS[key]}:${text}`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
export function formatTime(value?: string | null): string {
|
||||
if (!value) return '-';
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
||||
}
|
||||
|
||||
export function pointsReasonMeta(reason: string): { label: string; color: string } {
|
||||
if (reason === 'shortage') return { label: '积分不足', color: 'red' };
|
||||
if (reason === 'excess') return { label: '积分超阈值', color: 'orange' };
|
||||
if (reason === 'ok') return { label: '积分正常', color: 'green' };
|
||||
return { label: '未核账', color: 'default' };
|
||||
}
|
||||
|
||||
export function goodsOptions(goods: DouyuCollabGoods[], accountSpecific = false) {
|
||||
return goods
|
||||
.filter((item) => item.commodity_id && item.name)
|
||||
.map((item) => {
|
||||
const time = item.is_limited ? ' · 23返场/限时' : '';
|
||||
const accountState =
|
||||
accountSpecific && item.status === '1'
|
||||
? ' · 该账号已兑换'
|
||||
: item.open_status === 0
|
||||
? ' · 未开始'
|
||||
: '';
|
||||
return {
|
||||
value: item.commodity_id,
|
||||
label: `${item.name} · ${item.score ?? '-'} 积分${time}${accountState}`,
|
||||
goods: item,
|
||||
disabled: accountSpecific && item.status === '1',
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export interface OrderFormState {
|
||||
order_no: string;
|
||||
shop: string;
|
||||
owner_id: number | null;
|
||||
account_username: string;
|
||||
gift_name: string;
|
||||
commodity_id: string;
|
||||
required_points: number | null;
|
||||
home_images: string[];
|
||||
remark: string;
|
||||
}
|
||||
|
||||
export const EMPTY_FORM: OrderFormState = {
|
||||
order_no: '',
|
||||
shop: '',
|
||||
owner_id: null,
|
||||
account_username: '',
|
||||
gift_name: '',
|
||||
commodity_id: '',
|
||||
required_points: null,
|
||||
home_images: [],
|
||||
remark: '',
|
||||
};
|
||||
|
||||
export const SUCCESS_PURCHASE_FIELD_LABELS: Record<string, string> = {
|
||||
order_no: '订单编号',
|
||||
account_username: '斗鱼用户名',
|
||||
gift_name: '礼包',
|
||||
commodity_id: '商品编号',
|
||||
required_points: '所需积分',
|
||||
};
|
||||
|
||||
export interface SuccessfulPurchaseChange {
|
||||
field: string;
|
||||
label: string;
|
||||
before: string;
|
||||
after: string;
|
||||
}
|
||||
|
||||
export function successfulPurchaseChanges(
|
||||
order: DouyuCollabOrder,
|
||||
form: OrderFormState,
|
||||
): SuccessfulPurchaseChange[] {
|
||||
const pairs: Array<[string, string | number | null, string | number | null]> = [
|
||||
['order_no', order.order_no, form.order_no.trim()],
|
||||
['account_username', order.account_username, form.account_username.trim()],
|
||||
['gift_name', order.gift_name, form.gift_name.trim()],
|
||||
['commodity_id', order.commodity_id, form.commodity_id.trim()],
|
||||
['required_points', order.required_points, form.required_points],
|
||||
];
|
||||
return pairs
|
||||
.filter(([, before, after]) => (before ?? '') !== (after ?? ''))
|
||||
.map(([field, before, after]) => ({
|
||||
field,
|
||||
label: SUCCESS_PURCHASE_FIELD_LABELS[field] || field,
|
||||
before: before == null || before === '' ? '未填写' : String(before),
|
||||
after: after == null || after === '' ? '未填写' : String(after),
|
||||
}));
|
||||
}
|
||||
@@ -50,326 +50,42 @@ import { getErrorMessage } from '../utils/error';
|
||||
import { copyTextToClipboard } from '../utils/clipboard';
|
||||
import { usePermissions } from '../hooks/usePermissions';
|
||||
import { useCollabRealtime, type CollabRealtimeEvent } from '../hooks/useCollabRealtime';
|
||||
import {
|
||||
ACTION_LABELS,
|
||||
CK_META,
|
||||
COLLAB_SORT_KEYS,
|
||||
FLOW_STATUS_OPTIONS,
|
||||
IMPORT_PREVIEW_ROWS,
|
||||
MAX_IMAGES_PER_SLOT,
|
||||
RECHARGE_THRESHOLD_KEY,
|
||||
REALTIME_PAUSED_STORAGE_KEY,
|
||||
SLOT_META,
|
||||
STATUS_META,
|
||||
STATUS_ORDER_OPTIONS,
|
||||
VERDICT_META,
|
||||
clearCreateDraft,
|
||||
clearSupplementDraft,
|
||||
createDraftKey,
|
||||
draftHintShown,
|
||||
formatTime,
|
||||
hasDraftContent,
|
||||
hasTextInputFocus,
|
||||
markDraftHintShown,
|
||||
readCreateDraft,
|
||||
readGiftCache,
|
||||
readRealtimePaused,
|
||||
readRechargeThreshold,
|
||||
readSupplementDraft,
|
||||
supplementDraftKey,
|
||||
writeGiftCache,
|
||||
type CollabSortKey,
|
||||
type CollabSortOrder,
|
||||
type SupplementDraft,
|
||||
type SupplementFormValues,
|
||||
} from './HuyaCollabPageConfig';
|
||||
|
||||
const { Text, Paragraph } = Typography;
|
||||
|
||||
function hasTextInputFocus(): boolean {
|
||||
const active = document.activeElement;
|
||||
return (
|
||||
active instanceof HTMLElement &&
|
||||
(active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable)
|
||||
);
|
||||
}
|
||||
|
||||
/** 实时同步暂停开关按浏览器记住:刷新页面后仍保持暂停,直到用户手动恢复。 */
|
||||
const REALTIME_PAUSED_STORAGE_KEY = 'huya.collab.realtime-paused';
|
||||
|
||||
function readRealtimePaused(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(REALTIME_PAUSED_STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const STATUS_META: Record<HuyaCollabStatus, { label: string; color: string }> = {
|
||||
// 只登记了订单号 + 店铺,客户资料(CK / 礼包 / 主页截图)到了再补
|
||||
incomplete: { label: '待补资料', color: 'gold' },
|
||||
// 资料齐全且 CK 有效;等充值
|
||||
to_recharge: { label: '待充值', color: 'orange' },
|
||||
recharged: { label: '已充值', color: 'geekblue' },
|
||||
scripted: { label: '已上脚本', color: 'purple' },
|
||||
// 抢购成功(枚举值仍是 done):从「已上脚本」查到兑换记录 → 自动进这一步
|
||||
done: { label: '抢购成功', color: 'success' },
|
||||
// 充值完成但积分不足/超出阈值
|
||||
points_error: { label: '积分异常', color: 'volcano' },
|
||||
// 旁路终态:抢购后查兑换记录没查到这一单的礼包(枚举值仍是 failed)
|
||||
failed: { label: '抢购失败', color: 'red' },
|
||||
void: { label: '已作废', color: 'error' },
|
||||
};
|
||||
|
||||
/** 判定结论的配色(生命周期时间线用):与「业务状态名」分开,这里说的是"兑换记录里查到没有" */
|
||||
const VERDICT_META: Record<string, { label: string; color: string }> = {
|
||||
success: { label: '兑换成功', color: 'success' },
|
||||
failed: { label: '兑换失败', color: 'error' },
|
||||
unknown: { label: '无法判定', color: 'default' },
|
||||
};
|
||||
|
||||
/** 「改状态」能选的目标(顺序 = 业务流程顺序,回退要显式勾选)
|
||||
* 「待补资料」只作为新建起点,不放进「改状态」:它只能通过「回退状态」进入。 */
|
||||
const STATUS_ORDER_OPTIONS: { value: HuyaCollabStatus; label: string }[] = [
|
||||
{ value: 'to_recharge', label: '待充值' },
|
||||
{ value: 'recharged', label: '已充值(核账)' },
|
||||
{ value: 'scripted', label: '已上脚本' },
|
||||
{ value: 'done', label: '抢购成功' },
|
||||
{ value: 'failed', label: '抢购失败' },
|
||||
{ value: 'void', label: '已作废' },
|
||||
];
|
||||
|
||||
/** 「回退」能选的目标:流程链(含「待补资料」;要进「已作废 / 抢购失败」走「改状态」或「作废」入口) */
|
||||
const FLOW_STATUS_OPTIONS: { value: HuyaCollabStatus; label: string }[] = [
|
||||
{ value: 'incomplete', label: '待补资料' },
|
||||
{ value: 'to_recharge', label: '待充值' },
|
||||
{ value: 'recharged', label: '已充值(核账)' },
|
||||
{ value: 'scripted', label: '已上脚本' },
|
||||
{ value: 'done', label: '抢购成功' },
|
||||
];
|
||||
|
||||
const CK_META: Record<string, { label: string; color: string }> = {
|
||||
unverified: { label: '未验证', color: 'default' },
|
||||
valid: { label: '有效', color: 'success' },
|
||||
invalid: { label: '已失效', color: 'error' },
|
||||
disabled: { label: '已停用', color: 'warning' },
|
||||
};
|
||||
|
||||
/** 表头排序字段(后端白名单):seq = 固定创建序号;点击一次正序,再点一次反序。 */
|
||||
type CollabSortKey =
|
||||
| 'seq'
|
||||
| 'order_no'
|
||||
| 'shop'
|
||||
| 'owner'
|
||||
| 'bind'
|
||||
| 'gift_name'
|
||||
| 'status'
|
||||
| 'uid'
|
||||
| 'ck_status'
|
||||
| 'updated_at';
|
||||
type CollabSortOrder = 'ascend' | 'descend';
|
||||
const COLLAB_SORT_KEYS: ReadonlySet<string> = new Set<CollabSortKey>([
|
||||
'seq',
|
||||
'order_no',
|
||||
'shop',
|
||||
'owner',
|
||||
'bind',
|
||||
'gift_name',
|
||||
'status',
|
||||
'uid',
|
||||
'ck_status',
|
||||
'updated_at',
|
||||
]);
|
||||
|
||||
const ACTION_LABELS: Record<string, string> = {
|
||||
'huya:collab:create': '新建',
|
||||
'huya:collab:update': '编辑',
|
||||
'huya:collab:status': '状态变更',
|
||||
'huya:collab:ck': 'CK 变更',
|
||||
'huya:collab:ck_status': 'CK 验证',
|
||||
'huya:collab:probe_snapshot': '绑定快照刷新',
|
||||
'huya:collab:recharge_invalidate': '核账快照失效',
|
||||
'huya:collab:image': '图片变更',
|
||||
'huya:collab:delete': '删除',
|
||||
};
|
||||
|
||||
const SLOT_META: Record<HuyaCollabImageSlot, { label: string; keysKey: 'bind_images' | 'home_images' }> = {
|
||||
// 绑定图不再人工上传:绑定关系由探针自动读(2026-10-16 用户拍板),只留老数据只读展示
|
||||
bind_images: { label: '历史绑定图', keysKey: 'bind_images' },
|
||||
home_images: { label: '主页截图', keysKey: 'home_images' },
|
||||
};
|
||||
|
||||
const IMPORT_PREVIEW_ROWS = 20;
|
||||
// 「礼包列表」的本地缓存键:一个活动期间就那一批礼包,没必要每贴一份 CK 都去虎牙拉一次;
|
||||
// v3 = 2026-11-11 起自动合并积分中心全部页签,换键避免继续用只含「精英专享」的旧缓存。
|
||||
const GIFTS_CACHE_KEY = 'huya.collab.gifts.v3';
|
||||
const RECHARGE_THRESHOLD_KEY = 'huya.collab.rechargeThreshold';
|
||||
const RECHARGE_THRESHOLD_DEFAULT = 100;
|
||||
|
||||
function readRechargeThreshold(): number {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(RECHARGE_THRESHOLD_KEY);
|
||||
if (raw === null || raw === '') return RECHARGE_THRESHOLD_DEFAULT;
|
||||
const value = Number(raw);
|
||||
return Number.isFinite(value) && value >= 0 ? value : RECHARGE_THRESHOLD_DEFAULT;
|
||||
} catch {
|
||||
return RECHARGE_THRESHOLD_DEFAULT;
|
||||
}
|
||||
}
|
||||
const MAX_IMAGES_PER_SLOT = 20;
|
||||
|
||||
/** 读礼包缓存(读不到 / 解析坏 / 空列表都当没缓存) */
|
||||
function readGiftCache(): { gifts: HuyaCollabGift[]; at: number } | null {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(GIFTS_CACHE_KEY);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as { at?: number; gifts?: HuyaCollabGift[] };
|
||||
const gifts = Array.isArray(parsed.gifts) ? parsed.gifts : [];
|
||||
if (gifts.length === 0) return null;
|
||||
return { gifts, at: Number(parsed.at) || 0 };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 写礼包缓存:写不进去(隐私模式 / 配额满)也不影响功能,静静跳过 */
|
||||
function writeGiftCache(gifts: HuyaCollabGift[]): void {
|
||||
try {
|
||||
window.localStorage.setItem(GIFTS_CACHE_KEY, JSON.stringify({ at: Date.now(), gifts }));
|
||||
} catch {
|
||||
// 忽略:缓存只是体验优化
|
||||
}
|
||||
}
|
||||
|
||||
// 「新建协作单」草稿:填一半关掉 / 刷新页面后再打开不能清空(2026-10-17 用户需求)。
|
||||
// 按登录用户分键,避免同一台电脑换账号后看到上一个人的 CK。
|
||||
const CREATE_DRAFT_KEY_PREFIX = 'huya.collab.createDraft';
|
||||
// 「只填订单号 + 店铺直接建单」的首次提示只弹一次(按浏览器记,不再打扰)
|
||||
const CREATE_DRAFT_HINT_KEY = 'huya.collab.draftHintShown';
|
||||
|
||||
interface CreateDraft {
|
||||
order_no: string;
|
||||
shop: string;
|
||||
ck_text: string;
|
||||
gift_name: string;
|
||||
required_points: number | null;
|
||||
remark: string;
|
||||
home_images: string[];
|
||||
saved_at: number;
|
||||
}
|
||||
|
||||
function createDraftKey(userId?: number | null): string {
|
||||
return userId ? `${CREATE_DRAFT_KEY_PREFIX}.${userId}` : '';
|
||||
}
|
||||
|
||||
/** 读草稿(读不到 / 解析坏都当没有) */
|
||||
function readCreateDraft(userId?: number | null): CreateDraft | null {
|
||||
const key = createDraftKey(userId);
|
||||
if (!key) return null;
|
||||
try {
|
||||
const raw = window.localStorage.getItem(key);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as Partial<CreateDraft>;
|
||||
const savedAt = Number(parsed.saved_at) || 0;
|
||||
// 草稿只留 7 天:里面可能有一份 CK,不能无限期躺在浏览器里
|
||||
if (!savedAt || Date.now() - savedAt > 7 * 24 * 60 * 60 * 1000) {
|
||||
window.localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
order_no: typeof parsed.order_no === 'string' ? parsed.order_no : '',
|
||||
shop: typeof parsed.shop === 'string' ? parsed.shop : '',
|
||||
ck_text: typeof parsed.ck_text === 'string' ? parsed.ck_text : '',
|
||||
gift_name: typeof parsed.gift_name === 'string' ? parsed.gift_name : '',
|
||||
required_points: typeof parsed.required_points === 'number' ? parsed.required_points : null,
|
||||
remark: typeof parsed.remark === 'string' ? parsed.remark : '',
|
||||
home_images: Array.isArray(parsed.home_images)
|
||||
? parsed.home_images.filter((item): item is string => typeof item === 'string')
|
||||
: [],
|
||||
saved_at: Number(parsed.saved_at) || 0,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function clearCreateDraft(userId?: number | null): void {
|
||||
const key = createDraftKey(userId);
|
||||
if (!key) return;
|
||||
try {
|
||||
window.localStorage.removeItem(key);
|
||||
} catch {
|
||||
// 忽略:清不掉也不影响当前表单
|
||||
}
|
||||
}
|
||||
|
||||
/** 「资料没填全时直接建单 → 待补资料」的首次提示是否已经展示过 */
|
||||
function draftHintShown(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(CREATE_DRAFT_HINT_KEY) === '1';
|
||||
} catch {
|
||||
return true; // 存不了就不要再反复弹
|
||||
}
|
||||
}
|
||||
|
||||
function markDraftHintShown(): void {
|
||||
try {
|
||||
window.localStorage.setItem(CREATE_DRAFT_HINT_KEY, '1');
|
||||
} catch {
|
||||
// 忽略:提示只是体验
|
||||
}
|
||||
}
|
||||
|
||||
function hasDraftContent(draft: Omit<CreateDraft, 'saved_at'>): boolean {
|
||||
// 礼包名不算「填过东西」:它现在默认空白、也不从草稿恢复(见下面 createForm 那段的说明),
|
||||
// 否则一份「只被上次自动填了礼包」的老草稿会一直弹「已恢复上次未提交的草稿」。
|
||||
return Boolean(
|
||||
draft.order_no.trim()
|
||||
|| draft.shop.trim()
|
||||
|| draft.ck_text.trim()
|
||||
|| draft.remark.trim()
|
||||
|| draft.home_images.length,
|
||||
);
|
||||
}
|
||||
|
||||
// 「补资料」草稿:按登录用户 + 订单 id 分开存。填一半关掉 / 刷新后,
|
||||
// 再点这一行的「补资料」会原样恢复(含刚贴的 CK 和刚上传的截图 key)。
|
||||
const SUPPLEMENT_DRAFT_KEY_PREFIX = 'huya.collab.supplementDraft';
|
||||
|
||||
interface SupplementDraft {
|
||||
shop: string;
|
||||
ck_text: string;
|
||||
gift_name: string;
|
||||
required_points: number | null;
|
||||
remark: string;
|
||||
home_images: string[];
|
||||
saved_at: number;
|
||||
}
|
||||
|
||||
interface SupplementFormValues {
|
||||
shop: string;
|
||||
ck_text?: string;
|
||||
gift_name?: string;
|
||||
required_points?: number | null;
|
||||
remark?: string;
|
||||
home_images?: string[];
|
||||
}
|
||||
|
||||
function supplementDraftKey(userId?: number | null, orderId?: number): string {
|
||||
return userId && orderId ? `${SUPPLEMENT_DRAFT_KEY_PREFIX}.${userId}.${orderId}` : '';
|
||||
}
|
||||
|
||||
function readSupplementDraft(userId: number | null | undefined, orderId: number): SupplementDraft | null {
|
||||
const key = supplementDraftKey(userId, orderId);
|
||||
if (!key) return null;
|
||||
try {
|
||||
const raw = window.localStorage.getItem(key);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as Partial<SupplementDraft>;
|
||||
const savedAt = Number(parsed.saved_at) || 0;
|
||||
if (!savedAt || Date.now() - savedAt > 7 * 24 * 60 * 60 * 1000) {
|
||||
window.localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
shop: typeof parsed.shop === 'string' ? parsed.shop : '',
|
||||
ck_text: typeof parsed.ck_text === 'string' ? parsed.ck_text : '',
|
||||
gift_name: typeof parsed.gift_name === 'string' ? parsed.gift_name : '',
|
||||
required_points: typeof parsed.required_points === 'number' ? parsed.required_points : null,
|
||||
remark: typeof parsed.remark === 'string' ? parsed.remark : '',
|
||||
home_images: Array.isArray(parsed.home_images)
|
||||
? parsed.home_images.filter((item): item is string => typeof item === 'string')
|
||||
: [],
|
||||
saved_at: savedAt,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function clearSupplementDraft(userId: number | null | undefined, orderId: number): void {
|
||||
const key = supplementDraftKey(userId, orderId);
|
||||
if (!key) return;
|
||||
try {
|
||||
window.localStorage.removeItem(key);
|
||||
} catch {
|
||||
// 忽略:清不掉也不影响当前表单
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(value: string | null | undefined): string {
|
||||
if (!value) return '-';
|
||||
const time = new Date(value);
|
||||
return Number.isNaN(time.getTime()) ? String(value) : time.toLocaleString();
|
||||
}
|
||||
|
||||
/** 点开即改、失焦提交(回车=失焦提交,Esc=放弃) */
|
||||
function EditableText({
|
||||
value, disabled, placeholder, onCommit,
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
import type {
|
||||
HuyaCollabGift,
|
||||
HuyaCollabImageSlot,
|
||||
HuyaCollabStatus,
|
||||
} from '../api/modules';
|
||||
|
||||
export function hasTextInputFocus(): boolean {
|
||||
const active = document.activeElement;
|
||||
return (
|
||||
active instanceof HTMLElement &&
|
||||
(active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable)
|
||||
);
|
||||
}
|
||||
|
||||
/** 实时同步暂停开关按浏览器记住:刷新页面后仍保持暂停,直到用户手动恢复。 */
|
||||
export const REALTIME_PAUSED_STORAGE_KEY = 'huya.collab.realtime-paused';
|
||||
|
||||
export function readRealtimePaused(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(REALTIME_PAUSED_STORAGE_KEY) === '1';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const STATUS_META: Record<HuyaCollabStatus, { label: string; color: string }> = {
|
||||
// 只登记了订单号 + 店铺,客户资料(CK / 礼包 / 主页截图)到了再补
|
||||
incomplete: { label: '待补资料', color: 'gold' },
|
||||
// 资料齐全且 CK 有效;等充值
|
||||
to_recharge: { label: '待充值', color: 'orange' },
|
||||
recharged: { label: '已充值', color: 'geekblue' },
|
||||
scripted: { label: '已上脚本', color: 'purple' },
|
||||
// 抢购成功(枚举值仍是 done):从「已上脚本」查到兑换记录 → 自动进这一步
|
||||
done: { label: '抢购成功', color: 'success' },
|
||||
// 充值完成但积分不足/超出阈值
|
||||
points_error: { label: '积分异常', color: 'volcano' },
|
||||
// 旁路终态:抢购后查兑换记录没查到这一单的礼包(枚举值仍是 failed)
|
||||
failed: { label: '抢购失败', color: 'red' },
|
||||
void: { label: '已作废', color: 'error' },
|
||||
};
|
||||
|
||||
/** 判定结论的配色(生命周期时间线用):与「业务状态名」分开,这里说的是"兑换记录里查到没有" */
|
||||
export const VERDICT_META: Record<string, { label: string; color: string }> = {
|
||||
success: { label: '兑换成功', color: 'success' },
|
||||
failed: { label: '兑换失败', color: 'error' },
|
||||
unknown: { label: '无法判定', color: 'default' },
|
||||
};
|
||||
|
||||
/** 「改状态」能选的目标(顺序 = 业务流程顺序,回退要显式勾选)
|
||||
* 「待补资料」只作为新建起点,不放进「改状态」:它只能通过「回退状态」进入。 */
|
||||
export const STATUS_ORDER_OPTIONS: { value: HuyaCollabStatus; label: string }[] = [
|
||||
{ value: 'to_recharge', label: '待充值' },
|
||||
{ value: 'recharged', label: '已充值(核账)' },
|
||||
{ value: 'scripted', label: '已上脚本' },
|
||||
{ value: 'done', label: '抢购成功' },
|
||||
{ value: 'failed', label: '抢购失败' },
|
||||
{ value: 'void', label: '已作废' },
|
||||
];
|
||||
|
||||
/** 「回退」能选的目标:流程链(含「待补资料」;要进「已作废 / 抢购失败」走「改状态」或「作废」入口) */
|
||||
export const FLOW_STATUS_OPTIONS: { value: HuyaCollabStatus; label: string }[] = [
|
||||
{ value: 'incomplete', label: '待补资料' },
|
||||
{ value: 'to_recharge', label: '待充值' },
|
||||
{ value: 'recharged', label: '已充值(核账)' },
|
||||
{ value: 'scripted', label: '已上脚本' },
|
||||
{ value: 'done', label: '抢购成功' },
|
||||
];
|
||||
|
||||
export const CK_META: Record<string, { label: string; color: string }> = {
|
||||
unverified: { label: '未验证', color: 'default' },
|
||||
valid: { label: '有效', color: 'success' },
|
||||
invalid: { label: '已失效', color: 'error' },
|
||||
disabled: { label: '已停用', color: 'warning' },
|
||||
};
|
||||
|
||||
/** 表头排序字段(后端白名单):seq = 固定创建序号;点击一次正序,再点一次反序。 */
|
||||
export type CollabSortKey =
|
||||
| 'seq'
|
||||
| 'order_no'
|
||||
| 'shop'
|
||||
| 'owner'
|
||||
| 'bind'
|
||||
| 'gift_name'
|
||||
| 'status'
|
||||
| 'uid'
|
||||
| 'ck_status'
|
||||
| 'updated_at';
|
||||
export type CollabSortOrder = 'ascend' | 'descend';
|
||||
export const COLLAB_SORT_KEYS: ReadonlySet<string> = new Set<CollabSortKey>([
|
||||
'seq',
|
||||
'order_no',
|
||||
'shop',
|
||||
'owner',
|
||||
'bind',
|
||||
'gift_name',
|
||||
'status',
|
||||
'uid',
|
||||
'ck_status',
|
||||
'updated_at',
|
||||
]);
|
||||
|
||||
export const ACTION_LABELS: Record<string, string> = {
|
||||
'huya:collab:create': '新建',
|
||||
'huya:collab:update': '编辑',
|
||||
'huya:collab:status': '状态变更',
|
||||
'huya:collab:ck': 'CK 变更',
|
||||
'huya:collab:ck_status': 'CK 验证',
|
||||
'huya:collab:probe_snapshot': '绑定快照刷新',
|
||||
'huya:collab:recharge_invalidate': '核账快照失效',
|
||||
'huya:collab:image': '图片变更',
|
||||
'huya:collab:delete': '删除',
|
||||
};
|
||||
|
||||
export const SLOT_META: Record<HuyaCollabImageSlot, { label: string; keysKey: 'bind_images' | 'home_images' }> = {
|
||||
// 绑定图不再人工上传:绑定关系由探针自动读(2026-10-16 用户拍板),只留老数据只读展示
|
||||
bind_images: { label: '历史绑定图', keysKey: 'bind_images' },
|
||||
home_images: { label: '主页截图', keysKey: 'home_images' },
|
||||
};
|
||||
|
||||
export const IMPORT_PREVIEW_ROWS = 20;
|
||||
// 「礼包列表」的本地缓存键:一个活动期间就那一批礼包,没必要每贴一份 CK 都去虎牙拉一次;
|
||||
// v3 = 2026-11-11 起自动合并积分中心全部页签,换键避免继续用只含「精英专享」的旧缓存。
|
||||
export const GIFTS_CACHE_KEY = 'huya.collab.gifts.v3';
|
||||
export const RECHARGE_THRESHOLD_KEY = 'huya.collab.rechargeThreshold';
|
||||
export const RECHARGE_THRESHOLD_DEFAULT = 100;
|
||||
|
||||
export function readRechargeThreshold(): number {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(RECHARGE_THRESHOLD_KEY);
|
||||
if (raw === null || raw === '') return RECHARGE_THRESHOLD_DEFAULT;
|
||||
const value = Number(raw);
|
||||
return Number.isFinite(value) && value >= 0 ? value : RECHARGE_THRESHOLD_DEFAULT;
|
||||
} catch {
|
||||
return RECHARGE_THRESHOLD_DEFAULT;
|
||||
}
|
||||
}
|
||||
export const MAX_IMAGES_PER_SLOT = 20;
|
||||
|
||||
/** 读礼包缓存(读不到 / 解析坏 / 空列表都当没缓存) */
|
||||
export function readGiftCache(): { gifts: HuyaCollabGift[]; at: number } | null {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(GIFTS_CACHE_KEY);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as { at?: number; gifts?: HuyaCollabGift[] };
|
||||
const gifts = Array.isArray(parsed.gifts) ? parsed.gifts : [];
|
||||
if (gifts.length === 0) return null;
|
||||
return { gifts, at: Number(parsed.at) || 0 };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 写礼包缓存:写不进去(隐私模式 / 配额满)也不影响功能,静静跳过 */
|
||||
export function writeGiftCache(gifts: HuyaCollabGift[]): void {
|
||||
try {
|
||||
window.localStorage.setItem(GIFTS_CACHE_KEY, JSON.stringify({ at: Date.now(), gifts }));
|
||||
} catch {
|
||||
// 忽略:缓存只是体验优化
|
||||
}
|
||||
}
|
||||
|
||||
// 「新建协作单」草稿:填一半关掉 / 刷新页面后再打开不能清空(2026-10-17 用户需求)。
|
||||
// 按登录用户分键,避免同一台电脑换账号后看到上一个人的 CK。
|
||||
export const CREATE_DRAFT_KEY_PREFIX = 'huya.collab.createDraft';
|
||||
// 「只填订单号 + 店铺直接建单」的首次提示只弹一次(按浏览器记,不再打扰)
|
||||
export const CREATE_DRAFT_HINT_KEY = 'huya.collab.draftHintShown';
|
||||
|
||||
export interface CreateDraft {
|
||||
order_no: string;
|
||||
shop: string;
|
||||
ck_text: string;
|
||||
gift_name: string;
|
||||
required_points: number | null;
|
||||
remark: string;
|
||||
home_images: string[];
|
||||
saved_at: number;
|
||||
}
|
||||
|
||||
export function createDraftKey(userId?: number | null): string {
|
||||
return userId ? `${CREATE_DRAFT_KEY_PREFIX}.${userId}` : '';
|
||||
}
|
||||
|
||||
/** 读草稿(读不到 / 解析坏都当没有) */
|
||||
export function readCreateDraft(userId?: number | null): CreateDraft | null {
|
||||
const key = createDraftKey(userId);
|
||||
if (!key) return null;
|
||||
try {
|
||||
const raw = window.localStorage.getItem(key);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as Partial<CreateDraft>;
|
||||
const savedAt = Number(parsed.saved_at) || 0;
|
||||
// 草稿只留 7 天:里面可能有一份 CK,不能无限期躺在浏览器里
|
||||
if (!savedAt || Date.now() - savedAt > 7 * 24 * 60 * 60 * 1000) {
|
||||
window.localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
order_no: typeof parsed.order_no === 'string' ? parsed.order_no : '',
|
||||
shop: typeof parsed.shop === 'string' ? parsed.shop : '',
|
||||
ck_text: typeof parsed.ck_text === 'string' ? parsed.ck_text : '',
|
||||
gift_name: typeof parsed.gift_name === 'string' ? parsed.gift_name : '',
|
||||
required_points: typeof parsed.required_points === 'number' ? parsed.required_points : null,
|
||||
remark: typeof parsed.remark === 'string' ? parsed.remark : '',
|
||||
home_images: Array.isArray(parsed.home_images)
|
||||
? parsed.home_images.filter((item): item is string => typeof item === 'string')
|
||||
: [],
|
||||
saved_at: Number(parsed.saved_at) || 0,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearCreateDraft(userId?: number | null): void {
|
||||
const key = createDraftKey(userId);
|
||||
if (!key) return;
|
||||
try {
|
||||
window.localStorage.removeItem(key);
|
||||
} catch {
|
||||
// 忽略:清不掉也不影响当前表单
|
||||
}
|
||||
}
|
||||
|
||||
/** 「资料没填全时直接建单 → 待补资料」的首次提示是否已经展示过 */
|
||||
export function draftHintShown(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(CREATE_DRAFT_HINT_KEY) === '1';
|
||||
} catch {
|
||||
return true; // 存不了就不要再反复弹
|
||||
}
|
||||
}
|
||||
|
||||
export function markDraftHintShown(): void {
|
||||
try {
|
||||
window.localStorage.setItem(CREATE_DRAFT_HINT_KEY, '1');
|
||||
} catch {
|
||||
// 忽略:提示只是体验
|
||||
}
|
||||
}
|
||||
|
||||
export function hasDraftContent(draft: Omit<CreateDraft, 'saved_at'>): boolean {
|
||||
// 礼包名不算「填过东西」:它现在默认空白、也不从草稿恢复(见下面 createForm 那段的说明),
|
||||
// 否则一份「只被上次自动填了礼包」的老草稿会一直弹「已恢复上次未提交的草稿」。
|
||||
return Boolean(
|
||||
draft.order_no.trim()
|
||||
|| draft.shop.trim()
|
||||
|| draft.ck_text.trim()
|
||||
|| draft.remark.trim()
|
||||
|| draft.home_images.length,
|
||||
);
|
||||
}
|
||||
|
||||
// 「补资料」草稿:按登录用户 + 订单 id 分开存。填一半关掉 / 刷新后,
|
||||
// 再点这一行的「补资料」会原样恢复(含刚贴的 CK 和刚上传的截图 key)。
|
||||
export const SUPPLEMENT_DRAFT_KEY_PREFIX = 'huya.collab.supplementDraft';
|
||||
|
||||
export interface SupplementDraft {
|
||||
shop: string;
|
||||
ck_text: string;
|
||||
gift_name: string;
|
||||
required_points: number | null;
|
||||
remark: string;
|
||||
home_images: string[];
|
||||
saved_at: number;
|
||||
}
|
||||
|
||||
export interface SupplementFormValues {
|
||||
shop: string;
|
||||
ck_text?: string;
|
||||
gift_name?: string;
|
||||
required_points?: number | null;
|
||||
remark?: string;
|
||||
home_images?: string[];
|
||||
}
|
||||
|
||||
export function supplementDraftKey(userId?: number | null, orderId?: number): string {
|
||||
return userId && orderId ? `${SUPPLEMENT_DRAFT_KEY_PREFIX}.${userId}.${orderId}` : '';
|
||||
}
|
||||
|
||||
export function readSupplementDraft(userId: number | null | undefined, orderId: number): SupplementDraft | null {
|
||||
const key = supplementDraftKey(userId, orderId);
|
||||
if (!key) return null;
|
||||
try {
|
||||
const raw = window.localStorage.getItem(key);
|
||||
if (!raw) return null;
|
||||
const parsed = JSON.parse(raw) as Partial<SupplementDraft>;
|
||||
const savedAt = Number(parsed.saved_at) || 0;
|
||||
if (!savedAt || Date.now() - savedAt > 7 * 24 * 60 * 60 * 1000) {
|
||||
window.localStorage.removeItem(key);
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
shop: typeof parsed.shop === 'string' ? parsed.shop : '',
|
||||
ck_text: typeof parsed.ck_text === 'string' ? parsed.ck_text : '',
|
||||
gift_name: typeof parsed.gift_name === 'string' ? parsed.gift_name : '',
|
||||
required_points: typeof parsed.required_points === 'number' ? parsed.required_points : null,
|
||||
remark: typeof parsed.remark === 'string' ? parsed.remark : '',
|
||||
home_images: Array.isArray(parsed.home_images)
|
||||
? parsed.home_images.filter((item): item is string => typeof item === 'string')
|
||||
: [],
|
||||
saved_at: savedAt,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearSupplementDraft(userId: number | null | undefined, orderId: number): void {
|
||||
const key = supplementDraftKey(userId, orderId);
|
||||
if (!key) return;
|
||||
try {
|
||||
window.localStorage.removeItem(key);
|
||||
} catch {
|
||||
// 忽略:清不掉也不影响当前表单
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTime(value: string | null | undefined): string {
|
||||
if (!value) return '-';
|
||||
const time = new Date(value);
|
||||
return Number.isNaN(time.getTime()) ? String(value) : time.toLocaleString();
|
||||
}
|
||||
Reference in New Issue
Block a user