init: TS 版 dacli v0.7 baseline (8 父命令/26+ 子命令, 0.4MB, .claude/skills/dacli-ts)
参考 boot/ 仓库结构初始化, 同步到 gitea:3000/ssw/dacli (private). 包括: - src/ 8 父命令 (form/menu/dm/dict/di/apis/doc/workflow + login/status) + core (client/crypto/help/log/types/config) - src/schema/ FieldBuilder (从 JNPF web 源码提取, 避免 53 个手写 builder) - tests/ vitest 单元 + playwright E2E (含 workSystem/developSystem baseline regression) - scripts/ extract-all.mjs (从 jnpf-web 源码生成 schema) + seed-tds-baseline.ts - doc/ architecture/plan/api/extractors/baseline/RESUME/help-system + v0.6/v0.7 changelog - .claude/skills/dacli-ts/ Claude 集成 skill (SKILL.md + 5 references + 7 examples + 3 baseline) - CLAUDE.md (项目说明) + README.md + prompt.md (开发任务说明书) - 配置文件: package.json/lock, tsconfig, vitest.config, playwright.config
This commit is contained in:
commit
c98ad4f425
93 files changed
+12718
No files matched your search
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
* schema/FieldBuilder.ts — 通用 FieldBuilder
|
||||
*
|
||||
* 从 src/data/*.json 加载 schema, 暴露 `build(jnpfKey, props)` API.
|
||||
*
|
||||
* 核心设计 (来自 doc/architecture.md §2.3):
|
||||
* - 不用 Java 版 53 个硬编码 builder
|
||||
* - 1 个通用 builder + JSON schema
|
||||
* - JNPF 升级: 重跑 extract-all, 不改 builder 代码
|
||||
*
|
||||
* 数据流:
|
||||
* component-map.json (jnpfKey → tag) ─┐
|
||||
* field-schemas.json (jnpfKey → fields) ─┤→ FieldBuilder.build()
|
||||
* validation-rules.json (L1 正则) ─┘
|
||||
*
|
||||
* 用法:
|
||||
* const fb = new FieldBuilder()
|
||||
* const f = fb.build('input', { label: '姓名', __config__: { required: true } })
|
||||
*/
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
// ----- JSON 数据类型 -----
|
||||
|
||||
export interface ComponentMap {
|
||||
[jnpfKey: string]: string
|
||||
}
|
||||
|
||||
export interface FieldSchemas {
|
||||
[jnpfKey: string]: string[]
|
||||
}
|
||||
|
||||
export interface ValidationRule {
|
||||
msg: string
|
||||
rule: string
|
||||
}
|
||||
|
||||
export interface ValidationRules {
|
||||
[name: string]: ValidationRule
|
||||
}
|
||||
|
||||
// ----- 加载工具 -----
|
||||
|
||||
function dataDir(): string {
|
||||
// 文件位置: src/schema/FieldBuilder.ts
|
||||
// 数据位置: src/data/*.json
|
||||
// __dirname = src/schema → ../../data ? No: src/schema → ../data
|
||||
const here = dirname(fileURLToPath(import.meta.url))
|
||||
return resolve(here, '../data')
|
||||
}
|
||||
|
||||
function readJson<T>(file: string): T {
|
||||
const p = resolve(dataDir(), file)
|
||||
return JSON.parse(readFileSync(p, 'utf-8')) as T
|
||||
}
|
||||
|
||||
/** 加载 component-map (jnpfKey → tag). 60+ 项 */
|
||||
export function loadComponentMap(): ComponentMap {
|
||||
return readJson<ComponentMap>('component-map.json')
|
||||
}
|
||||
|
||||
/** 加载 field-schemas (jnpfKey → activeData 字段列表). 39 控件 */
|
||||
export function loadFieldSchemas(): FieldSchemas {
|
||||
return readJson<FieldSchemas>('field-schemas.json')
|
||||
}
|
||||
|
||||
/** 加载 validation-rules (L1 正则). 14 条 */
|
||||
export function loadValidationRules(): ValidationRules {
|
||||
return readJson<ValidationRules>('validation-rules.json')
|
||||
}
|
||||
|
||||
// ----- 通用 FieldBuilder -----
|
||||
|
||||
/** 完整 field 形状 (来自 web componentMap.ts 的 inputComponents 之一) */
|
||||
export interface JnpfField {
|
||||
__config__: {
|
||||
jnpfKey: string
|
||||
label: string
|
||||
tag: string
|
||||
span: number
|
||||
layout: 'colFormItem' | 'rowFormItem'
|
||||
showLabel: boolean
|
||||
required: boolean
|
||||
regList: unknown[]
|
||||
trigger: string | string[]
|
||||
visibility: string[]
|
||||
[k: string]: unknown
|
||||
}
|
||||
// 其他属性 (placeholder, style, options 等) 由用户传入
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
/** 控件分类 (来自 web componentMap.ts) */
|
||||
export const COMPONENT_CATEGORY: Record<string, 'input' | 'select' | 'system' | 'layout' | 'ocr'> = {
|
||||
// 基础 input
|
||||
input: 'input', textarea: 'input', inputNumber: 'input', switch: 'input',
|
||||
radio: 'input', checkbox: 'input', select: 'input', cascader: 'input',
|
||||
datePicker: 'input', timePicker: 'input', uploadFile: 'input', uploadImg: 'input',
|
||||
colorPicker: 'input', rate: 'input', slider: 'input', editor: 'input',
|
||||
link: 'input', button: 'input', text: 'input', alert: 'input',
|
||||
qrcode: 'input', barcode: 'input', carousel: 'input',
|
||||
// 高级 select
|
||||
organizeSelect: 'select', posSelect: 'select', userSelect: 'select',
|
||||
roleSelect: 'select', groupSelect: 'select', table: 'select',
|
||||
treeSelect: 'select', popupTableSelect: 'select', autoComplete: 'select',
|
||||
areaSelect: 'select', relationForm: 'select', relationFormAttr: 'select',
|
||||
popupSelect: 'select', popupAttr: 'select', signature: 'select',
|
||||
sign: 'select', location: 'select', iframe: 'select', calculate: 'select',
|
||||
dateCalculate: 'select', relationQuery: 'select',
|
||||
// 系统
|
||||
createUser: 'system', createTime: 'system', modifyUser: 'system',
|
||||
modifyTime: 'system', currOrganize: 'system', currPosition: 'system', billRule: 'system',
|
||||
// 布局
|
||||
groupTitle: 'layout', divider: 'layout', collapse: 'layout', tab: 'layout',
|
||||
steps: 'layout', row: 'layout', card: 'layout', tableGrid: 'layout',
|
||||
}
|
||||
|
||||
/** layout 类的 jnpfKey */
|
||||
const LAYOUT_KEYS = new Set([
|
||||
'groupTitle', 'divider', 'collapse', 'tab', 'steps', 'row', 'card', 'tableGrid',
|
||||
])
|
||||
|
||||
/** 子表 (table) 类 (特殊) */
|
||||
const TABLE_KEY = 'table'
|
||||
|
||||
/**
|
||||
* 通用 FieldBuilder — 从 JSON schema 装配一个完整 field
|
||||
*
|
||||
* @param jnpfKey 控件 key (e.g. 'input', 'select', 'relationForm')
|
||||
* @param props 覆盖属性, 可含 __config__ 子对象覆盖默认
|
||||
* @returns 完整 JnpfField 对象
|
||||
*/
|
||||
export class FieldBuilder {
|
||||
private componentMap: ComponentMap
|
||||
private fieldSchemas: FieldSchemas
|
||||
private validationRules: ValidationRules
|
||||
|
||||
constructor() {
|
||||
this.componentMap = loadComponentMap()
|
||||
this.fieldSchemas = loadFieldSchemas()
|
||||
this.validationRules = loadValidationRules()
|
||||
}
|
||||
|
||||
/** 所有已知的 jnpfKey */
|
||||
listKeys(): string[] {
|
||||
return Object.keys(this.componentMap)
|
||||
}
|
||||
|
||||
/** 控件分类 */
|
||||
category(jnpfKey: string): 'input' | 'select' | 'system' | 'layout' | 'ocr' | 'unknown' {
|
||||
return COMPONENT_CATEGORY[jnpfKey] || 'unknown'
|
||||
}
|
||||
|
||||
/** jnpfKey 对应的 tag (e.g. 'input' → 'JnpfInput'). 找不到返回 undefined */
|
||||
tag(jnpfKey: string): string | undefined {
|
||||
return this.componentMap[jnpfKey]
|
||||
}
|
||||
|
||||
/** 控件在 Rxxx.vue 里实际使用的 activeData 字段列表 (来自 field-schemas.json) */
|
||||
activeDataFields(jnpfKey: string): string[] {
|
||||
return this.fieldSchemas[jnpfKey] || []
|
||||
}
|
||||
|
||||
/** L1 正则规则 (14 条) */
|
||||
validationRule(name: string): ValidationRule | undefined {
|
||||
return this.validationRules[name]
|
||||
}
|
||||
|
||||
/** 所有 L1 正则 key (供 `dacli form create --fields` 用) */
|
||||
validationRuleKeys(): string[] {
|
||||
return Object.keys(this.validationRules)
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造一个完整 field 对象.
|
||||
*
|
||||
* @example
|
||||
* const f = fb.build('input', {
|
||||
* label: '姓名',
|
||||
* __config__: { required: true, regList: [{ pattern: 'chinese', message: '请输入中文' }] },
|
||||
* placeholder: '请输入姓名',
|
||||
* })
|
||||
*/
|
||||
build(jnpfKey: string, props: Record<string, unknown> = {}): JnpfField {
|
||||
const tag = this.componentMap[jnpfKey]
|
||||
if (!tag) {
|
||||
throw new Error(`Unknown jnpfKey: '${jnpfKey}'. 可用: ${this.listKeys().slice(0, 10).join(', ')}...`)
|
||||
}
|
||||
const cat = this.category(jnpfKey)
|
||||
const isLayout = cat === 'layout'
|
||||
const isTable = jnpfKey === TABLE_KEY
|
||||
|
||||
// 默认 __config__
|
||||
const defaultConfig: Record<string, unknown> = {
|
||||
jnpfKey,
|
||||
label: props.label as string || jnpfKey,
|
||||
tag,
|
||||
showLabel: !isLayout,
|
||||
span: 24,
|
||||
layout: isLayout || isTable ? 'rowFormItem' : 'colFormItem',
|
||||
required: false,
|
||||
visibility: ['pc', 'app'],
|
||||
noShow: false,
|
||||
dragDisabled: false,
|
||||
}
|
||||
// 大部分控件有 regList, 简单系统/布局类没有
|
||||
if (!isLayout && jnpfKey !== 'billRule' && jnpfKey !== 'createUser' && jnpfKey !== 'createTime' &&
|
||||
jnpfKey !== 'modifyUser' && jnpfKey !== 'modifyTime' && jnpfKey !== 'currOrganize' &&
|
||||
jnpfKey !== 'currPosition' && jnpfKey !== 'link' && jnpfKey !== 'button' && jnpfKey !== 'text' &&
|
||||
jnpfKey !== 'alert' && jnpfKey !== 'iframe') {
|
||||
defaultConfig.regList = []
|
||||
}
|
||||
// trigger
|
||||
if (['input', 'textarea'].includes(jnpfKey)) defaultConfig.trigger = 'blur'
|
||||
else if (['switch', 'radio', 'checkbox', 'select', 'cascader', 'datePicker', 'timePicker',
|
||||
'uploadFile', 'uploadImg', 'colorPicker', 'rate', 'slider', 'treeSelect',
|
||||
'popupTableSelect', 'areaSelect', 'relationForm', 'popupSelect', 'signature',
|
||||
'sign', 'location', 'userSelect', 'roleSelect', 'organizeSelect', 'posSelect',
|
||||
'groupSelect', 'inputNumber', 'autoComplete'].includes(jnpfKey)) {
|
||||
defaultConfig.trigger = 'change'
|
||||
}
|
||||
else if (jnpfKey === 'editor') defaultConfig.trigger = 'blur'
|
||||
|
||||
// 合并 __config__ (用户提供优先)
|
||||
const userConfig = (props.__config__ as Record<string, unknown>) || {}
|
||||
const finalConfig: Record<string, unknown> = { ...defaultConfig, ...userConfig }
|
||||
// label 一致性: __config__.label 优先 (用户可能两边都传)
|
||||
if (props.label && !userConfig.label) finalConfig.label = props.label
|
||||
|
||||
// 默认属性 (style 等)
|
||||
const defaults: Record<string, unknown> = {
|
||||
style: { width: '100%' },
|
||||
}
|
||||
// switch/radio/checkbox/select 默认值
|
||||
if (jnpfKey === 'switch') defaults.defaultValue = 0
|
||||
if (jnpfKey === 'checkbox') defaults.defaultValue = []
|
||||
if (jnpfKey === 'cascader') defaults.defaultValue = []
|
||||
if (jnpfKey === 'rate' || jnpfKey === 'slider') defaults.defaultValue = 0
|
||||
|
||||
const { __config__: _drop, ...restUser } = props
|
||||
return {
|
||||
...defaults,
|
||||
...restUser,
|
||||
__config__: finalConfig,
|
||||
} as JnpfField
|
||||
}
|
||||
|
||||
/**
|
||||
* 便利: 构造 regList 条目 (引用 L1 正则).
|
||||
* @example
|
||||
* fb.regList('chinese', '请输入中文')
|
||||
* → { pattern: 'chinese', message: '请输入中文' }
|
||||
*/
|
||||
regList(name: string, customMsg?: string): { pattern: string; message: string } {
|
||||
const r = this.validationRules[name]
|
||||
if (!r) throw new Error(`Unknown L1 rule: '${name}'. 可用: ${this.validationRuleKeys().join(', ')}`)
|
||||
return { pattern: name, message: customMsg || r.msg }
|
||||
}
|
||||
}
|
||||
|
||||
/** 全局单例 (复用已加载的 JSON) */
|
||||
let _defaultBuilder: FieldBuilder | null = null
|
||||
export function defaultFieldBuilder(): FieldBuilder {
|
||||
if (!_defaultBuilder) _defaultBuilder = new FieldBuilder()
|
||||
return _defaultBuilder
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* schema/index.ts — FieldBuilder 入口
|
||||
*
|
||||
* 用法:
|
||||
* import { FieldBuilder, defaultFieldBuilder, type JnpfField } from '../schema/index.ts'
|
||||
*
|
||||
* const fb = defaultFieldBuilder()
|
||||
* const field = fb.build('input', { label: '姓名', __config__: { required: true } })
|
||||
*/
|
||||
export * from './FieldBuilder.ts'
|
||||
Reference in new issue
Block a user