diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ae3b455743bdc07ca7a944a2c6aeeefd5d4142..f86d1f27150af629b9c0829c7ed67e155b25a2f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,13 @@ - 支持分割面板容器 - 非路由打开视图标题样式调整 - 图表默认size改为1000 +- 表单多数据部件项支持值规则校验 ### Fixed - 修复预置直接内容数据渲染不出来问题 +- 修复表单多数据项引用表格新增无效 +- 修复表单多数据项引用表单srfkey异常 ### Changed diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl-content-type.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl-content-type.controller.ts index 920039704427d2b6918a0ea5a22ae4e86aa13075..c2a23248773ab28a06784ccadde81bd0ed055673 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl-content-type.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl-content-type.controller.ts @@ -124,4 +124,15 @@ export class FormMDCtrlContentTypeController { } } } + + /** + * 表单项值规则校验 + * + * @author zzq + * @date 2023-08-23 16:33:32 + * @memberof FormMDCtrlContentTypeController + */ + async validate(): Promise { + return true; + } } diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl-form/form-mdctrl-form.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl-form/form-mdctrl-form.controller.ts index a1e5ce1f0d457b5ea0cef3be16ae87f35121869b..a607ff9972f439c0025f9b9592fb158ccbcf2949 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl-form/form-mdctrl-form.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl-form/form-mdctrl-form.controller.ts @@ -1,4 +1,4 @@ -import { IHttpResponse } from '@ibiz-template/core'; +import { IHttpResponse, mergeInLeft } from '@ibiz-template/core'; import { ControlVO, EventBase, @@ -27,7 +27,7 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { * @type {IGridController} * @memberof FormMDCtrlGridController */ - controlControllerArray: IEditFormController[] | null[] = []; + controlControllerArray: IEditFormController[] = []; /** * uiState @@ -123,7 +123,7 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { * * @author zk * @date 2023-07-30 08:07:32 - * @memberof FormMDCtrlContentTypeController + * @memberof FormMDCtrlFormController */ async initData(): Promise { const res = await this.fetch( @@ -165,7 +165,7 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { } c.save(); if (this.state.data[index]) { - this.state.data[index] = data[0]; + mergeInLeft(this.state.data[index], data[0]); } this.parent.state.contentCtrlData = this.state.data; this.parent.setFormDataValue(); @@ -181,6 +181,7 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { */ onFormRemoveSuccess(index: number): void { this.state.data.splice(index, 1); + this.controlControllerArray.splice(index, 1); this.parent.state.contentCtrlData = this.state.data; this.parent.setFormDataValue(); } @@ -190,12 +191,37 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { * * @author zk * @date 2023-07-31 12:07:27 - * @param {IData} [data] - * @memberof FormMDCtrlContentTypeController + * @memberof FormMDCtrlFormController */ - onDataInsert(): void { - this.state.data.push({}); - this.parent.state.contentCtrlData = this.state.data; - this.parent.setFormDataValue(); + async onDataInsert(): Promise { + const res = await this.service.getDraft( + this.parent.form.context, + this.parent.form.params, + ); + if (res.data) { + const result = await this.service.create( + this.parent.form.context, + res.data, + ); + this.state.data.push(result.data); + this.parent.state.contentCtrlData = this.state.data; + this.parent.setFormDataValue(); + } + } + + /** + * 表单项值规则校验 + * + * @author zzq + * @date 2023-08-23 16:33:32 + * @memberof FormMDCtrlFormController + */ + async validate(): Promise { + const values = await Promise.all( + this.controlControllerArray.map(form => form.validate()), + ); + + // 找不到value为false即全部是true + return values.findIndex(value => !value) === -1; } } diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl-grid/form-mdctrl-grid.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl-grid/form-mdctrl-grid.controller.ts index b8567a044121b5225a8d656218b260af6c3d8419..8099867e85967c3a57790af43481efe346587f8e 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl-grid/form-mdctrl-grid.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl-grid/form-mdctrl-grid.controller.ts @@ -1,4 +1,9 @@ -import { EventBase, IGridController } from '@ibiz-template/runtime'; +import { + EventBase, + IGridController, + getControlProvider, +} from '@ibiz-template/runtime'; +import { RuntimeError, mergeInLeft } from '@ibiz-template/core'; import { FormMDCtrlControlController } from '../form-mdctrl-control/form-mdctrl-control.controller'; /** @@ -117,4 +122,43 @@ export class FormMDCtrlGridController extends FormMDCtrlControlController { this.parent.state.contentCtrlData = this.gridController.state.items; this.parent.setFormDataValue(); } + + /** + * 初始化, 表格默认支持行编辑、行编辑 + * + * @author zzq + * @date 2023-08-23 15:41:27 + * @param {IData} [data] + * @memberof FormMDCtrlContentTypeController + */ + public async onInit(): Promise { + const model = this.parent.model; + const contentControl = model.contentControl; + if (!contentControl) { + throw new RuntimeError('表单多数据部件未配置嵌入部件'); + } + mergeInLeft(contentControl, { enableRowEdit: true, enableRowNew: true }); + this.controlModel = contentControl; + const controlProvider = await getControlProvider(this.controlModel); + if (controlProvider) { + this.provider = controlProvider; + } + } + + /** + * 表单项值规则校验 + * + * @author zzq + * @date 2023-08-23 16:33:32 + * @memberof FormMDCtrlFormController + */ + async validate(): Promise { + const rows = this.gridController.state.rows; + const values = await Promise.all( + rows.map(row => this.gridController.validate(row)), + ); + + // 找不到value为false即全部是true + return values.findIndex(value => !value) === -1; + } } diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form-one/form-mdctrl-repeater-form-one.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form-one/form-mdctrl-repeater-form-one.controller.ts index 1d014ee19b34f085a7191624a6fbe59e11a8faf7..10822ed3e13372ab702bd9c9daf8295016412229 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form-one/form-mdctrl-repeater-form-one.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form-one/form-mdctrl-repeater-form-one.controller.ts @@ -11,6 +11,7 @@ import { FormController } from '../../../../form'; import { FormGroupPanelController } from '../../../form-group-panel'; import { FormMDCtrlContentTypeController } from '../../form-mdctrl-content-type.controller'; import { FormMDCtrlItemController } from '../form-mdctrl-repeater-form/form-mdctrl-repeater-form-item.controller'; +import { FormItemController } from '../../../form-item'; /** * 表单多数据部件表格类型控制器 @@ -44,7 +45,11 @@ export class FormMDCtrlRepeaterFormOneController extends FormMDCtrlContentTypeCo * @type {Array>} * @memberof FormMDCtrlController */ - formDetail: Array<{ name: string; c: IFormDetailController }> = []; + formDetail: Array<{ + name: string; + detailType: string; + c: IFormDetailController; + }> = []; private formCtx!: CTX; @@ -98,6 +103,7 @@ export class FormMDCtrlRepeaterFormOneController extends FormMDCtrlContentTypeCo } this.formDetail.push({ name: detail.id!, + detailType: detail.detailType!, c: detailController, }); // 有子成员的生成子控制器 @@ -149,4 +155,25 @@ export class FormMDCtrlRepeaterFormOneController extends FormMDCtrlContentTypeCo this.parent.state.contentCtrlData = data; this.parent.setFormDataValue(); } + + /** + * 表单值校验 + * + * @author zzq + * @date 2023-08-23 19:07:11 + * @memberof FormMDCtrlController + */ + async validate(): Promise { + const values: Promise[] = []; + this.formDetail.forEach(detail => { + if (detail.detailType === 'FORMITEM') { + const c = detail.c as FormItemController; + values.push(c.validate()); + } + }); + + const results = await Promise.all(values); + // 找不到value为false即全部是true + return results.findIndex(value => !value) === -1; + } } diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form/form-mdctrl-repeater-form.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form/form-mdctrl-repeater-form.controller.ts index cf0331e1fafd3761bccfd0487d97809d2f613897..2eb4d840bcca6933f0651ffbbf07fc942e249d5b 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form/form-mdctrl-repeater-form.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl-repeater/form-mdctrl-repeater-form/form-mdctrl-repeater-form.controller.ts @@ -11,6 +11,7 @@ import { FormController } from '../../../../form'; import { FormGroupPanelController } from '../../../form-group-panel'; import { FormMDCtrlContentTypeController } from '../../form-mdctrl-content-type.controller'; import { FormMDCtrlItemController } from './form-mdctrl-repeater-form-item.controller'; +import { FormItemController } from '../../../form-item'; /** * 表单多数据部件表格类型控制器 @@ -31,7 +32,9 @@ export class FormMDCtrlRepeaterFormController extends FormMDCtrlContentTypeContr * @type {Array>} * @memberof FormMDCtrlController */ - formDetails: Array> = []; + formDetails: Array< + Array<{ name: string; detailType: string; c: IFormDetailController }> + > = []; /** * 表单ctx @@ -103,6 +106,7 @@ export class FormMDCtrlRepeaterFormController extends FormMDCtrlContentTypeContr } this.formDetails[index].push({ name: detail.id!, + detailType: detail.detailType!, c: detailController, }); // 有子成员的生成子控制器 @@ -184,4 +188,27 @@ export class FormMDCtrlRepeaterFormController extends FormMDCtrlContentTypeContr ); this.state.isInit = true; } + + /** + * 表单项值规则校验 + * + * @author zzq + * @date 2023-08-23 17:21:37 + * @memberof FormMDCtrlRepeaterFormController + */ + async validate(): Promise { + const values: Promise[] = []; + this.formDetails.forEach(details => { + details.forEach(detail => { + if (detail.detailType === 'FORMITEM') { + const c = detail.c as FormItemController; + values.push(c.validate()); + } + }); + }); + + const results = await Promise.all(values); + // 找不到value为false即全部是true + return results.findIndex(value => !value) === -1; + } } diff --git a/src/control/form/form-detail/form-mdctrl/form-mdctrl.controller.ts b/src/control/form/form-detail/form-mdctrl/form-mdctrl.controller.ts index 8f2cd6e797800feaaba163844cda9797e43062e9..7b2c1d2046ffb6b5289958e94dcc47b1542b1fbc 100644 --- a/src/control/form/form-detail/form-mdctrl/form-mdctrl.controller.ts +++ b/src/control/form/form-detail/form-mdctrl/form-mdctrl.controller.ts @@ -128,4 +128,26 @@ export class FormMDCtrlController extends FormDetailController { async loadData(): Promise { await this.mdCtrlContentController.initData(); } + + /** + * 表单校验,通知子表单进行校验 + * + * @author zzq + * @date 2023-08-23 11:07:09 + * @memberof FormMDCtrlController + */ + async validate(): Promise { + return this.mdCtrlContentController.validate(); + } + + /** + * 设置默认值 + * + * @author zzq + * @date 2023-08-23 19:00:09 + * @memberof FormMDCtrlController + */ + setDefaultValue(): void { + // todo 设置默认值 + } } diff --git a/src/control/form/form/form.controller.ts b/src/control/form/form/form.controller.ts index 6fdee5034fb4b1455ce94f9b573c9479b3153529..454bb1d374edd1dc9dde11996fc27038d3f58663 100644 --- a/src/control/form/form/form.controller.ts +++ b/src/control/form/form/form.controller.ts @@ -180,7 +180,10 @@ export abstract class FormController< parent, ); form.details[detail.id!] = detailController; - if (detail.detailType === 'FORMITEM') { + if ( + detail.detailType === 'FORMITEM' || + detail.detailType === 'MDCTRL' + ) { form.formItems.push(detailController as FormItemController); } // 有子成员的生成子控制器