75 lines
2.8 KiB
JavaScript
75 lines
2.8 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const { modules } = require('./capture-full-manual-pages')
|
|
|
|
const root = path.resolve(__dirname, '..', '..')
|
|
const outputPath = path.resolve(__dirname, 'manual-dialog-audit.json')
|
|
|
|
function unique(values) {
|
|
return [...new Set(values.map(value => String(value || '').trim()).filter(Boolean))]
|
|
}
|
|
|
|
function literalAttribute(attributes, name) {
|
|
const match = attributes.match(new RegExp(`(?:^|\\s)${name}\\s*=\\s*["']([^"']+)["']`))
|
|
return match ? match[1].trim() : ''
|
|
}
|
|
|
|
function cleanText(value) {
|
|
return String(value || '')
|
|
.replace(/<[^>]+>/g, ' ')
|
|
.replace(/\{\{[\s\S]*?\}\}/g, ' ')
|
|
.replace(/\s+/g, ' ')
|
|
.trim()
|
|
}
|
|
|
|
const results = []
|
|
for (const module of modules) {
|
|
for (const [title, route, source] of module.pages) {
|
|
const sourcePath = path.resolve(root, 'src', 'views', source)
|
|
const content = fs.readFileSync(sourcePath, 'utf8')
|
|
const scriptStart = content.indexOf('<script')
|
|
const template = (scriptStart >= 0 ? content.slice(0, scriptStart) : content)
|
|
.replace(/<!--[\s\S]*?-->/g, '')
|
|
|
|
const dialogs = []
|
|
const dialogPattern = /<el-dialog\b([^>]*)>([\s\S]*?)<\/el-dialog>/g
|
|
let dialogMatch
|
|
while ((dialogMatch = dialogPattern.exec(template))) {
|
|
const attributes = dialogMatch[1]
|
|
const body = dialogMatch[2]
|
|
const dialogTitle = literalAttribute(attributes, 'title') || '业务操作弹窗'
|
|
const fields = unique([...body.matchAll(/<el-form-item\b([^>]*)>/g)]
|
|
.map(match => literalAttribute(match[1], 'label')))
|
|
const columns = unique([...body.matchAll(/<el-table-column\b([^>]*)>/g)]
|
|
.map(match => literalAttribute(match[1], 'label')))
|
|
const commands = unique([...body.matchAll(/<el-button\b[^>]*>([\s\S]*?)<\/el-button>/g)]
|
|
.map(match => cleanText(match[1])))
|
|
dialogs.push({ title: dialogTitle, fields, columns, commands })
|
|
}
|
|
|
|
const inlineEditableFields = []
|
|
const columnPattern = /<el-table-column\b([^>]*)>([\s\S]*?)<\/el-table-column>/g
|
|
let columnMatch
|
|
while ((columnMatch = columnPattern.exec(template))) {
|
|
const label = literalAttribute(columnMatch[1], 'label')
|
|
if (label && /@change\s*=|@blur\s*=|@click\s*=|v-model\s*=/.test(columnMatch[2])) {
|
|
inlineEditableFields.push(label)
|
|
}
|
|
}
|
|
|
|
results.push({
|
|
module: module.title,
|
|
title,
|
|
route,
|
|
source,
|
|
dialogs,
|
|
inlineEditableFields: unique(inlineEditableFields)
|
|
})
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(outputPath, JSON.stringify(results, null, 2), 'utf8')
|
|
console.log(`Audited ${results.length} pages`)
|
|
console.log(`Pages with dialogs: ${results.filter(item => item.dialogs.length).length}`)
|
|
console.log(`Pages with inline editing: ${results.filter(item => item.inlineEditableFields.length).length}`)
|