From 20e4400cff2f1601f114d665e901ff53af456858 Mon Sep 17 00:00:00 2001 From: Cano1997 <1978141412@qq.com> Date: Wed, 23 Aug 2023 20:00:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=83=A8=E4=BB=B6=E9=A1=B9=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=80=BC=E8=A7=84=E5=88=99=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../form-mdctrl-content-type.controller.ts | 11 +++++++ .../form-mdctrl-form.controller.ts | 16 ++++++++++ .../form-mdctrl-grid.controller.ts | 17 +++++++++++ ...orm-mdctrl-repeater-form-one.controller.ts | 29 ++++++++++++++++++- .../form-mdctrl-repeater-form.controller.ts | 29 ++++++++++++++++++- .../form-mdctrl/form-mdctrl.controller.ts | 22 ++++++++++++++ src/control/form/form/form.controller.ts | 5 +++- 8 files changed, 127 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ae3b455..7bd8b706b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - 支持分割面板容器 - 非路由打开视图标题样式调整 - 图表默认size改为1000 +- 表单多数据部件项支持值规则校验 ### Fixed 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 920039704..c2a232487 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 a1e5ce1f0..43a0fe36c 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 @@ -198,4 +198,20 @@ export class FormMDCtrlFormController extends FormMDCtrlControlController { 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 b8567a044..53173678e 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 @@ -117,4 +117,21 @@ export class FormMDCtrlGridController extends FormMDCtrlControlController { this.parent.state.contentCtrlData = this.gridController.state.items; this.parent.setFormDataValue(); } + + /** + * 表单项值规则校验 + * + * @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 1d014ee19..10822ed3e 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 cf0331e1f..2eb4d840b 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 8f2cd6e79..7b2c1d204 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 6fdee5034..454bb1d37 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); } // 有子成员的生成子控制器 -- Gitee From 48f4cdbc929f0373408178180ab75237ae784434 Mon Sep 17 00:00:00 2001 From: Cano1997 <1978141412@qq.com> Date: Wed, 23 Aug 2023 20:03:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E9=A1=B9=E5=BC=95=E7=94=A8=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=96=B0=E5=A2=9E=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../form-mdctrl-grid.controller.ts | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bd8b706b..cfa55c99f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ ### Fixed - 修复预置直接内容数据渲染不出来问题 +- 修复表单多数据项引用表格新增无效 ### Changed 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 53173678e..8099867e8 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'; /** @@ -118,6 +123,28 @@ export class FormMDCtrlGridController extends FormMDCtrlControlController { 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; + } + } + /** * 表单项值规则校验 * -- Gitee From d476849004b401a2223f89e5c93640d1fd054dee Mon Sep 17 00:00:00 2001 From: Cano1997 <1978141412@qq.com> Date: Wed, 23 Aug 2023 20:06:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=A4=9A=E6=95=B0=E6=8D=AE=E9=A1=B9=E5=BC=95=E7=94=A8=E8=A1=A8?= =?UTF-8?q?=E5=8D=95srfkey=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../form-mdctrl-form.controller.ts | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfa55c99f..f86d1f271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - 修复预置直接内容数据渲染不出来问题 - 修复表单多数据项引用表格新增无效 +- 修复表单多数据项引用表单srfkey异常 ### Changed 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 43a0fe36c..a607ff997 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,13 +191,22 @@ 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(); + } } /** -- Gitee