/** * 打印 Vue SSR 出来的 fault 页签里含 "前三" 的那段 HTML(对照旧页面,定位差在哪)。 * 用法:node tools/dump_ssr.mjs fault 前三 */ import { JSDOM } from 'jsdom' import { pathToFileURL } from 'node:url' import { resolve, dirname } from 'node:path' import { fileURLToPath } from 'node:url' const HERE = dirname(fileURLToPath(import.meta.url)) const GATEWAY = 'http://127.0.0.1:28084' const TAB = process.argv[2] || 'fault' const NEEDLE = process.argv[3] || '前三' const data = await (await fetch(`${GATEWAY}/detail/api/fleet`)).json() const entry = pathToFileURL(resolve(HERE, '../target/ssr/entry-server.js')).href const html = await (await import(entry)).renderTab(data, TAB) const dom = new JSDOM(`
${html}
`) const wrap = dom.window.document.getElementById('wrap') for (const p of Array.from(wrap.querySelectorAll('p'))) { if (p.textContent.includes(NEEDLE)) { console.log('--- Vue SSR

---') console.log(p.outerHTML.replace(/\s+/g, ' ').slice(0, 700)) console.log(' 文本节点:') for (const c of p.childNodes) { if (c.nodeType === 3 && c.textContent.trim()) console.log(' text:', JSON.stringify(c.textContent)) else if (c.nodeType === 1) console.log(' <' + c.tagName.toLowerCase() + '>', JSON.stringify(c.textContent)) } } }