50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
import { chromium } from 'playwright-core'
|
|
|
|
const BASE = 'http://localhost:5082'
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: `${process.env.LOCALAPPDATA}\\ms-playwright\\chromium-1232\\chrome-win64\\chrome.exe`,
|
|
})
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
|
|
|
await page.addInitScript(() => {
|
|
sessionStorage.setItem('fms-login', JSON.stringify({ loginInfo: { token: 'dev-token', user: { id: 1, name: 'dev', account: 'g3soft' } } }))
|
|
localStorage.setItem('fms-user', JSON.stringify({ userInfo: { orgId: 'G3HD', account: 'g3soft' } }))
|
|
})
|
|
await page.route('**/api/**', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: null }) }))
|
|
|
|
await page.goto(`${BASE}/file-demo`, { waitUntil: 'networkidle', timeout: 30000 })
|
|
await page.waitForTimeout(3000)
|
|
|
|
const result = await page.evaluate(() => {
|
|
const out = { components: [] }
|
|
const seen = new Set()
|
|
function walk(instance) {
|
|
if (!instance || seen.has(instance)) return
|
|
seen.add(instance)
|
|
const sub = instance.subTree
|
|
if (sub) visit(sub)
|
|
}
|
|
function visit(v) {
|
|
if (!v) return
|
|
if (v.component) {
|
|
const p = v.component.props
|
|
if (p && (p.defaultSize !== undefined || p['default-size'] !== undefined || p.default_size !== undefined)) {
|
|
out.components.push({
|
|
name: v.type?.__name || v.type?.name || '(anon)',
|
|
props: { ...p },
|
|
propKeys: Object.keys(p),
|
|
})
|
|
}
|
|
walk(v.component)
|
|
}
|
|
if (Array.isArray(v.children)) v.children.forEach(visit)
|
|
else if (v.children && typeof v.children === 'object' && !v.component) visit(v.children)
|
|
}
|
|
const app = document.querySelector('#app')?.__vue_app__
|
|
walk(app?._instance)
|
|
return out
|
|
})
|
|
|
|
console.log(JSON.stringify(result, null, 2))
|
|
await browser.close() |