Connect front web app to workbench APIs

This commit is contained in:
王鹏
2026-05-22 16:43:55 +08:00
parent d39eeca8a9
commit 625489e77c
6 changed files with 82 additions and 5 deletions

View File

@@ -132,6 +132,64 @@ watch(
}
)
watch(
tables,
(nextTables) => {
nextTables.forEach(normalizeTable)
},
{ deep: true, immediate: true }
)
function toPascalCase(value) {
return String(value || '')
.split(/[^A-Za-z0-9]+|_/)
.filter(Boolean)
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join('')
}
function toCamelCase(value) {
const pascal = toPascalCase(value)
return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : ''
}
function javaTypeOf(columnType) {
const normalized = String(columnType || '').toLowerCase()
if (normalized.startsWith('bigint')) return 'Long'
if (normalized.startsWith('int')) return 'Integer'
if (normalized.startsWith('decimal')) return 'BigDecimal'
if (normalized === 'datetime' || normalized === 'date') return 'Date'
return 'String'
}
function normalizeTable(table) {
if (!table) return
table.className = toPascalCase(table.tableName)
table.moduleName = table.moduleName || 'system'
table.businessName = toCamelCase(table.tableName)
table.functionName = table.tableComment || table.tableName
table.tplCategory = table.tplCategory || 'crud'
table.tplWebType = table.tplWebType || 'element-plus'
const columns = Array.isArray(table.columns) ? table.columns : []
columns.forEach((column) => normalizeColumn(column))
}
function normalizeColumn(column) {
if (!column) return
column.javaField = toCamelCase(column.columnName)
column.javaType = javaTypeOf(column.columnType)
column.isPk = column.isPk === '1' ? '1' : '0'
column.isIncrement = column.isIncrement === '1' ? '1' : '0'
column.isRequired = column.isRequired === '1' ? '1' : '0'
column.isInsert = column.isInsert || '1'
column.isEdit = column.isEdit || '1'
column.isList = column.isList || '1'
column.isQuery = column.isQuery || '0'
column.queryType = column.queryType || 'EQ'
column.htmlType = column.htmlType || 'input'
}
function uid(prefix) {
return `${prefix}_${Date.now()}_${Math.random().toString(16).slice(2)}`
}