From f0884182ea512adb9365edc07aec4e959eff9141 Mon Sep 17 00:00:00 2001 From: zhangkang <57750083+zhangkang1314@users.noreply.github.com> Date: Thu, 1 Jun 2023 21:13:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=9D=E5=AD=98=E5=B9=B6=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=20&=20=E5=88=A0=E9=99=A4=E5=B9=B6=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../caption-bar/caption-bar.controller.ts | 6 +-- .../form/edit-form/edit-form.controller.ts | 37 +++++++++++++++---- .../form-item/form-item.controller.ts | 18 ++++----- src/control/form/form/form.controller.ts | 12 ++---- .../search-form/search-form.controller.ts | 6 +-- src/control/grid/grid/grid.scss | 22 ++++++----- src/view-engine/edit-view.engine.ts | 30 +++++++++++++-- 7 files changed, 88 insertions(+), 43 deletions(-) diff --git a/src/control/caption-bar/caption-bar.controller.ts b/src/control/caption-bar/caption-bar.controller.ts index d4eb546c..ae4c112e 100644 --- a/src/control/caption-bar/caption-bar.controller.ts +++ b/src/control/caption-bar/caption-bar.controller.ts @@ -28,9 +28,9 @@ export class CaptionBarController await super.doCreated(); this.view.evt.on('onViewInfoChange', ({ caption: _caption, dataInfo }) => { - if (dataInfo) { - this.state.caption = `${this.state.caption}-${dataInfo}`; - } + this.state.caption = `${this.view.model.caption!}${ + dataInfo ? `-${dataInfo}` : '' + }`; }); } } diff --git a/src/control/form/edit-form/edit-form.controller.ts b/src/control/form/edit-form/edit-form.controller.ts index daa147c4..4989e6f4 100644 --- a/src/control/form/edit-form/edit-form.controller.ts +++ b/src/control/form/edit-form/edit-form.controller.ts @@ -1,4 +1,10 @@ -import { awaitTimeout, mergeInLeft, RuntimeError } from '@ibiz-template/core'; +import { + awaitTimeout, + IHttpResponse, + mergeInLeft, + RuntimeError, + mergeDefaultInLeft, +} from '@ibiz-template/core'; import { ControlVO, FormNotifyState, @@ -67,8 +73,9 @@ export class EditFormController const queryParams = { ...this.params }; // 新建默认值给到graft接口,接口会回来 + let params: IData = {}; if (this.isNewData) { - const params = await this.getDraftParams(); + params = await this.getDraftParams(); Object.assign(queryParams, params); } @@ -89,6 +96,8 @@ export class EditFormController this.state.data = res.data; } this.state.modified = false; + this.state.data = res.data; + mergeDefaultInLeft(this.data, params); this.formStateNotify( this.isNewData ? FormNotifyState.DRAFT : FormNotifyState.LOAD, ); @@ -146,19 +155,31 @@ export class EditFormController * @date 2022-09-01 09:09:36 * @returns {*} */ - async remove() { + async remove(): Promise { // 新建数据清空数据 + let res: IHttpResponse | undefined; + let ok: boolean = false; if (!this.isNewData) { - await this.startLoading(); - try { - await this.service.remove(this.context, this.params); - } finally { - await this.endLoading(); + ok = await ibiz.modal.confirm({ + title: '提示', + desc: '确认删除吗?', + }); + if (ok) { + await this.startLoading(); + try { + res = await this.service.remove(this.context, this.params); + } finally { + await this.endLoading(); + } + await this.evt.emit('onRemoveSuccess', undefined); + this.state.data = new ControlVO(); + ok = res.ok; } } await this.evt.emit('onRemoveSuccess', undefined); this.state.data = new ControlVO(); this.state.modified = false; + return ok; } /** diff --git a/src/control/form/form-detail/form-item/form-item.controller.ts b/src/control/form/form-detail/form-item/form-item.controller.ts index 9818611b..ad8ff057 100644 --- a/src/control/form/form-detail/form-item/form-item.controller.ts +++ b/src/control/form/form-detail/form-item/form-item.controller.ts @@ -326,13 +326,13 @@ export class FormItemController * @date 2022-09-15 22:09:52 * @param {boolean} isCreate 新建默认值还是更新默认值 */ - setDefaultValue(isCreate: boolean) { + setDefaultValue(isCreate: boolean, data: IData = this.data) { const { createDVT, createDV, updateDVT, updateDV } = this.model; const valueType = isCreate ? createDVT : updateDVT; const defaultValue = isCreate ? createDV : updateDV; // 置空 if (valueType === 'RESET') { - this.data[this.name] = null; + data[this.name] = null; return; } @@ -346,34 +346,34 @@ export class FormItemController } // 没有配类型,配了默认值的直接赋值默认值 if (!valueType && defaultValue) { - this.data[this.name] = defaultValue; + data[this.name] = defaultValue; return; } switch (valueType) { // 当前应用数据,优先取视图参数,视图参数没有取上下文 case 'APPDATA': if (Object.prototype.hasOwnProperty.call(this.context, defaultValue!)) { - this.data[this.name] = this.context[defaultValue!]; + data[this.name] = this.context[defaultValue!]; } if (Object.prototype.hasOwnProperty.call(this.params, defaultValue!)) { - this.data[this.name] = this.params[defaultValue!]; + data[this.name] = this.params[defaultValue!]; } break; // 当前操作用户(名称) case 'OPERATORNAME': - this.data[this.name] = this.context.srfusername; + data[this.name] = this.context.srfusername; break; // 当前操作用户(编号) case 'OPERATOR': - this.data[this.name] = this.context.srfuserid; + data[this.name] = this.context.srfuserid; break; // 当前时间 case 'CURTIME': - this.data[this.name] = dayjs().format(this.model.valueFormat); + data[this.name] = dayjs().format(this.model.valueFormat); break; // 数据对象属性 case 'PARAM': - this.data[this.name] = this.data[defaultValue!]; + data[this.name] = this.data[defaultValue!]; break; default: ibiz.message.error(`[${valueType}]类型默认值未支持`); diff --git a/src/control/form/form/form.controller.ts b/src/control/form/form/form.controller.ts index 20eb9b42..1788770d 100644 --- a/src/control/form/form/form.controller.ts +++ b/src/control/form/form/form.controller.ts @@ -14,7 +14,6 @@ import { isValueChange, } from '@ibiz-template/runtime'; import { IDEForm, IDEFormDetail, IDEFormGroupPanel } from '@ibiz/model-core'; -import { isNil } from 'lodash-es'; import { FormGroupPanelController, FormItemController } from '../form-detail'; /** @@ -147,13 +146,10 @@ export abstract class FormController< * @return {*} */ async getDraftParams() { - await Promise.all(this.formItems.map(item => item.setDefaultValue(true))); - const result: IParams = {}; - Object.keys(this.data).forEach(key => { - if (!isNil(this.data[key])) { - result[key] = this.data[key]; - } - }); + const result: IData = {}; + await Promise.all( + this.formItems.map(item => item.setDefaultValue(true, result)), + ); return result; } diff --git a/src/control/form/search-form/search-form.controller.ts b/src/control/form/search-form/search-form.controller.ts index d2c8ac6c..784a0796 100644 --- a/src/control/form/search-form/search-form.controller.ts +++ b/src/control/form/search-form/search-form.controller.ts @@ -1,4 +1,4 @@ -import { mergeInLeft } from '@ibiz-template/core'; +import { mergeDefaultInLeft } from '@ibiz-template/core'; import { FormNotifyState, ISearchFormController, @@ -61,8 +61,8 @@ export class SearchFormController Object.assign(queryParams, params); const res = await this.service.getDraft(this.context, queryParams); - // !getDraft的时候不替换,进行合并,空值不覆盖 - mergeInLeft(this.data, res.data); + this.state.data = res.data; + mergeDefaultInLeft(this.data, params); this.state.isLoaded = true; this.formStateNotify(FormNotifyState.DRAFT); return this.data; diff --git a/src/control/grid/grid/grid.scss b/src/control/grid/grid/grid.scss index a128981a..94f2107a 100644 --- a/src/control/grid/grid/grid.scss +++ b/src/control/grid/grid/grid.scss @@ -18,17 +18,23 @@ @include e(table) { // 行悬浮样式,选中行样式 - #{--el-table-row-hover-bg-color}: getCssVar('control-grid-content','item-highlight-bg-color'); - #{--el-table-current-row-bg-color}: getCssVar('control-grid-content','item-highlight-bg-color'); + #{--el-table-row-hover-bg-color}: getCssVar( + 'control-grid-content', + 'item-highlight-bg-color' + ); + #{--el-table-current-row-bg-color}: getCssVar( + 'control-grid-content', + 'item-highlight-bg-color' + ); height: 100%; // 清除element单元格的padding - &.el-table .el-table__cell{ + &.el-table .el-table__cell { padding: 0; } // 表格列头样式 - .el-table__header-wrapper .cell{ + .el-table__header-wrapper .cell { height: getCssVar('control-grid-header', 'height'); padding: getCssVar('control-grid-header', 'cell-padding'); color: getCssVar('control-grid-header', 'text-color'); @@ -43,7 +49,7 @@ // 谷歌行高样式 .el-table__row { height: getCssVar('control-grid-content', 'row-height'); - + cursor: pointer; > td { height: 0; } @@ -57,18 +63,16 @@ } // 单元格通用样式 - .cell{ + .cell { height: 100%; padding: 0; } // 选择列单元格样式 - .#{bem('control-grid','selection')}{ + .#{bem('control-grid','selection')} { padding: getCssVar('control-grid', 'cell-padding'); } - } - } @include b(control-grid-page) { diff --git a/src/view-engine/edit-view.engine.ts b/src/view-engine/edit-view.engine.ts index cdc4583f..f67a3a20 100644 --- a/src/view-engine/edit-view.engine.ts +++ b/src/view-engine/edit-view.engine.ts @@ -6,6 +6,7 @@ import { EventBase, IViewState, IEditViewEvent, + ControlVO, calcDeCodeNameById, } from '@ibiz-template/runtime'; import { IAppDEEditView } from '@ibiz/model-core'; @@ -50,9 +51,7 @@ export class EditVIewEngine extends ViewEngineBase { const data = event.data[0]; this.toolbar?.calcButtonState(data, formDeId); const info: IData = {}; - if (data?.srfmajortext) { - info.dataInfo = data.srfmajortext; - } + info.dataInfo = data.srfmajortext || ''; evt.emit('onViewInfoChange', info); }; @@ -102,6 +101,31 @@ export class EditVIewEngine extends ViewEngineBase { await this.form.save(); return { closeView: true }; } + if (key === SysUIActionTag.REMOVE_AND_EXIT) { + const res = await this.form.remove(); + return { closeView: res }; + } + if (key === SysUIActionTag.SAVE_AND_NEW) { + this.saveAndNew(); + } return super.call(key, args); } + + /** + * 保存并新建 + * + * @author zk + * @date 2023-06-01 01:06:59 + * @return {*} + * @memberof EditVIewEngine + */ + async saveAndNew() { + await this.form.save(); + this.form.state.data = new ControlVO(); + // 置空主键 + this.view.context[calcDeCodeNameById(this.view.model.appDataEntityId!)] = + undefined; + await this.form.load(); + return null; + } } -- Gitee