diff --git a/CHANGELOG.md b/CHANGELOG.md index c65a65d61f52cdf5f5d157a315a4f8668361935d..04bb7e025b16c691853866a014a5fda72263a25a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Changed - 文本域编辑器最小高度32,与输入框对齐 +- 树部件支持在树节点内绘制新建编辑框 ### Changed diff --git a/src/control/tree/tree.scss b/src/control/tree/tree.scss index 53772f1fed08a45fc1669f3e4ad354059471c40b..e66d046587e5f24f9a8a4733b737a7a7bbec3bd8 100644 --- a/src/control/tree/tree.scss +++ b/src/control/tree/tree.scss @@ -128,11 +128,12 @@ $control-treeview-tree: ( } @include b(control-treeview-new-node){ - display: flex; - align-items: center; - justify-content: center; - padding-left: calc(1em + 12px); - font-size: #{getCssVar(control-treeview, font-size)} + display: flex; + align-items: center; + justify-content: center; + padding-right: getCssVar(spacing, base); + padding-left: calc(1em + 12px); + font-size: #{getCssVar(control-treeview, font-size)}; } @include b(control-treeview-context-menu-trigger) { @@ -186,6 +187,14 @@ $control-treeview-tree: ( padding: getCssVar(control-treeview-tree, padding); background-color: #{getCssVar(control-treeview, bg-color)}; + + .el-tree-node__content:has(.#{bem(control-treeview-new-node)}) { + .#{bem(control-treeview-new-node)} { + width: 100%; + padding-right: 0; + padding-left: 0; + } + } } diff --git a/src/control/tree/tree.tsx b/src/control/tree/tree.tsx index d12a36f622c9dbe6b55b32ce7f39f4daf8f8eb70..f5477051add4b06338ad7f02f06b12a38ca00c50 100644 --- a/src/control/tree/tree.tsx +++ b/src/control/tree/tree.tsx @@ -151,12 +151,24 @@ export const TreeControl = defineComponent({ const newTreeNodeText = ref(null); const newNodeModel = ref(null); const newDefaultValue = ref(null); + const newNodeKey = ref(`${createUUID()}-${createUUID()}`); + const newNodeData = ref(null); c.evt.on('onNewTreeNode', args => { - const { nodeModel, defaultValue } = args; + const { nodeModel, defaultValue, parentNodeData } = args; newNodeModel.value = nodeModel; newDefaultValue.value = defaultValue; editingNodeKey.value = null; editingNodeText.value = null; + if (parentNodeData && treeRef.value) { + const _newNodeData = {}; + Object.assign(_newNodeData, { + _id: newNodeKey.value, + _text: '', + _leaf: true, + }); + treeRef.value.append(_newNodeData, parentNodeData); + newNodeData.value = _newNodeData; + } }); watch( @@ -220,6 +232,8 @@ export const TreeControl = defineComponent({ newNodeModel.value = null; newTreeNodeText.value = null; newDefaultValue.value = null; + if (newNodeData.value) treeRef.value?.remove(newNodeData.value); + newNodeData.value = null; } }; @@ -239,6 +253,8 @@ export const TreeControl = defineComponent({ newNodeModel.value = null; newTreeNodeText.value = null; newDefaultValue.value = null; + if (newNodeData.value) treeRef.value?.remove(newNodeData.value); + newNodeData.value = null; } }; @@ -795,7 +811,13 @@ export const TreeControl = defineComponent({ return null; } return ( -
+
{ + _e.preventDefault(); + _e.stopPropagation(); + }} + > {newNodeModel.value?.sysImage ? ( {{ - default: ({ data }: { node: IData; data: IData }) => { + default: ({ data, node }: { node: IData; data: IData }) => { + // 绘制新建项 + if (this.newNodeKey === data._id) return this.renderNewNode(); + const nodeData = this.findNodeData(data._uuid, this.c)!; if (!nodeData) { return null; @@ -988,7 +1015,7 @@ export const TreeControl = defineComponent({ }, }} , - this.renderNewNode(), + !this.newNodeData && this.renderNewNode(), this.c.state.enableNavView && this.c.state.showNavIcon ? ( !this.c.state.showNavView ? (