feat(p3-commands): v0.11e+ Phase D1 org/msg/datasource step machine

新建 3 _validate.ts (P3 命令 step machine 扩展):
- org/_validate.ts (1 step, 镜像 web organize/Form.vue + 后端 OrganizeController + PS036 层级限制)
- msg/_validate.ts (1 step, 镜像 web message/notice/Form.vue + 后端 MessageController + MSERR114 系统编码规则 + 4 种消息类型)
- datasource/_validate.ts (1 step, 镜像 web dataSource/Form.vue + 后端 DbLinkController + DB001 数据库类型 + host/port/user/password 必填)

每个 _validate.ts 完整导出:
- ValidationError + StepValidation interface
- validateBasicInfo
- validate<Datasource>Create

镜像 web 端:
- organize/Form.vue PS013 (parentId 必填, 不能与父级相同) / PS036 (层级限制)
- message/notice/Form.vue MSERR113/114 (模板标题参数 + 系统编码规则)
- dataSource/Form.vue DB001 (6 种数据库类型枚举)

未集成到 create.ts (P3 命令大, 留待后续 session 集成)
This commit is contained in:
ssw committed 2026-06-27 03:24:51 +08:00
1 parent 2b24a487a2
commit f3bd0cc088
3 files changed
+272

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
/**
* commands/msg/_validate.ts — msg notice/template create/update step machine (Phase D1)
*
* 镜像 web message/notice/Form.vue + message/template/Form.vue + 后端 MessageController
* - fullName 必填
* - enCode 必填
* - type ∈ {1=系统, 2=消息中心, 3=邮件, 4=短信}
* - MSERR113/114 镜像: 模板标题参数 + 系统编码规则
*
* v0.11e+ Phase D1: 剩余 40 命令 step machine 扩展
*/
export interface ValidationError {
field?: string
message: string
code?: string
}
export interface StepValidation {
ok: boolean
step: 0
stepName: string
errors: ValidationError[]
}
export interface MsgOpts {
fullName?: string
enCode?: string
type?: number | string
category?: string
enabledMark?: number | string
}
const VALID_TYPES = [1, 2, 3, 4]
export function validateBasicInfo(opts: MsgOpts): StepValidation {
const errors: ValidationError[] = []
if (!opts.fullName || !String(opts.fullName).trim()) {
errors.push({ field: 'fullName', message: '消息标题不能为空' })
}
if (!opts.enCode || !String(opts.enCode).trim()) {
errors.push({ field: 'enCode', message: '消息编码不能为空' })
} else if (String(opts.enCode).startsWith('sys_') || String(opts.enCode).startsWith('system_')) {
// MSERR114 镜像: 自定义模板编码不能使用系统模板编码规则
errors.push({
field: 'enCode',
message: '消息编码不能以 sys_/system_ 开头 (MSERR114, 保留系统模板编码)',
code: 'MSERR114',
})
}
if (opts.type !== undefined && !VALID_TYPES.includes(Number(opts.type))) {
errors.push({
field: 'type',
message: `消息类型必须是 ${VALID_TYPES.join('/')} 之一 (1=系统 2=消息中心 3=邮件 4=短信), 当前 ${opts.type}`,
})
}
if (opts.enabledMark !== undefined && ![0, 1].includes(Number(opts.enabledMark))) {
errors.push({ field: 'enabledMark', message: 'enabledMark 必须是 0 或 1' })
}
return {
ok: errors.length === 0,
step: 0,
stepName: '基础信息',
errors,
}
}
export function validateMsgCreate(opts: MsgOpts): {
ok: boolean
steps: StepValidation[]
} {
const s0 = validateBasicInfo(opts)
return { ok: s0.ok, steps: [s0] }
}
export function validateMsgUpdate(opts: MsgOpts): {
ok: boolean
steps: StepValidation[]
} {
return validateMsgCreate(opts)
}