diff --git a/packages/antv-x6-design/src/panel-items/x6-panel-item-stencil/x6-panel-item-stencil.controller.ts b/packages/antv-x6-design/src/panel-items/x6-panel-item-stencil/x6-panel-item-stencil.controller.ts index fb12e260f2587f03ee48306798a152527f6651fe..d97931d652ec0d9834fe116f7bd2cd90cc38e8f6 100644 --- a/packages/antv-x6-design/src/panel-items/x6-panel-item-stencil/x6-panel-item-stencil.controller.ts +++ b/packages/antv-x6-design/src/panel-items/x6-panel-item-stencil/x6-panel-item-stencil.controller.ts @@ -7,6 +7,7 @@ import { import { IPanelField, ICodeListEditor, IAppCodeList } from '@ibiz/model-core'; import { Stencil } from '@antv/x6-plugin-stencil'; import { RuntimeModelError, awaitTimeout } from '@ibiz-template/core'; +import { Graph } from '@antv/x6'; import { X6PanelItemStencilState } from './x6-panel-item-stencil.state'; import { X6PanelItemController } from '../x6-panel-item/x6-panel-item.controller'; import { X6Controller } from '../../controller'; @@ -44,6 +45,27 @@ export class X6PanelItemStencilController extends PanelItemController { - const item = codeListItems.find( - i => (i.id as string).toLowerCase() === key.toLowerCase(), - ); - if (item) { - Object.assign(item, { action: action[key] }); - if (item.children) { - item.children.forEach(i => { - Object.assign(i, { action: action[key] }); - }); - } + fillAction(codeListItems: CodeListItem[]) { + codeListItems.forEach(item => { + const action = this.actionParams[item.id]; + if (action) { + const data = item.data || {}; + Object.assign(item, { data: { action, ...data } }); + } + if (Array.isArray(item.children)) { + item.children.forEach(x => { + const data = x.data || {}; + Object.assign(x, { data: { action, ...data } }); + }); } }); } @@ -115,58 +135,38 @@ export class X6PanelItemStencilController extends PanelItemController { + public loadNodes(codeListItems: CodeListItem[]) { + this.nodes = []; + codeListItems.forEach(item => { + let nodes: IData[] = []; if (item.children) { - const nodes = item.children.map(codeItem => { + nodes = item.children.map(codeItem => { + const param = codeItem; + if (param.data && param.data.action && param.data.action.remove) { + Object.assign(param.data, { + actionID: param.data.action.remove, + }); + } const node = this.x6.g.createNode( - this.provider.createMaterialCell(codeItem), + this.provider.createMaterialCell(param), ); return node; }); - if (codeListItems[index]) { - const add = (codeListItems[index] as IData)?.action; - if (add?.ADD_ACTION) { - const addNode = this.x6.g.createNode( - this.provider.createMaterialAddCell({ - action: add, - data: { - psdelogicnodename: 'add', - memo: '新增', - logicnodetype: 'add', - param1: 'add', - }, - id: 'add', - sysImage: { - appId: 'metaflow__dataflowdesign', - rawContent: - '', - }, - text: '新增', - value: 'add', - } as CodeListItem), - ); - nodes.push(addNode); - } - } - this.s!.load(nodes, item.id!); } - }); - } - - /** - * 清空分组 - * - * @author fangZhiHao - * @date 2024-07-24 09:07:59 - * @param {CodeListItem[]} codeListItems - */ - public removeGroup(codeListItems: CodeListItem[]) { - codeListItems.forEach(item => { - const i = this.s?.options.groups?.find(group => group.name === item.id); - if (!i) { - this.s?.removeGroup(item.id); + const data = item.data || {}; + if (data.action && data.action.add) { + const addNode = this.x6.g.createNode( + this.provider.createMaterialAddCell({ + id: 'add', + data: { actionID: data.action.add }, + text: '新增', + value: 'add', + } as CodeListItem), + ); + nodes.push(addNode); } + this.nodes.push(...nodes); + this.s!.load(nodes, item.id!); }); } @@ -178,19 +178,30 @@ export class X6PanelItemStencilController extends PanelItemController { - this.registerNodeEvent( - '.ibiz-material-node-delete-icon', - action, - 'REMOVE_ACTION', - ); - this.registerNodeEvent( - '.ibiz-material-node-add-icon', - action, - 'ADD_ACTION', - ); - }, 4000); + initEevnt() { + const graphs = (this.s! as IData).graphs; + Object.keys(this.actionParams).forEach(key => { + const graph: Graph = graphs[key]; + if (graph) { + graph.on('render:done', () => { + const nodes = graph.container.querySelectorAll('.x6-node'); + nodes.forEach(node => { + const dataId = node.getAttribute('data-cell-id'); + const cell = graph.getCellById(dataId!); + if (this.actionParams[key].remove) { + this.registerNodeEvent( + node, + cell, + '.ibiz-material-node-delete-icon', + ); + } + if (this.actionParams[key].add) { + this.registerNodeEvent(node, cell, '.ibiz-material-add-node'); + } + }); + }); + } + }); } /** @@ -202,45 +213,40 @@ export class X6PanelItemStencilController extends PanelItemController { - el.addEventListener( + async registerNodeEvent(container: Element, cell: IData, className: string) { + const element = container.querySelector(className) as IData; + if (element) { + if (element.classList.contains('is-active')) { + return; + } + element.classList.add('is-active'); + element.addEventListener( 'mousedown', async (event: MouseEvent) => { - const cl = el.classList?.[1]; - let uiActionId = ''; - if (cl) { - uiActionId = `${ - action[cl.toLocaleUpperCase()] && - action[cl.toLocaleUpperCase()][key] - }@psdelogic`; - } else { - return; - } - event.preventDefault(); - event.stopPropagation(); - await UIActionUtil.execAndResolved( - uiActionId, - { - context: this.panel.context, - params: { - panelDataParent: this.dataParent.model.id!, - ...this.panel.params, + if (cell.data && cell.data.data && cell.data.data.actionID) { + const uiActionId = `${cell.data.data.actionID}`; + event.preventDefault(); + event.stopPropagation(); + await UIActionUtil.execAndResolved( + uiActionId, + { + context: this.panel.context, + params: { + panelDataParent: this.dataParent.model.id!, + ...this.panel.params, + }, + data: [this.data], + view: this.panel.view, + event, + noWaitRoute: true, }, - data: [this.data], - view: this.panel.view, - event, - noWaitRoute: true, - }, - this.model.appId, - ); - this.reloadCodeList(action); - this.initEevnt(action); + this.model.appId, + ); + } }, { captrue: true, passive: false }, ); - }); + } } /** @@ -250,14 +256,43 @@ export class X6PanelItemStencilController extends PanelItemController { + graph.clearCells({ refresh: true }); + }); const { appCodeListId } = this.model.editor as ICodeListEditor; - let codeListItems: CodeListItem[] = []; - if (appCodeListId) { - codeListItems = await this.loadCodeList(appCodeListId, action); - this.calcAction(codeListItems, action); - this.mountNodes(codeListItems); + const codeListItems: CodeListItem[] = + await this.loadCodeList(appCodeListId); + this.fillAction(codeListItems); + this.loadNodes(codeListItems); + this.initEevnt(); + } + } + + /** + * @description 初始化编辑器参数 + * @param {IData} editorParams + * @memberof X6PanelItemStencilController + */ + initEditorParams(editorParams: IData) { + if (editorParams) { + Object.keys(editorParams).forEach((key: string) => { + const keys = key.split('_'); + if (keys.length === 3 && keys[2] === 'ACTION') { + const action = this.actionParams[keys[0]] || {}; + this.actionParams[keys[0]] = { + [keys[1].toLowerCase()]: editorParams[key], + ...action, + }; + } + }); + if (editorParams.SHOWHEADER) { + this.showGroupHeader = + editorParams.SHOWHEADER === 'true' || + editorParams.SHOWHEADER === 'TRUE'; + } } } @@ -281,40 +316,16 @@ export class X6PanelItemStencilController extends PanelItemController { - const firstUnderscoreIndex = key.indexOf('_'); - if (firstUnderscoreIndex !== -1) { - const part1 = key - .substring(0, firstUnderscoreIndex) - .toLocaleUpperCase(); - const part2 = key.substring(firstUnderscoreIndex + 1); - if (action[part1]) { - action[part1][part2] = editorParams[key]; - } else { - action[part1] = { - [part2]: editorParams[key], - id: part1, - }; - } - } - }); - if (editorParams.SHOWHEADER) { - Object.assign(action, { - showHeader: JSON.parse(editorParams.SHOWHEADER), - }); - } - } + const { appCodeListId, editorParams = {} } = editor as ICodeListEditor; + this.initEditorParams(editorParams); if (appCodeListId) { // 加载代码表 并计算界面行为 const app = await ibiz.hub.getApp(this.model.appId); codeList = app.codeList.getCodeList(appCodeListId)!; - codeListItems = await this.loadCodeList(appCodeListId, action); - this.calcAction(codeListItems, action); + codeListItems = await this.loadCodeList(appCodeListId); + this.fillAction(codeListItems); } } if (!codeList) { @@ -362,8 +373,8 @@ export class X6PanelItemStencilController extends PanelItemController', }, }, ...metadata, diff --git a/packages/antv-x6-design/src/plugins/logic-design/custom-node/material-node.ts b/packages/antv-x6-design/src/plugins/logic-design/custom-node/material-node.ts index d47e7b5a651365bb55d4984f96c9cb7cd972416f..192372f1fc235a5d36df5438295a2b07a53cdf2c 100644 --- a/packages/antv-x6-design/src/plugins/logic-design/custom-node/material-node.ts +++ b/packages/antv-x6-design/src/plugins/logic-design/custom-node/material-node.ts @@ -54,18 +54,16 @@ export class MaterialNode extends Shape.Rect { }, ...metadata, }; - if (metadata.data.action && metadata.data.action.REMOVE_ACTION) { + const data = metadata.data.data || {}; + if (data.actionID) { config.markup[0].children[0].children.push({ tagName: 'div', - className: [ - ns.b('delete-icon'), - metadata.data?.action && metadata.data.action.id, - ], + className: [ns.b('delete-icon'), data.actionID], selector: 'deleteIcon', }); Object.assign(config.attrs, { deleteIcon: { - html: ``, + html: ``, }, }); } diff --git a/packages/antv-x6-design/src/plugins/logic-design/index.scss b/packages/antv-x6-design/src/plugins/logic-design/index.scss index 9d6069a9d80f3165c0af94feca720c001fa5edea..e22d795e4dc495f655ef082f1f4faa30f7d707e9 100644 --- a/packages/antv-x6-design/src/plugins/logic-design/index.scss +++ b/packages/antv-x6-design/src/plugins/logic-design/index.scss @@ -16,6 +16,19 @@ } } } +@include b(material-add-node-container) { + display: flex; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + cursor: pointer; + + .#{bem(material-add-node-icon)}{ + width: 60px; + height: 60px; + } +} @include b(material-node-icon) { flex: 0 0 auto; @@ -34,6 +47,8 @@ right: 6px; z-index: 10; display: none; + width: 24px; + height: 24px; cursor: pointer; }