feat(工作台): 视频列表加收藏列+数字列右对齐,视频详情页信息三行+标签排版

This commit is contained in:
maogeigei committed 2026-09-01 14:56:46 +08:00
1 parent 3f5c687e48
commit e43e5bbb6c
12 files changed
+830 -27

No files matched your search

@@ -0,0 +1,83 @@
/* cdp-verify-videoinfo.mjs — 验证:视频详情页信息卡三行排版(标题/账号组/数据组)(09-01) */
const CDP = 'http://127.0.0.1:9223';
async function getWs(targetId) {
const tabs = await (await fetch(CDP + '/json')).json();
const t = tabs.find((x) => x.id === targetId);
if (!t) throw new Error('target not found: ' + targetId);
return t.webSocketDebuggerUrl;
}
function cdp(ws, method, params = {}) {
return new Promise((resolve, reject) => {
const id = ++cdp._id;
const w = new WebSocket(ws);
const timer = setTimeout(() => { try { w.close(); } catch (e) {} reject(new Error('timeout: ' + method)); }, 30000);
w.onopen = () => w.send(JSON.stringify({ id, method, params }));
w.onmessage = (ev) => {
const m = JSON.parse(ev.data);
if (m.id !== id) return;
clearTimeout(timer);
try { w.close(); } catch (e) {}
m.error ? reject(new Error(method + ': ' + JSON.stringify(m.error))) : resolve(m.result);
};
w.onerror = () => { clearTimeout(timer); reject(new Error('ws error: ' + method)); };
});
}
cdp._id = 0;
async function evalJs(ws, expr) {
const r = await cdp(ws, 'Runtime.evaluate', { expression: expr, awaitPromise: true, returnByValue: true });
if (r.exceptionDetails) throw new Error('eval err: ' + JSON.stringify(r.exceptionDetails).slice(0, 300));
return r.result && r.result.value;
}
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const waitFor = async (ws, expr, timeout = 15000, label = '') => {
const t0 = Date.now();
while (Date.now() - t0 < timeout) {
if (await evalJs(ws, expr)) return true;
await sleep(300);
}
throw new Error('waitFor timeout: ' + label);
};
async function main() {
const tabs = await (await fetch(CDP + '/json')).json();
const tab = tabs.find((x) => x.url.includes('localhost:8900')) || tabs.find((x) => x.type === 'page');
if (!tab) throw new Error('no 8900 tab found');
const ws = await getWs(tab.id);
await cdp(ws, 'Page.enable');
await cdp(ws, 'Runtime.enable');
let pass = 0, fail = 0;
const check = (name, cond) => { cond ? pass++ : fail++; console.log((cond ? 'PASS' : 'FAIL') + ' | ' + name); };
await cdp(ws, 'Page.navigate', { url: 'http://localhost:8900/?v=vinfo#/video/680' });
await waitFor(ws, `!!document.querySelector('.video-detail-title')`, 15000, '视频详情渲染');
const r = await evalJs(ws, `(() => {
const card = document.querySelector('.video-info');
const title = card ? card.querySelector('.video-detail-title') : null;
const rows = card ? [...card.querySelectorAll('.info-row')] : [];
const rowLabels = rows.map((row) => [...row.querySelectorAll('.info-label')].map((l) => l.textContent.trim()));
const hasRenderErr = document.body.textContent.includes('渲染失败');
const titleStyle = title ? { fontSize: getComputedStyle(title).fontSize, weight: getComputedStyle(title).fontWeight } : null;
return {
hasTitle: !!title,
titleText: title ? title.textContent.trim().slice(0, 25) : '',
titleStyle,
rowCount: rows.length,
rowLabels,
hasRenderErr
};
})()`);
check('标题独立行存在', r.hasTitle && !!r.titleText);
check('标题大字号(' + (r.titleStyle ? r.titleStyle.fontSize + '/' + r.titleStyle.weight : '') + ')', r.titleStyle && parseFloat(r.titleStyle.fontSize) >= 18);
check('共 3 组信息行', r.rowCount === 3);
check('第1行=账号/视频ID/时长/发布时间(' + r.rowLabels[0] + ')', JSON.stringify(r.rowLabels[0]) === JSON.stringify(['账号', '视频ID', '时长', '发布时间']));
check('第2行=点赞/评论/分享/收藏(' + r.rowLabels[1] + ')', JSON.stringify(r.rowLabels[1]) === JSON.stringify(['点赞', '评论', '分享', '收藏']));
check('第3行=标签(' + r.rowLabels[2] + ')', JSON.stringify(r.rowLabels[2]) === JSON.stringify(['标签']));
check('无渲染失败', !r.hasRenderErr);
console.log(`\n结果: ${pass} PASS / ${fail} FAIL`);
process.exit(fail ? 1 : 0);
}
main().catch((e) => { console.error('ERROR:', e.message); process.exit(1); });