From 093604011d26b3c466761397404e1b1143abc261 Mon Sep 17 00:00:00 2001 From: JenniferW <1627055433@qq.com> Date: Thu, 14 Aug 2025 16:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/order/intention/Step2.vue | 38 ++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/views/order/intention/Step2.vue b/src/views/order/intention/Step2.vue index cdb0711..4b7c4db 100644 --- a/src/views/order/intention/Step2.vue +++ b/src/views/order/intention/Step2.vue @@ -127,7 +127,7 @@ {{ cond.value }}{{ cond.value || "空值" }} @@ -645,7 +645,7 @@ const handleInputContainerClick = (e) => { // 处理输入框点击事件 - 支持点击已输入值显示下拉 const handleInputClick = () => { const index = findCursorConditionIndex(); - const parts = currentInput.value.split(";"); + const parts = currentInput.value.split(/[;;]/); if (index >= 0 && index < parts.length) { const part = parts[index].trim(); @@ -664,7 +664,7 @@ const handleInputMouseUp = () => { // 聚焦到指定的条件标签 const focusConditionTag = (index) => { - const parts = currentInput.value.split(";"); + const parts = currentInput.value.split(/[;;]/); if (index < parts.length) { // 将光标定位到该条件 selectedConditionIndex.value = index; @@ -673,15 +673,15 @@ const focusConditionTag = (index) => { if (!inputEl) return; // 计算该条件在输入框中的位置 - let material = 0; + let cursorPos = 0; for (let i = 0; i < index; i++) { - material += parts[i].length + 1; // +1 是分号的长度 + cursorPos += parts[i].length + 1; // +1 是分号的长度 } // 设置光标位置 setTimeout(() => { inputEl.focus(); - inputEl.setSelectionRange(material, material + parts[index].length); + inputEl.setSelectionRange(cursorPos, cursorPos + parts[index].length); // 触发该条件的建议显示 triggerConditionSuggestions(parts[index].trim()); }, 0); @@ -742,7 +742,7 @@ const triggerConditionSuggestions = (conditionText) => { // 处理输入事件,实时生成建议 const handleInput = (value) => { // 获取当前正在输入的条件部分(分号后面的部分) - const parts = value.split(";"); + const parts = value.split(/[;;]/); const currentPart = parts[parts.length - 1].trim(); // 检查是否在编辑已有条件 @@ -901,7 +901,7 @@ const handleInput = (value) => { // 选择可能的字段 const selectPossibleField = (field) => { - const parts = currentInput.value.split(";"); + const parts = currentInput.value.split(/[;;]/); let targetIndex = selectedConditionIndex.value >= 0 ? selectedConditionIndex.value @@ -918,9 +918,14 @@ const selectPossibleField = (field) => { // 在当前值前添加字段名和冒号 parts[targetIndex] = `${field.label}:${targetPart}`; - // 重新拼接条件,清理多余分号 + // 重新拼接条件,清理多余分号,并确保末尾有分号 currentInput.value = parts.join(";").replace(/;;+/g, ";").trim(); + // 如果当前部分不为空且不以分号结尾,则添加分号 + if (currentInput.value && !currentInput.value.endsWith(";")) { + currentInput.value += ";"; + } + // 保持建议框显示,允许继续编辑 setTimeout(() => { handleInput(currentInput.value); @@ -971,7 +976,7 @@ const getOperator = (conditionValue) => { // 选择建议项 - 支持替换已有条件的值 const selectSuggestion = (item) => { - const parts = currentInput.value.split(";"); + const parts = currentInput.value.split(/[;;]/); let targetIndex = selectedConditionIndex.value >= 0 ? selectedConditionIndex.value @@ -1011,9 +1016,14 @@ const selectSuggestion = (item) => { } } - // 重新拼接条件,清理多余分号 + // 重新拼接条件,清理多余分号,并确保末尾有分号 currentInput.value = parts.join(";").replace(/;;+/g, ";").trim(); + // 如果当前部分不为空且不以分号结尾,则添加分号 + if (currentInput.value && !currentInput.value.endsWith(";")) { + currentInput.value += ";"; + } + // 保持建议框显示,允许继续编辑 setTimeout(() => { handleInput(currentInput.value); @@ -1216,6 +1226,12 @@ const removeCondition = (index) => { .join(";") .replace(/[;;]+/g, ";") .trim(); + + // 确保末尾有分号 + if (currentInput.value && !currentInput.value.endsWith(";")) { + currentInput.value += ";"; + } + parsedConditions.value = parseConditions(currentInput.value); filteredData.value = filterData(parsedConditions.value).map((item) => ({ ...item,