From 25dc3d56cd8db5a84d885952f5aeacf94f5ce89a Mon Sep 17 00:00:00 2001 From: ShineKOT <1917095344@qq.com> Date: Fri, 8 Nov 2024 16:51:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=20=E6=9B=B4=E6=96=B0=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooks/use-ctrl-pos/use-ctrl-pos.ts | 4 +- .../view-design-control.tsx | 22 +---- .../panel-ctrl-pos-propvider.ts | 76 ++++++++-------- .../app-index-view-design.engine.ts | 89 ++++++++----------- 4 files changed, 81 insertions(+), 110 deletions(-) diff --git a/packages/view-design/src/components/panel-item-widgets/hooks/use-ctrl-pos/use-ctrl-pos.ts b/packages/view-design/src/components/panel-item-widgets/hooks/use-ctrl-pos/use-ctrl-pos.ts index 4fcc97da..27ef7d24 100644 --- a/packages/view-design/src/components/panel-item-widgets/hooks/use-ctrl-pos/use-ctrl-pos.ts +++ b/packages/view-design/src/components/panel-item-widgets/hooks/use-ctrl-pos/use-ctrl-pos.ts @@ -57,7 +57,7 @@ export function useCtrlPos(props, ctx) { // 当前实体该类型部件集合 let ctrls: IData[] = []; // 当前面板该类型部件占位 - let ctrlsPos: IData[] = []; + const ctrlsPos: Ref = ref([]); // 部件类型 const ctrlType = props.data.type.toUpperCase(); // 面板设计上下文 @@ -94,7 +94,7 @@ export function useCtrlPos(props, ctx) { } }); } - ctrlsPos = tempCtrlsPos; + ctrlsPos.value = tempCtrlsPos; } else { throw new Error('加载当前面板该类型部件占位失败'); } diff --git a/packages/view-design/src/components/panel-item-widgets/widgets/view-design-control/view-design-control.tsx b/packages/view-design/src/components/panel-item-widgets/widgets/view-design-control/view-design-control.tsx index 9ce8a485..dce40bfa 100644 --- a/packages/view-design/src/components/panel-item-widgets/widgets/view-design-control/view-design-control.tsx +++ b/packages/view-design/src/components/panel-item-widgets/widgets/view-design-control/view-design-control.tsx @@ -94,7 +94,7 @@ export default defineComponent({ * @date 2024-10-21 17:10:09 */ const initCtrlPos = () => { - if (Object.is(ctrlType, 'APPMENU') && ctrlsPos.length > 1) { + if (Object.is(ctrlType, 'APPMENU') && ctrlsPos.value.length > 1) { ctx.emit('delete-item'); } }; @@ -213,16 +213,6 @@ export default defineComponent({ select.off(handleSelectChange); }); - /** - * 切换应用菜单 - * - * @author tony001 - * @date 2024-10-21 16:10:42 - */ - const switchAppMenu = () => { - console.log('switchAppMenu暂未实现'); - }; - /** * 行为点击 * @@ -252,13 +242,9 @@ export default defineComponent({ * @date 2024-10-21 16:10:19 */ const addControl = () => { - if (Object.is(ctrlType, 'APPMENU')) { - switchAppMenu(); - } else { - const tempData = clone(props.data.data); - Object.assign(tempData, { psctrltypeid: props.data.type }); - addCtrl(tempData, props.data.panelItemName); - } + const tempData = clone(props.data.data); + Object.assign(tempData, { psctrltypeid: props.data.type }); + addCtrl(tempData, props.data.panelItemName); isShow.value = false; }; diff --git a/packages/view-design/src/providers/item/panel-ctrl-pos-propvider/panel-ctrl-pos-propvider.ts b/packages/view-design/src/providers/item/panel-ctrl-pos-propvider/panel-ctrl-pos-propvider.ts index 381912e2..752e5a12 100644 --- a/packages/view-design/src/providers/item/panel-ctrl-pos-propvider/panel-ctrl-pos-propvider.ts +++ b/packages/view-design/src/providers/item/panel-ctrl-pos-propvider/panel-ctrl-pos-propvider.ts @@ -213,17 +213,12 @@ export class PanelCtrlPosProvider extends PanelItemProviderImpl { */ async onEdit(context: IContext, item: PanelDataProvider) { const { view } = this.panelDesignMetaData; - const ctrlType = item.type.toUpperCase(); - if (Object.is(ctrlType, 'APPMENU')) { - throw new RuntimeError('切换菜单暂未实现'); - } else { - const tempData = clone(item.data); - Object.assign(tempData, { psctrltypeid: item.type }); - view!.call('addCtrl', { - data: tempData, - ctrlposname: (item as PanelItemDataProvider).panelItemName, - }); - } + const tempData = clone(item.data); + Object.assign(tempData, { psctrltypeid: item.type }); + view!.call('addCtrl', { + data: tempData, + ctrlposname: (item as PanelItemDataProvider).panelItemName, + }); } /** @@ -244,8 +239,11 @@ export class PanelCtrlPosProvider extends PanelItemProviderImpl { if (parentToolbar) { const childToolbarItems = (parentToolbar as IDETBGroupItem).detoolbarItems || []; + const ctrlType = item.type.toUpperCase(); const action = childToolbarItems.find(childItem => { - return childItem.id === 'redirectctrldesign'; + return ctrlType === 'APPMENU' + ? childItem.id === 'openmenudesign' + : childItem.id === 'redirectctrldesign'; }); if (action && action.itemType === 'DEUIACTION') { const actionId = (action as IDETBUIActionItem).uiactionId; @@ -257,34 +255,36 @@ export class PanelCtrlPosProvider extends PanelItemProviderImpl { }), ); } - const app = ibiz.hub.getApp(context.srfappid); - const viewCtrlService = await app.deService.getService( - context, - 'viewdesign.psdeviewctrl', - ); - const viewCtrlResult = await viewCtrlService.fetchDefault(context); - if (viewCtrlResult.ok && Array.isArray(viewCtrlResult.data)) { - const viewCtrlItems = viewCtrlResult.data; - const targetViewCtrl = viewCtrlItems.find(viewCtrl => { - return Object.is( - viewCtrl.psdeviewctrlname, - (item as IData).panelItemName, - ); - }); - // 目标视图部件 - if (targetViewCtrl) { - await UIActionUtil.execAndResolved( - actionId!, - { - context, - params: {}, - data: [targetViewCtrl], - view: view!, - }, - action.appId, - ); + let targetData: IData = item.data; + if (ctrlType !== 'APPMENU') { + const app = ibiz.hub.getApp(context.srfappid); + const viewCtrlService = await app.deService.getService( + context, + 'viewdesign.psdeviewctrl', + ); + const viewCtrlResult = await viewCtrlService.fetchDefault(context); + if (viewCtrlResult.ok && Array.isArray(viewCtrlResult.data)) { + const viewCtrlItems = viewCtrlResult.data; + targetData = viewCtrlItems.find(viewCtrl => { + return Object.is( + viewCtrl.psdeviewctrlname, + (item as IData).panelItemName, + ); + }); } } + if (targetData) { + await UIActionUtil.execAndResolved( + actionId!, + { + context, + params: {}, + data: [targetData], + view: view!, + }, + action.appId, + ); + } } } } diff --git a/packages/view-design/src/views/app-index-view-design/app-index-view-design.engine.ts b/packages/view-design/src/views/app-index-view-design/app-index-view-design.engine.ts index 1b42aa5d..0a0d2bfd 100644 --- a/packages/view-design/src/views/app-index-view-design/app-index-view-design.engine.ts +++ b/packages/view-design/src/views/app-index-view-design/app-index-view-design.engine.ts @@ -19,67 +19,47 @@ export class AppIndexViewDesignEngine extends AppViewPanelDesignEngine { * 添加部件 * * @param {IData} data - * @param {string} ctrlposname - * @param {string} [ctrlType] * @return {*} {Promise} * @memberof AppIndexViewDesignEngine */ - public async addCtrl( - data: IData, - ctrlposname: string, - ctrlType?: string, - ): Promise { + public async addCtrl(data: IData): Promise { const panelDesignMetaData = this.view.getPanelDesignMetaData(); const item = getToolbarItem( - ctrlType === 'PANELPART' ? 'pickrefpanelpart' : 'viewctrlcreate', + 'switchappmenu', panelDesignMetaData.structure!, ); if (item && item.itemType === 'DEUIACTION') { const actionId = (item as IDETBUIActionItem).uiactionId; const uiAction = await getUIActionById(actionId!, item.appId); - if (!uiAction) { - return; + if (uiAction) { + const args = this.view.getEventArgs(); + await UIActionUtil.execAndResolved( + actionId!, + { + ...args, + data: [data], + }, + item.appId, + ); } - const tempData = [data]; - const tempParams = { srfparentdemapname: 'PSDEVIEWBASE' }; - if (ctrlType !== 'PANELPART') { - if (ctrlType) { - Object.assign(tempParams, { - psctrltypeid: ctrlType, - }); - } - if (!this.view.state.isDefaultLayout) { - Object.assign( - tempParams, - { defaultpanel: 1 }, - { ctrlposname: ctrlposname.toUpperCase() }, - ); - } else { - Object.assign( - tempParams, - { defaultpanel: 0 }, - { ctrlposname: ctrlposname.toUpperCase() }, - ); - } - } - if (ctrlType === 'PANELPART') { - Object.assign(tempParams, { - pssysviewpanelitemid: data.pssysviewpanelitemid, - }); - } - const args = this.view.getEventArgs(); - const tempContext = args.context.clone(); - Object.assign(tempContext, tempParams); - args.context = tempContext; - args.params = { ...tempParams, ...args.params }; - await UIActionUtil.execAndResolved( - actionId!, - { - ...args, - data: tempData, - }, - item.appId, - ); + } + } + + /** + * 切换应用菜单 + * + * @param {IData} data + * @return {*} {Promise} + * @memberof AppIndexViewDesignEngine + */ + public async switchAppMenu(data: IData): Promise { + if (data?.psappmenuid) { + await this.mainAppEntityService.updateTemp(this.view.context, { + ...this.view.state.data, + psappmenuid: data.psappmenuid, + psappmenuname: data.psappmenuname, + }); + await this.call('refresh'); } } @@ -92,8 +72,12 @@ export class AppIndexViewDesignEngine extends AppViewPanelDesignEngine { * @memberof AppIndexViewDesignEngine */ async call(key: string, args?: IData): Promise { + if (key === 'switchAppMenu') { + this.switchAppMenu(args?.data); + return undefined; + } if (key === 'addCtrl') { - this.addCtrl(args?.data, args?.ctrlposname, args?.ctrlType); + this.addCtrl(args?.data); return undefined; } return super.call(key, args); @@ -109,9 +93,10 @@ export class AppIndexViewDesignEngine extends AppViewPanelDesignEngine { */ protected async load(isInitialLoad: boolean = true): Promise { const data = await super.load(isInitialLoad); - // 将菜单合入上下文中 + // 将菜单和应用标识合入上下文中 if (data) { this.view.context.psappmenu = data.psappmenuid; + this.view.context.pssysapp = data.pssysappid; } return data; } -- Gitee