From 6d18c510b8e3e95ee7a0766108ce7183083a0b98 Mon Sep 17 00:00:00 2001 From: zhanghao <774378400@qq.com> Date: Mon, 20 Apr 2026 15:21:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E5=A4=B1=E7=84=A6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/flow/components/NodeTitle.vue | 88 ++++++++++++++++++++++-- src/views/flow/nodes/function/switch.vue | 78 ++++++++++++++++++++- 2 files changed, 158 insertions(+), 8 deletions(-) diff --git a/src/views/flow/components/NodeTitle.vue b/src/views/flow/components/NodeTitle.vue index 71d2e76..a4821e9 100644 --- a/src/views/flow/components/NodeTitle.vue +++ b/src/views/flow/components/NodeTitle.vue @@ -5,11 +5,18 @@
- {{ nodeName }} - + {{ localName }} +
-
- +
+ { + isEditing.value = true + showTextTitle.value = false + + // 使用 nextTick 确保 DOM 更新后再聚焦 + nextTick(() => { + if (inputRef.value && inputRef.value.input) { + inputRef.value.input.focus() + // 选择所有文本 + inputRef.value.input.select() + } + }) +} const confirmNodeName = () => { - emits('setNodeName', nodeName.value) + emits('setNodeName', localName.value) showTextTitle.value = true } const cancelNodeName = () => { - nodeName.value = props.nodeProperties?.name || props.nodeName + localName.value = props.nodeProperties?.name || props.nodeName showTextTitle.value = true } @@ -138,6 +161,32 @@ const execute = () => { document.dispatchEvent(myEvent); } +const handleInputFocus = (e) => { + console.log('Input focused') + // 阻止事件冒泡到 LogicFlow + e.stopPropagation() + e.preventDefault() + + // 设置编辑状态 + isEditing.value = true + + // 延迟执行,确保事件处理完成 + setTimeout(() => { + if (inputRef.value && inputRef.value.input) { + inputRef.value.input.focus() + } + }, 0) +} + +const handleInputBlur = (e) => { + console.log('Input blurred') + // 如果正在编辑,不要立即取消编辑状态 + if (isEditing.value) { + // 可以选择在失焦时自动保存或取消 + // 这里我们选择不自动保存,让用户点击确认按钮 + } +} + const handleInputKeydown = (e) => { // 阻止事件冒泡到 Logic Flow 节点,避免被其事件拦截 e.stopPropagation(); @@ -151,7 +200,12 @@ const imageUrl = () => { return new URL(props.icon, import.meta.url).href; } +onMounted(() => { + localName.value = props.nodeProperties?.name || props.nodeName +}) + onUnmounted(() => { + console.log(34566) emitter.off("deleteNode"); }) @@ -164,6 +218,7 @@ onUnmounted(() => { .left { display: flex; + align-items: center; // 添加垂直居中 img { width: 24px; @@ -193,6 +248,18 @@ onUnmounted(() => { .el-input { margin-left: 12px; width: 120px; + // 确保输入框有更高的 z-index + position: relative; + z-index: 1000; + + // 覆盖 Element Plus 的默认样式,确保焦点状态明显 + :deep(.el-input__wrapper) { + box-shadow: 0 0 0 1px #409eff !important; + + &:focus-within { + box-shadow: 0 0 0 2px #409eff !important; + } + } } .input_name_select { @@ -226,4 +293,11 @@ onUnmounted(() => { margin: 8px 0; } } + +// 添加全局样式,确保输入框焦点不被其他元素干扰 +:global(.lf-node) { + .el-input__inner { + user-select: text !important; + } +} diff --git a/src/views/flow/nodes/function/switch.vue b/src/views/flow/nodes/function/switch.vue index 7bcc0f9..8d5c48e 100644 --- a/src/views/flow/nodes/function/switch.vue +++ b/src/views/flow/nodes/function/switch.vue @@ -72,6 +72,10 @@ v-model="params.withOr" placeholder="Select" style="width: 240px" + @focus="handleInputFocus" + @blur="handleInputBlur" + @click.stop + @mousedown.stop > @@ -88,6 +92,11 @@ @@ -108,6 +117,11 @@ v-model="property.name" placeholder="请输入" clearable + @focus="handleInputFocus" + @blur="handleInputBlur" + @keydown="handleInputKeydown" + @click.stop + @mousedown.stop /> @@ -136,7 +155,14 @@ { required: true, message: '请输入变量名', trigger: 'blur' }, ]" > - + @@ -156,6 +182,11 @@ @@ -175,6 +206,11 @@ v-model="property.input" placeholder="请输入" clearable + @focus="handleInputFocus" + @blur="handleInputBlur" + @keydown="handleInputKeydown" + @click.stop + @mousedown.stop /> @@ -415,6 +456,41 @@ const closePopover = () => { } } +const handleInputFocus = (e) => { + console.log('Input focused') + // 阻止事件冒泡到 LogicFlow + e.stopPropagation() + e.preventDefault() + + // 设置编辑状态 + isEditing.value = true + + // 延迟执行,确保事件处理完成 + setTimeout(() => { + if (inputRef.value && inputRef.value.input) { + inputRef.value.input.focus() + } + }, 0) +} + +const handleInputBlur = (e) => { + console.log('Input blurred') + // 如果正在编辑,不要立即取消编辑状态 + if (isEditing.value) { + // 可以选择在失焦时自动保存或取消 + // 这里我们选择不自动保存,让用户点击确认按钮 + } +} + +const handleInputKeydown = (e) => { + // 阻止事件冒泡到 Logic Flow 节点,避免被其事件拦截 + e.stopPropagation(); + // 可选:明确放行 Ctrl+V(增强兼容性) + if ((e.ctrlKey || e.metaKey) && e.key === "v") { + e.returnValue = true; // 允许默认粘贴行为 + } +} + onMounted(() => { emits("addAnchor", 280, "".concat(props.model.id, "_else"));