From 0cd2dbd69c11a6874fd433e5f9dd0042a34df59a Mon Sep 17 00:00:00 2001 From: zhf <1204297681@qq.com> Date: Tue, 4 Mar 2025 20:55:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A0=91=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E8=AE=BE=E8=AE=A1=E5=B7=A5=E5=85=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=B8=85=E9=99=A4=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/design-view-base/design-view-base.engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/design-base/src/views/design-view-base/design-view-base.engine.ts b/packages/design-base/src/views/design-view-base/design-view-base.engine.ts index f1f8de0e..e87d1c0d 100644 --- a/packages/design-base/src/views/design-view-base/design-view-base.engine.ts +++ b/packages/design-base/src/views/design-view-base/design-view-base.engine.ts @@ -442,7 +442,7 @@ export class DesignViewEngineBase extends DEMainViewEngine { for (const key in majorData) { if (Object.prototype.hasOwnProperty.call(majorData, key)) { const val = majorData[key]; - if (typeof val === 'object') { + if (typeof val === 'object' && val !== null) { majorData[key] = undefined; } } -- Gitee From 2a8d6888c1665476b5929d1629b906fc53bc49e9 Mon Sep 17 00:00:00 2001 From: zhf <1204297681@qq.com> Date: Tue, 4 Mar 2025 21:12:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E8=A1=A8=E5=8D=95=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E7=B4=A0=E6=9D=90=E5=8C=BA=E8=A1=A5=E5=85=85=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AF=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd-stencil-basic.controller.ts | 202 ++++++++++++++++++ .../dnd-stencil-basic.provider.ts | 21 ++ .../src/plugins/dnd-stencil-basic/index.ts | 2 + .../dnd-stencil-editor.controller.ts | 42 ++-- packages/dnd-design/src/plugins/index.ts | 5 + .../dnd-design-view/dnd-design-view.engine.ts | 11 +- .../interface/dnd-design-view.event.ts | 15 ++ 7 files changed, 282 insertions(+), 16 deletions(-) create mode 100644 packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.controller.ts create mode 100644 packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.provider.ts create mode 100644 packages/dnd-design/src/plugins/dnd-stencil-basic/index.ts diff --git a/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.controller.ts b/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.controller.ts new file mode 100644 index 00000000..8c329174 --- /dev/null +++ b/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.controller.ts @@ -0,0 +1,202 @@ +import { + IAppDataEntity, + ICodeListEditor, + IDEEditForm, + IDEFormItem, +} from '@ibiz/model-core'; +import { IAppDEService, IDataEntity, getControl } from '@ibiz-template/runtime'; +import { IPortalMessage, RuntimeModelError } from '@ibiz-template/core'; +import { DndStencilPanelItemController } from '../../panel-items/dnd-stencil/dnd-stencil.controller'; + +export class DndStencilBasicController extends DndStencilPanelItemController { + /** + * 主表单 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:05 + * @protected + * @type {IDEEditForm} + */ + protected majorForm!: IDEEditForm; + + /** + * 主实体 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:14 + * @protected + * @type {IAppDataEntity} + */ + protected majorEntity!: IAppDataEntity; + + /** + * 主服务 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:35 + * @protected + * @type {IAppDEService} + */ + protected majorService!: IAppDEService; + + /** + * 代码表id + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:14 + * @protected + * @type {string} + */ + protected appCodeListId?: string; + + /** + * 移动端代码表id + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:25 + * @protected + * @type {string} + */ + protected mobAppCodeListId?: string; + + /** + * 初始化 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:53 + * @protected + * @return {*} {Promise} + */ + protected async onInit(): Promise { + await this.initBaseResource(); + await super.onInit(); + this.onDataUpdate = this.onDataUpdate.bind(this); + ibiz.mc.command.update.on(this.onDataUpdate); + this.view.evt.on('onStencilUpdate', async () => { + await this.load(); + }); + } + + /** + * 初始化基础资源 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:25 + * @protected + * @return {*} {Promise} + */ + protected async initBaseResource(): Promise { + const app = ibiz.hub.getApp(this.view.model.appId); + const majorForm = getControl(this.view.model, 'form'); + if (!majorForm) { + throw new RuntimeModelError(this.view, '未找到 form 表单模型'); + } + this.majorForm = majorForm; + this.majorEntity = await ibiz.hub.getAppDataEntity( + this.majorForm.appDataEntityId!, + this.view.model.appId, + ); + this.majorService = await app.deService.getService( + this.panel.context, + this.majorForm.appDataEntityId!, + ); + const pages = this.majorForm.deformPages; + if (!Array.isArray(pages) || !pages.length) { + return; + } + const page = pages[0]; + const formDetails = page.deformDetails; + if (!Array.isArray(formDetails)) { + return; + } + const formDetail = formDetails.find(item => item.codeName === 'pc'); + const mobFormDetail = formDetails.find(item => item.codeName === 'mob'); + if (!formDetail || !mobFormDetail) { + return; + } + const formEditor = (formDetail as IDEFormItem).editor as ICodeListEditor; + if (formEditor) { + this.appCodeListId = formEditor.appCodeListId; + } + const mobFormEditor = (mobFormDetail as IDEFormItem) + .editor as ICodeListEditor; + if (mobFormEditor) { + this.mobAppCodeListId = mobFormEditor.appCodeListId; + } + } + + /** + * 监听数据变化 + * + * @author zhanghengfeng + * @date 2025-03-04 19:03:28 + * @protected + * @param {IPortalMessage} msg + * @return {*} {Promise} + */ + protected async onDataUpdate(msg: IPortalMessage): Promise { + if (!msg || !msg.data || typeof msg.data !== 'object') { + return; + } + const data = msg.data as IDataEntity; + if ( + data.srfdecodename === this.majorEntity.codeName && + data.srfkey === this.view.state.data?.srfkey + ) { + const majorResult = await this.majorService.getTemp( + this.panel.context, + this.panel.params, + ); + if (!majorResult || !majorResult.ok || !majorResult.data) { + return; + } + if (majorResult.data.mobflag === this.view.context.mobflag) { + return; + } + this.view.context.mobflag = majorResult.data.mobflag; + this.view.evt.emit('onStencilUpdate', undefined); + } + } + + /** + * 加载数据 + * + * @author zhanghengfeng + * @date 2025-03-04 21:03:42 + * @return {*} {Promise} + */ + async load(): Promise { + const appCodeListId = this.view.context.mobflag + ? this.mobAppCodeListId + : this.appCodeListId; + if (!appCodeListId) { + throw new RuntimeModelError(this.model, `未配置素材区代码表`); + } + const app = ibiz.hub.getApp(this.model.appId); + this.codeList = app.codeList.getCodeList(appCodeListId)!; + if (!this.codeList) { + throw new RuntimeModelError(this.model, `未配置素材区代码表`); + } + this.codeItems = this.codeList.codeItems || []; + const index = this.codeItems.findIndex(item => { + if (item.codeItems && item.codeItems.length > 1) { + return true; + } + return false; + }); + this.enableGroup = index !== -1; + this.state.items = this.codeItems; + this.filter(); + } + + /** + * 销毁方法 + * + * @author zhanghengfeng + * @date 2025-03-04 21:03:59 + */ + destroy(): void { + super.destroy(); + ibiz.mc.command.update.off(this.onDataUpdate); + } +} diff --git a/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.provider.ts b/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.provider.ts new file mode 100644 index 00000000..9c86d23d --- /dev/null +++ b/packages/dnd-design/src/plugins/dnd-stencil-basic/dnd-stencil-basic.provider.ts @@ -0,0 +1,21 @@ +import { + IPanelItemController, + IPanelItemProvider, + IPanelController, +} from '@ibiz-template/runtime'; +import { IPanelItem } from '@ibiz/model-core'; +import { DndStencilBasicController } from './dnd-stencil-basic.controller'; + +export class DndStencilBasicProvider implements IPanelItemProvider { + component = 'IBizDndStencilPanelItem'; + + async createController( + panelItem: IPanelItem, + panel: IPanelController, + parent?: IPanelItemController, + ): Promise { + const c = new DndStencilBasicController(panelItem, panel, parent); + await c.init(); + return c; + } +} diff --git a/packages/dnd-design/src/plugins/dnd-stencil-basic/index.ts b/packages/dnd-design/src/plugins/dnd-stencil-basic/index.ts new file mode 100644 index 00000000..6c37f580 --- /dev/null +++ b/packages/dnd-design/src/plugins/dnd-stencil-basic/index.ts @@ -0,0 +1,2 @@ +export { DndStencilBasicController } from './dnd-stencil-basic.controller'; +export { DndStencilBasicProvider } from './dnd-stencil-basic.provider'; diff --git a/packages/dnd-design/src/plugins/dnd-stencil-editor/dnd-stencil-editor.controller.ts b/packages/dnd-design/src/plugins/dnd-stencil-editor/dnd-stencil-editor.controller.ts index 98b6e167..f0adffc3 100644 --- a/packages/dnd-design/src/plugins/dnd-stencil-editor/dnd-stencil-editor.controller.ts +++ b/packages/dnd-design/src/plugins/dnd-stencil-editor/dnd-stencil-editor.controller.ts @@ -64,6 +64,15 @@ export class DndStencilEditorController extends DndStencilPanelItemController { */ enableGroup: boolean = true; + /** + * 编辑器数据 + * + * @author zhanghengfeng + * @date 2025-03-04 21:03:08 + * @type {IData[]} + */ + editorData: IData[] = []; + /** * 初始化 * @@ -75,6 +84,9 @@ export class DndStencilEditorController extends DndStencilPanelItemController { protected async onInit(): Promise { await this.initBaseResource(); await super.onInit(); + this.view.evt.on('onStencilUpdate', async () => { + await this.load(true); + }); } /** @@ -127,7 +139,7 @@ export class DndStencilEditorController extends DndStencilPanelItemController { * @date 2025-01-22 19:01:20 * @return {*} {Promise} */ - async load(): Promise { + async load(isLocalMode: boolean = false): Promise { const majorResult = await this.majorService.getTemp( this.panel.context, this.panel.params, @@ -135,21 +147,23 @@ export class DndStencilEditorController extends DndStencilPanelItemController { if (!majorResult || !majorResult.ok || !majorResult.data) { return; } - const editorResult = await this.editorService.exec( - 'FetchCurSysWithIcon', - this.panel.context, - this.panel.params, - ); - if ( - !editorResult || - !editorResult.ok || - !Array.isArray(editorResult.data) - ) { - return; + if (!isLocalMode) { + const editorResult = await this.editorService.exec( + 'FetchCurSysWithIcon', + this.panel.context, + this.panel.params, + ); + if ( + !editorResult || + !editorResult.ok || + !Array.isArray(editorResult.data) + ) { + return; + } + this.editorData = editorResult.data; } const formData = majorResult.data; - const editorData = editorResult.data; - const items = editorData.filter(item => { + const items = this.editorData.filter(item => { const editorType = item.pseditortypeid; if ( editorType === 'HIDDEN' || diff --git a/packages/dnd-design/src/plugins/index.ts b/packages/dnd-design/src/plugins/index.ts index 900122cd..1573b061 100644 --- a/packages/dnd-design/src/plugins/index.ts +++ b/packages/dnd-design/src/plugins/index.ts @@ -3,6 +3,7 @@ import { registerPanelItemProvider } from '@ibiz-template/runtime'; import { DndStencilFieldProvider } from './dnd-stencil-field'; import FormLogicEventScript from './form-logic-event-script'; import { DndStencilEditorProvider } from './dnd-stencil-editor'; +import { DndStencilBasicProvider } from './dnd-stencil-basic'; export default { install(v: App) { @@ -15,5 +16,9 @@ export default { 'FIELD_DND_PANEL_ITEM_STENCIL_EDITOR', () => new DndStencilEditorProvider(), ); + registerPanelItemProvider( + 'FIELD_DND_PANEL_ITEM_STENCIL_BASIC', + () => new DndStencilBasicProvider(), + ); }, }; diff --git a/packages/dnd-design/src/views/dnd-design-view/dnd-design-view.engine.ts b/packages/dnd-design/src/views/dnd-design-view/dnd-design-view.engine.ts index 565652e0..8eed59aa 100644 --- a/packages/dnd-design/src/views/dnd-design-view/dnd-design-view.engine.ts +++ b/packages/dnd-design/src/views/dnd-design-view/dnd-design-view.engine.ts @@ -350,6 +350,7 @@ export class DndDesignViewEngine extends DEMainViewEngine { const res = await this.service.get(this.view.context, this.view.params); this.service.local.add(this.view.context, res.data as IDataEntity); this.view.state.data = res.data as IDataEntity; + this.view.context.mobflag = res.data?.mobflag; return res.data; } finally { this.view.endLoading(); @@ -375,6 +376,7 @@ export class DndDesignViewEngine extends DEMainViewEngine { const res = await this.service.update(this.view.context, data!); this.service.local.add(this.view.context, res.data as IDataEntity); this.view.state.data = res.data as IDataEntity; + this.view.context.mobflag = res.data?.mobflag; await this.view.evt.emit('onSaveSuccess', undefined); this.activeRoot(); this.view.evt.emit('onViewInfoChange', { @@ -460,11 +462,16 @@ export class DndDesignViewEngine extends DEMainViewEngine { if (!modelStateUtil.isEnableUpdate(modelState)) { context.srfreadonly = true; } - this.navPos.openView({ + const navViewMsg = { key: forceRefresh ? createUUID() : data.srfkey, viewId: ref.refAppViewId, context, - }); + }; + const cacheKey = (this.navPos as any).calcCacheKey(navViewMsg); + if (this.navPos.state.navViewMsgs[cacheKey]) { + Object.assign(this.navPos.state.navViewMsgs[cacheKey], { context }); + } + this.navPos.openView(navViewMsg); } else { throw new RuntimeModelError( this.view.model, diff --git a/packages/dnd-design/src/views/dnd-design-view/interface/dnd-design-view.event.ts b/packages/dnd-design/src/views/dnd-design-view/interface/dnd-design-view.event.ts index 8092d4be..70f7e847 100644 --- a/packages/dnd-design/src/views/dnd-design-view/interface/dnd-design-view.event.ts +++ b/packages/dnd-design/src/views/dnd-design-view/interface/dnd-design-view.event.ts @@ -121,4 +121,19 @@ export interface DndDesignViewEvent extends IViewEvent { event: EventBase; emitArgs: undefined; }; + + /** + * 素材更新事件 + * + * @author zhanghengfeng + * @date 2025-03-04 21:03:18 + * @type {{ + * event: EventBase; + * emitArgs: undefined; + * }} + */ + onStencilUpdate: { + event: EventBase; + emitArgs: undefined; + }; } -- Gitee