fix(account): 一键查询按反馈收敛 —— 只在账号管理展示、结果落账号、修 1970 显示
按用户反馈改了四处。 ## ① 结果只在账号管理展示(不再出现在精英宝典/电竞手册页) 移除了工作台页的结果弹窗与导入。**类型集合保留**(三个工作台都有)—— 因为账号页批量建任务要用 `handbook_scope` 过 `DOUYU_HANDBOOK_TASK_TYPES` 校验, 去掉会被「该任务不属于当前工作台」拦掉;去掉的只是**快捷操作按钮**。 ## ② 不再每次弹出 原来任务跑完就自动弹面板,而且任务会被反复轮询到。现在整个弹窗机制去掉了: 结果落在账号上,打开账号就能看。 ## ③ 结果写进账号(新增迁移 0047) 新增 `accounts.overview_snapshot`(JSON)+ `overview_queried_at`,覆盖式只留最新一份。 详情页直接读账号上的快照,不再轮询任务。 **为什么放账号而不是只留任务里**:任务会被保留策略清掉(长保留档 90 天), 而「这个账号现在什么情况」是**账号的信息**,不该依赖一条日志的寿命。 ## ④ 修 1970/1/1 08:00:00(真 bug) 斗鱼用 `0` / `"0"` / 空串表示「没有这个时间」。原实现直接透传, 前端 `new Date(0)` → **1970/1/1 08:00:00** —— 运营会以为"到期时间是 1970 年"。 两端都修了: - 后端新增 `_ts()`,把 `0`/`"0"`/空/负数 归成 `None`(积分到期、宝典到期、 电竞到期、商品活动时间四处都过一遍) - 前端 `formatTime` 也把 `0`/负数显示成 `-`(上游再出错也不至于显示 1970) ## 测试(+14 条,共 36) - `TestTimestampNormalisation`:`0`/`"0"`/空/负数 → `None`;真实时间戳透传 - `TestSnapshotIsWrittenToAccount`:快照与时间落到账号上、 **`willExpireTime="0"` 不能落库成 0**(1970 的回归用例)、覆盖式不追加 ## 验证 `TZ=Asia/Shanghai` **588 passed / 6 skipped**;`TZ=UTC` 41 passed; ruff 全绿;前端 build 通过、lint 0 errors。
This commit is contained in:
@@ -57,10 +57,17 @@ const ERROR_LABELS: Record<string, string> = {
|
||||
exchange_records: '兑换记录',
|
||||
};
|
||||
|
||||
/** 时间戳(秒/毫秒/字符串)→ 可读文本;认不出来就原样显示。 */
|
||||
/** 时间戳(秒/毫秒/字符串)→ 可读文本;认不出来就原样显示。
|
||||
*
|
||||
* ⚠️ `0` / `"0"` / 空 必须显示成 `-`:斗鱼用 0 表示「没有这个时间」,
|
||||
* 而 `new Date(0)` 是 **1970/1/1 08:00:00** —— 直接格式化会让运营
|
||||
* 以为"到期时间是 1970 年"(这个 bug 真出现过)。
|
||||
*/
|
||||
function formatTime(value: string | number | null | undefined): string {
|
||||
if (value === null || value === undefined || value === '') return '-';
|
||||
if (typeof value === 'number' && value <= 0) return '-';
|
||||
const text = String(value).trim();
|
||||
if (/^-?\d+$/.test(text) && Number(text) <= 0) return '-';
|
||||
let seconds: number | null = null;
|
||||
if (/^\d+$/.test(text)) {
|
||||
seconds = Number(text);
|
||||
@@ -138,7 +145,14 @@ function HighValueCard({ goods }: { goods: HighValueGoods }) {
|
||||
);
|
||||
}
|
||||
|
||||
export default function AccountOverviewPanel({ result }: { result: AccountOverviewResult }) {
|
||||
export default function AccountOverviewPanel({
|
||||
result,
|
||||
queriedAt,
|
||||
}: {
|
||||
result: AccountOverviewResult;
|
||||
/** 查询时间(优先用账号上记录的,回落到结果里的) */
|
||||
queriedAt?: string | null;
|
||||
}) {
|
||||
if (!result) return <Empty description="暂无结果" />;
|
||||
const assets = result.assets || {};
|
||||
const errors = result.errors || {};
|
||||
@@ -247,7 +261,7 @@ export default function AccountOverviewPanel({ result }: { result: AccountOvervi
|
||||
</Card>
|
||||
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
查询时间:{formatTime(result.queried_at)}
|
||||
查询时间:{formatTime(queriedAt ?? result.queried_at)}
|
||||
</Text>
|
||||
</Space>
|
||||
);
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
CheckCircleOutlined, ColumnWidthOutlined, CopyOutlined, CreditCardOutlined, ExclamationCircleOutlined, FieldTimeOutlined, FilterOutlined, GiftOutlined,
|
||||
ImportOutlined, QrcodeOutlined, ReloadOutlined,
|
||||
SearchOutlined, SettingOutlined, ShoppingOutlined, StopOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
accountApi,
|
||||
@@ -19,9 +18,6 @@ import {
|
||||
} from '../../api/modules';
|
||||
import ExchangeResultImage from '../../components/ExchangeResultImage';
|
||||
import QrActions from '../../components/QrActions';
|
||||
import AccountOverviewPanel, {
|
||||
type AccountOverviewResult,
|
||||
} from './AccountOverviewPanel';
|
||||
import { usePermissions } from '../../hooks/usePermissions';
|
||||
import { useWebSocketLogs } from '../../hooks/useWebSocketLogs';
|
||||
import {
|
||||
@@ -153,9 +149,6 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
const autoOpenedPayTaskIds = useRef<Set<number>>(new Set());
|
||||
const autoCopiedExchangeTaskIds = useRef<Set<number>>(new Set());
|
||||
const autoNotifiedConfirmFailedTaskIds = useRef<Set<number>>(new Set());
|
||||
// 一键查询:任务跑完后自动把结果面板弹出来(去重,同一个任务只弹一次)
|
||||
const [ovPanelTask, setOvPanelTask] = useState<DouyuTaskItem | null>(null);
|
||||
const shownOvTaskIds = useRef<Set<number>>(new Set());
|
||||
const [confirmFailTip, setConfirmFailTip] = useState<{ taskId: number; message: string } | null>(null);
|
||||
const [confirmFailCountdown, setConfirmFailCountdown] = useState(0);
|
||||
const [exchangePreview, setExchangePreview] = useState<{ task: DouyuTaskItem; url: string } | null>(null);
|
||||
@@ -649,22 +642,6 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// 一键查询的结果是一大块结构化信息,不适合塞进列表单元格 ——
|
||||
// 跑完就弹面板,弹过就不再弹(任务会被反复轮询到,不去重会一直弹)。
|
||||
const finished = tasks.filter(
|
||||
(task) =>
|
||||
task.task_type === 'query_account_overview'
|
||||
&& task.status === 'success'
|
||||
&& task.result,
|
||||
);
|
||||
const fresh = finished.find((task) => !shownOvTaskIds.current.has(task.id));
|
||||
if (fresh) {
|
||||
shownOvTaskIds.current.add(fresh.id);
|
||||
setOvPanelTask(fresh);
|
||||
}
|
||||
}, [tasks]);
|
||||
|
||||
// qrTask 已由 useMemo 从 tasks 派生,切换 Tab / 后端 progress 写入后自动更新,无需手动跟随
|
||||
|
||||
useEffect(() => {
|
||||
@@ -2561,18 +2538,6 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={<Space><ThunderboltOutlined /><span>一键查询结果</span></Space>}
|
||||
open={Boolean(ovPanelTask)}
|
||||
onCancel={() => setOvPanelTask(null)}
|
||||
footer={<Button onClick={() => setOvPanelTask(null)}>关闭</Button>}
|
||||
width={780}
|
||||
styles={{ body: { maxHeight: '70vh', overflowY: 'auto' } }}
|
||||
>
|
||||
{ovPanelTask?.result ? (
|
||||
<AccountOverviewPanel result={ovPanelTask.result as AccountOverviewResult} />
|
||||
) : null}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import {
|
||||
CheckCircleOutlined, CreditCardOutlined, FieldTimeOutlined, GiftOutlined,
|
||||
ProfileOutlined,
|
||||
QrcodeOutlined, ReloadOutlined, SearchOutlined, ShoppingOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import type { DouyuGoodsItem, DouyuTaskItem } from '../../api/modules';
|
||||
@@ -39,7 +38,6 @@ export const ELITE_QUICK_ACTIONS = [
|
||||
{ key: 'query_limited_goods', icon: <SearchOutlined /> },
|
||||
{ key: 'query_gold_balance', icon: <SearchOutlined /> },
|
||||
{ key: 'lock_goods', icon: <ShoppingOutlined /> },
|
||||
{ key: 'query_account_overview', icon: <ProfileOutlined /> },
|
||||
{ key: 'exchange_goods', icon: <ShoppingOutlined /> },
|
||||
{ key: 'create_gold_qr', icon: <CreditCardOutlined /> },
|
||||
{ key: 'donate_elite_gift', icon: <GiftOutlined /> },
|
||||
@@ -54,7 +52,6 @@ export const ESPORTS_QUICK_ACTIONS = [
|
||||
{ key: 'query_limited_goods', icon: <SearchOutlined /> },
|
||||
{ key: 'query_gold_balance', icon: <SearchOutlined /> },
|
||||
{ key: 'refresh_esports_goods', icon: <ReloadOutlined /> },
|
||||
{ key: 'query_account_overview', icon: <ProfileOutlined /> },
|
||||
{ key: 'exchange_esports_goods', icon: <ShoppingOutlined /> },
|
||||
{ key: 'create_gold_qr', icon: <CreditCardOutlined /> },
|
||||
{ key: 'donate_esports_chicken_gift', icon: <GiftOutlined /> },
|
||||
@@ -69,7 +66,6 @@ export const PEACE_QUICK_ACTIONS = [
|
||||
{ key: 'query_xpd_balance', icon: <SearchOutlined /> },
|
||||
{ key: 'query_xpd_fragments', icon: <SearchOutlined /> },
|
||||
{ key: 'query_xpd_purchase_records', icon: <FieldTimeOutlined /> },
|
||||
{ key: 'query_account_overview', icon: <ProfileOutlined /> },
|
||||
{ key: 'refresh_xpd_goods', icon: <ReloadOutlined /> },
|
||||
{ key: 'exchange_xpd_goods', icon: <ShoppingOutlined /> },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user