feat(bigscreen/portal/report): v0.11e+ Phase B1 完整设计 step machine
新建 3 个 _validate.ts (Phase B1 web Form.vue 镜像):
- portal/_validate.ts (2 step: 基础信息 + BS-47 唯一性, 镜像 web visualPortal/Form.vue:28-100)
- bigscreen/_validate.ts (2 step, 镜像 web bigScreen/Form.vue)
- report/_validate.ts (1 step, 预留 create 命令基础信息校验)
集成 2 create 命令:
- portal/create.ts: 跑 step machine + catch enhanceFromBackend (A1 复用)
- 加 --type/--platformType/--link 选项 (镜像 web visualPortal/Form.vue:55-105)
- bigscreen/create.ts: 跑 step machine + catch enhanceFromBackend
镜像源:
- web visualPortal/Form.vue:32-37 fullName 必填
- web visualPortal/Form.vue:39-44 enCode 必填 + formValidate.ts:24-28 正则
- web visualPortal/Form.vue:46-51 category 必填
- web visualPortal/Form.vue:55-67 type ∈ {0,1}
- web visualPortal/Form.vue:75-87 platformType ∈ {0,1}
- web visualPortal/Form.vue:90-105 link 必填 (type=1)
report/ 暂无 create.ts (templates.ts 已实现), _validate.ts 预留
bigscreen/update.ts 也复用 _validate.ts (同 create)
This commit is contained in:
1 parent
fefa6014a0
commit
0dbefddf64
5 files changed
+393
-2
No files matched your search
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* commands/bigscreen/_validate.ts — bigscreen create/update step machine 校验 (Phase B1)
|
||||
*
|
||||
* 镜像 web bigScreen/Form.vue schemas + handleSubmit (BS-47 全平台唯一性)
|
||||
* 注: bigScreen 模板数据复杂, dacli 简化基础信息校验 (fullName/enCode/category)
|
||||
* - 完整模板设计在 web designer, dacli 不镜像 (太复杂 + AI 不需要)
|
||||
*
|
||||
* v0.11e+ Phase B1: 完整设计 + step machine 镜像
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
/** v0.11e+: ErrorCode */
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0 | 1
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
/** enCode 正则 — 镜像 web formValidate.ts:24-28 */
|
||||
const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i
|
||||
|
||||
export interface BigscreenOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
category?: string
|
||||
/** 已存在 enCodes (BS-47 唯一性预校验) */
|
||||
existingEnCodes?: string[]
|
||||
/** 编辑模式: 当前 bigscreen id */
|
||||
currentId?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* step 0: 基础信息校验
|
||||
*/
|
||||
export function validateBasicInfo(opts: BigscreenOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '大屏名称不能为空' })
|
||||
} else if (String(opts.fullName).length > 50) {
|
||||
errors.push({ field: 'fullName', message: '大屏名称不能超过 50 个字符' })
|
||||
}
|
||||
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '大屏编码不能为空' })
|
||||
} else if (String(opts.enCode).length > 50) {
|
||||
errors.push({ field: 'enCode', message: '大屏编码不能超过 50 个字符' })
|
||||
} else if (!ENCODE_REGEXP.test(String(opts.enCode))) {
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: '只能输入英文、数字和小数点且小数点不能放在首尾',
|
||||
code: 'VS030',
|
||||
})
|
||||
}
|
||||
|
||||
if (!opts.category || !String(opts.category).trim()) {
|
||||
errors.push({ field: 'category', message: '大屏分类不能为空' })
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* step 1: 全平台唯一性预校验 (BS-47)
|
||||
*
|
||||
* 镜像 web Selector + 后端 BigScreenController L186-201
|
||||
*/
|
||||
export function validateUniqueness(opts: BigscreenOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.existingEnCodes || opts.existingEnCodes.length === 0) {
|
||||
return { ok: true, step: 1, stepName: '唯一性', errors: [] }
|
||||
}
|
||||
|
||||
if (opts.enCode && opts.existingEnCodes.includes(String(opts.enCode))) {
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: `大屏编码"${opts.enCode}"已存在 (BS-47, 后端 EXIST002)`,
|
||||
code: 'EXIST002',
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 1,
|
||||
stepName: '唯一性',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateBigscreenCreate(opts: BigscreenOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
const s1 = validateUniqueness(opts)
|
||||
return { ok: s0.ok && s1.ok, steps: [s0, s1] }
|
||||
}
|
||||
|
||||
export function validateBigscreenUpdate(opts: BigscreenOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
return validateBigscreenCreate(opts)
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { validateBigscreenCreate } from './_validate.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
@@ -26,6 +28,23 @@ export function buildBigscreenCreateCommand(): Command {
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// v0.11e+ Phase B1: step machine 校验 (2 step, fullName/enCode/category + BS-47 唯一性)
|
||||
const validation = validateBigscreenCreate({
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
category: opts.category,
|
||||
})
|
||||
if (!validation.ok) {
|
||||
for (const s of validation.steps) {
|
||||
for (const e of s.errors) {
|
||||
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
|
||||
}
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
|
||||
|
||||
const body = {
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
@@ -37,7 +56,8 @@ export function buildBigscreenCreateCommand(): Command {
|
||||
}
|
||||
const r = await c.postJson<{ id?: string }>('/extend/BigData', body)
|
||||
if (r.code !== 200) {
|
||||
log.error(`bigscreen create 失败 (code=${r.code}): ${r.msg}`)
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'bigscreen', { entity: 'bigscreen' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
let id = r.data?.id
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* commands/portal/_validate.ts — portal create step machine 校验 (Phase B1)
|
||||
*
|
||||
* 镜像 web visualPortal/Form.vue:28-100 schemas + handleSubmit (L150-180)
|
||||
* - fullName 必填 (L32-37)
|
||||
* - enCode 必填 + formValidate 正则 (L39-44)
|
||||
* - category 必填 (L46-51)
|
||||
* - type 必填 ∈ {0=页面, 1=外链} (L55-67)
|
||||
* - platformType 必填 ∈ {0=门户设计, 1=配置路径} (L75-87)
|
||||
* - link 必填 (type=1 外链时, L90-105)
|
||||
*
|
||||
* v0.11e+ Phase B1: 完整设计 + step machine 镜像
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
/** v0.11e+: ErrorCode (镜像后端 MsgCode.java) */
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0 | 1
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
/** enCode 正则 — 镜像 web formValidate.ts:24-28 */
|
||||
const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i
|
||||
|
||||
/** 合法 type 值 */
|
||||
const VALID_TYPES = [0, 1]
|
||||
|
||||
/** 合法 platformType 值 */
|
||||
const VALID_PLATFORM_TYPES = [0, 1]
|
||||
|
||||
export interface PortalOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
category?: string
|
||||
type?: number | string
|
||||
platformType?: number | string
|
||||
link?: string
|
||||
/** portal 关联 form id (web Form.vue:139 formId 选择) */
|
||||
formId?: string
|
||||
/** 已存在 enCodes (BS-47 唯一性预校验) */
|
||||
existingEnCodes?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* step 0: 基础信息校验
|
||||
*
|
||||
* 镜像 web visualPortal/Form.vue:28-100 schemas
|
||||
*/
|
||||
export function validateBasicInfo(opts: PortalOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
// 镜像 Form.vue:32-37 fullName
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '门户名称不能为空' })
|
||||
} else if (String(opts.fullName).length > 50) {
|
||||
errors.push({ field: 'fullName', message: '门户名称不能超过 50 个字符' })
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:39-44 enCode + formValidate.ts:24-28
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '门户编码不能为空' })
|
||||
} else if (String(opts.enCode).length > 50) {
|
||||
errors.push({ field: 'enCode', message: '门户编码不能超过 50 个字符' })
|
||||
} else if (!ENCODE_REGEXP.test(String(opts.enCode))) {
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: '只能输入英文、数字和小数点且小数点不能放在首尾',
|
||||
code: 'VS030',
|
||||
})
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:46-51 category
|
||||
if (!opts.category || !String(opts.category).trim()) {
|
||||
errors.push({ field: 'category', message: '门户分类不能为空' })
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:55-67 type
|
||||
if (opts.type !== undefined && !VALID_TYPES.includes(Number(opts.type))) {
|
||||
errors.push({
|
||||
field: 'type',
|
||||
message: `门户类型必须是 ${VALID_TYPES.join('/')} 之一 (0=页面 1=外链), 当前 ${opts.type}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:75-87 platformType
|
||||
if (opts.platformType !== undefined && !VALID_PLATFORM_TYPES.includes(Number(opts.platformType))) {
|
||||
errors.push({
|
||||
field: 'platformType',
|
||||
message: `平台类型必须是 ${VALID_PLATFORM_TYPES.join('/')} 之一 (0=门户设计 1=配置路径), 当前 ${opts.platformType}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 镜像 Form.vue:90-105 link 必填 (type=1 外链时)
|
||||
if (Number(opts.type) === 1 && (!opts.link || !String(opts.link).trim())) {
|
||||
errors.push({ field: 'link', message: 'type=1 (外链) 时链接地址必填' })
|
||||
} else if (Number(opts.type) === 1 && opts.link && !/^https?:\/\//.test(String(opts.link))) {
|
||||
errors.push({ field: 'link', message: '外链必须以 http:// 或 https:// 开头' })
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* step 1: 全平台唯一性预校验 (BS-47)
|
||||
*
|
||||
* 镜像 web Selector + 后端 PortalController L186-201
|
||||
* - enCode 全平台唯一 → EXIST002
|
||||
* - fullName 全平台唯一 → EXIST001
|
||||
*/
|
||||
export function validateUniqueness(opts: PortalOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.existingEnCodes || opts.existingEnCodes.length === 0) {
|
||||
return { ok: true, step: 1, stepName: '唯一性', errors: [] }
|
||||
}
|
||||
|
||||
if (opts.enCode && opts.existingEnCodes.includes(String(opts.enCode))) {
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: `门户编码"${opts.enCode}"已存在 (BS-47, 后端 EXIST002)`,
|
||||
code: 'EXIST002',
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 1,
|
||||
stepName: '唯一性',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
/** 跑全部 step 校验 */
|
||||
export function validatePortalCreate(opts: PortalOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
const s1 = validateUniqueness(opts)
|
||||
return { ok: s0.ok && s1.ok, steps: [s0, s1] }
|
||||
}
|
||||
@@ -9,12 +9,17 @@ import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { validatePortalCreate } from './_validate.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
enCode: string
|
||||
category: string
|
||||
platform?: string
|
||||
type?: string
|
||||
platformType?: string
|
||||
link?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
@@ -25,9 +30,33 @@ export function buildPortalCreateCommand(): Command {
|
||||
.requiredOption('--enCode <code>', '门户编码')
|
||||
.requiredOption('--category <cat>', '分类: 1=经典门户 2=全屏门户')
|
||||
.option('--platform <p>', '平台: Web/App/PC', 'Web')
|
||||
// v0.11e+ Phase B1: step machine 字段 (镜像 web visualPortal/Form.vue:55-105)
|
||||
.option('--type <t>', '门户类型: 0=页面 1=外链 (镜像 Form.vue:55-67)')
|
||||
.option('--platformType <t>', '平台类型: 0=门户设计 1=配置路径 (镜像 Form.vue:75-87)')
|
||||
.option('--link <url>', '外链 URL (type=1 必填, 镜像 Form.vue:90-105)')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// v0.11e+ Phase B1: step machine 校验 (2 step 镜像 web visualPortal/Form.vue:28-100 + L150-180 handleSubmit)
|
||||
const validation = validatePortalCreate({
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
category: opts.category,
|
||||
type: opts.type,
|
||||
platformType: opts.platformType,
|
||||
link: opts.link,
|
||||
})
|
||||
if (!validation.ok) {
|
||||
for (const s of validation.steps) {
|
||||
for (const e of s.errors) {
|
||||
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
|
||||
}
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
|
||||
|
||||
const body = {
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
@@ -40,7 +69,8 @@ export function buildPortalCreateCommand(): Command {
|
||||
}
|
||||
const r = await c.postJson<{ id?: string }>('/visualdev/Portal', body)
|
||||
if (r.code !== 200) {
|
||||
log.error(`portal create 失败 (code=${r.code}): ${r.msg}`)
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
let id = r.data?.id
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* commands/report/_validate.ts — report create step machine 校验 (Phase B1)
|
||||
*
|
||||
* 镜像 web report/Form.vue schemas (大屏报表 + 打印模板)
|
||||
* 注: report 命令目前只有 templates.ts (v0.11+ 已实现), 暂无 create.ts
|
||||
* 这里为未来 create 命令预留 step machine 模式
|
||||
*
|
||||
* v0.11e+ Phase B1: 完整设计 + step machine 镜像
|
||||
*/
|
||||
|
||||
export interface ValidationError {
|
||||
field?: string
|
||||
message: string
|
||||
/** v0.11e+: ErrorCode */
|
||||
code?: string
|
||||
}
|
||||
|
||||
export interface StepValidation {
|
||||
ok: boolean
|
||||
step: 0
|
||||
stepName: string
|
||||
errors: ValidationError[]
|
||||
}
|
||||
|
||||
/** enCode 正则 — 镜像 web formValidate.ts:24-28 */
|
||||
const ENCODE_REGEXP = /^[a-z0-9]((([a-z0-9])*)|(([a-z0-9]+|\.)*[a-z0-9]))$/i
|
||||
|
||||
export interface ReportOpts {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
category?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* step 0: 基础信息校验
|
||||
*
|
||||
* 镜像 web report/Form.vue schemas (fullName/enCode 必填)
|
||||
*/
|
||||
export function validateBasicInfo(opts: ReportOpts): StepValidation {
|
||||
const errors: ValidationError[] = []
|
||||
|
||||
if (!opts.fullName || !String(opts.fullName).trim()) {
|
||||
errors.push({ field: 'fullName', message: '报表名称不能为空' })
|
||||
} else if (String(opts.fullName).length > 50) {
|
||||
errors.push({ field: 'fullName', message: '报表名称不能超过 50 个字符' })
|
||||
}
|
||||
|
||||
if (!opts.enCode || !String(opts.enCode).trim()) {
|
||||
errors.push({ field: 'enCode', message: '报表编码不能为空' })
|
||||
} else if (!ENCODE_REGEXP.test(String(opts.enCode))) {
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: '只能输入英文、数字和小数点且小数点不能放在首尾',
|
||||
code: 'VS030',
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
ok: errors.length === 0,
|
||||
step: 0,
|
||||
stepName: '基础信息',
|
||||
errors,
|
||||
}
|
||||
}
|
||||
|
||||
export function validateReportCreate(opts: ReportOpts): {
|
||||
ok: boolean
|
||||
steps: StepValidation[]
|
||||
} {
|
||||
const s0 = validateBasicInfo(opts)
|
||||
return { ok: s0.ok, steps: [s0] }
|
||||
}
|
||||
Reference in new issue
Block a user