124 lines
4.8 KiB
JavaScript
124 lines
4.8 KiB
JavaScript
import { chromium } from 'playwright-core'
|
|
import zlib from 'node:zlib'
|
|
|
|
const BASE = 'http://localhost:5082'
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
})
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 })
|
|
|
|
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/**', async (route) => {
|
|
const req = route.request()
|
|
const url = req.url()
|
|
let body = {}
|
|
try { body = req.postDataJSON() || {} } catch {}
|
|
if (url.includes('/data/loaddata')) {
|
|
const rows = body.view_name === 's_module' ? [{ b_id: 1, b_code: 'b_port', b_name: '港口管理' }] :
|
|
body.view_name === 'bf_files_cateid' ? [{ b_id: '10', b_name: '合同文件' }] : []
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: rows }) })
|
|
}
|
|
if (url.includes('/data/page')) {
|
|
const files = Array.from({ length: 4 }, (_, i) => ({
|
|
subid: String(1000 + i), father: '1001', mx_moduleid: '1', mx_cate_id: '10',
|
|
mx_filename: `文件-${i + 1}.pdf`, mx_filesize: (i + 1) * 1024 * 1024,
|
|
mx_fileext: 'pdf', mx_mapfilename: '',
|
|
}))
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: { rows: files, total: files.length } }) })
|
|
}
|
|
return 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(2000)
|
|
await page.locator('button:has-text("声明式弹窗")').click()
|
|
await page.waitForTimeout(1500)
|
|
|
|
const buf = await page.screenshot()
|
|
|
|
// ---- minimal PNG decoder ----
|
|
function decodePNG(buf) {
|
|
if (buf.readUInt32BE(0) !== 0x89504e47) throw new Error('not png')
|
|
let pos = 8
|
|
let width = 0, height = 0, bitDepth = 0, colorType = 0
|
|
const idat = []
|
|
while (pos < buf.length) {
|
|
const len = buf.readUInt32BE(pos)
|
|
const type = buf.toString('ascii', pos + 4, pos + 8)
|
|
const data = buf.subarray(pos + 8, pos + 8 + len)
|
|
if (type === 'IHDR') {
|
|
width = data.readUInt32BE(0)
|
|
height = data.readUInt32BE(4)
|
|
bitDepth = data[8]
|
|
colorType = data[9]
|
|
} else if (type === 'IDAT') {
|
|
idat.push(data)
|
|
} else if (type === 'IEND') break
|
|
pos += 12 + len
|
|
}
|
|
const channels = colorType === 6 ? 4 : colorType === 2 ? 3 : colorType === 0 ? 1 : 4
|
|
const bpp = Math.max(1, (channels * bitDepth) / 8)
|
|
const raw = zlib.inflateSync(Buffer.concat(idat))
|
|
const stride = width * channels
|
|
const out = Buffer.alloc(height * stride)
|
|
const paeth = (a, b, c) => {
|
|
const p = a + b - c
|
|
const pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c)
|
|
if (pa <= pb && pa <= pc) return a
|
|
if (pb <= pc) return b
|
|
return c
|
|
}
|
|
for (let y = 0; y < height; y++) {
|
|
const filter = raw[y * (stride + 1)]
|
|
const row = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1))
|
|
const prev = y > 0 ? out.subarray((y - 1) * stride, y * stride) : null
|
|
const cur = out.subarray(y * stride, (y + 1) * stride)
|
|
for (let x = 0; x < stride; x++) {
|
|
const a = x >= bpp ? cur[x - bpp] : 0
|
|
const b = prev ? prev[x] : 0
|
|
const c = x >= bpp && prev ? prev[x - bpp] : 0
|
|
let v = row[x]
|
|
if (filter === 1) v = (v + a) & 0xff
|
|
else if (filter === 2) v = (v + b) & 0xff
|
|
else if (filter === 3) v = (v + Math.floor((a + b) / 2)) & 0xff
|
|
else if (filter === 4) v = (v + paeth(a, b, c)) & 0xff
|
|
cur[x] = v
|
|
}
|
|
}
|
|
return { width, height, channels, data: out }
|
|
}
|
|
|
|
const png = decodePNG(buf)
|
|
const { width, height, channels, data } = png
|
|
const px = (x, y) => {
|
|
const i = (y * width + x) * channels
|
|
return channels === 4
|
|
? `${data[i]},${data[i + 1]},${data[i + 2]}`
|
|
: `${data[i]},${data[i + 1]},${data[i + 2]}`
|
|
}
|
|
|
|
// Profile horizontal strip at several y's around the two bars (x 380..940)
|
|
const yPositions = [220, 300, 400, 500, 600, 700, 800]
|
|
const compact = []
|
|
for (let x = 385; x <= 940; x++) {
|
|
const row = { x }
|
|
for (const y of yPositions) row[`y${y}`] = px(x, y)
|
|
compact.push(row)
|
|
}
|
|
|
|
// Also sample a vertical strip through both bars at mid height to show line thickness
|
|
const vertical = []
|
|
for (let y = 215; y <= 720; y += 10) {
|
|
vertical.push({ y, bar1: px(400, y), bar2: px(906, y), gap1: px(397, y), gap2: px(403, y) })
|
|
}
|
|
|
|
console.log('HORIZONTAL PROFILE (x around both bars):')
|
|
for (const r of compact) console.log(JSON.stringify(r))
|
|
console.log('\nVERTICAL PROFILE:')
|
|
for (const r of vertical) console.log(JSON.stringify(r))
|
|
await browser.close()
|