This commit is contained in:
JenniferW 2025-08-14 16:53:13 +08:00
parent 889400c9ab
commit 093604011d
1 changed files with 27 additions and 11 deletions

View File

@ -127,7 +127,7 @@
<span <span
class="tag-value" class="tag-value"
@click.stop="focusConditionTag(index)" @click.stop="focusConditionTag(index)"
>{{ cond.value }}</span >{{ cond.value || "空值" }}</span
> >
<el-icon class="tag-edit-icon" size="14"><Edit /></el-icon> <el-icon class="tag-edit-icon" size="14"><Edit /></el-icon>
</el-tag> </el-tag>
@ -645,7 +645,7 @@ const handleInputContainerClick = (e) => {
// 处理输入框点击事件 - 支持点击已输入值显示下拉 // 处理输入框点击事件 - 支持点击已输入值显示下拉
const handleInputClick = () => { const handleInputClick = () => {
const index = findCursorConditionIndex(); const index = findCursorConditionIndex();
const parts = currentInput.value.split(";"); const parts = currentInput.value.split(/[;;]/);
if (index >= 0 && index < parts.length) { if (index >= 0 && index < parts.length) {
const part = parts[index].trim(); const part = parts[index].trim();
@ -664,7 +664,7 @@ const handleInputMouseUp = () => {
// 聚焦到指定的条件标签 // 聚焦到指定的条件标签
const focusConditionTag = (index) => { const focusConditionTag = (index) => {
const parts = currentInput.value.split(";"); const parts = currentInput.value.split(/[;;]/);
if (index < parts.length) { if (index < parts.length) {
// 将光标定位到该条件 // 将光标定位到该条件
selectedConditionIndex.value = index; selectedConditionIndex.value = index;
@ -673,15 +673,15 @@ const focusConditionTag = (index) => {
if (!inputEl) return; if (!inputEl) return;
// 计算该条件在输入框中的位置 // 计算该条件在输入框中的位置
let material = 0; let cursorPos = 0;
for (let i = 0; i < index; i++) { for (let i = 0; i < index; i++) {
material += parts[i].length + 1; // +1 是分号的长度 cursorPos += parts[i].length + 1; // +1 是分号的长度
} }
// 设置光标位置 // 设置光标位置
setTimeout(() => { setTimeout(() => {
inputEl.focus(); inputEl.focus();
inputEl.setSelectionRange(material, material + parts[index].length); inputEl.setSelectionRange(cursorPos, cursorPos + parts[index].length);
// 触发该条件的建议显示 // 触发该条件的建议显示
triggerConditionSuggestions(parts[index].trim()); triggerConditionSuggestions(parts[index].trim());
}, 0); }, 0);
@ -742,7 +742,7 @@ const triggerConditionSuggestions = (conditionText) => {
// 处理输入事件,实时生成建议 // 处理输入事件,实时生成建议
const handleInput = (value) => { const handleInput = (value) => {
// 获取当前正在输入的条件部分(分号后面的部分) // 获取当前正在输入的条件部分(分号后面的部分)
const parts = value.split(";"); const parts = value.split(/[;;]/);
const currentPart = parts[parts.length - 1].trim(); const currentPart = parts[parts.length - 1].trim();
// 检查是否在编辑已有条件 // 检查是否在编辑已有条件
@ -901,7 +901,7 @@ const handleInput = (value) => {
// 选择可能的字段 // 选择可能的字段
const selectPossibleField = (field) => { const selectPossibleField = (field) => {
const parts = currentInput.value.split(";"); const parts = currentInput.value.split(/[;;]/);
let targetIndex = let targetIndex =
selectedConditionIndex.value >= 0 selectedConditionIndex.value >= 0
? selectedConditionIndex.value ? selectedConditionIndex.value
@ -918,9 +918,14 @@ const selectPossibleField = (field) => {
// 在当前值前添加字段名和冒号 // 在当前值前添加字段名和冒号
parts[targetIndex] = `${field.label}:${targetPart}`; parts[targetIndex] = `${field.label}:${targetPart}`;
// 重新拼接条件,清理多余分号 // 重新拼接条件,清理多余分号,并确保末尾有分号
currentInput.value = parts.join(";").replace(/;;+/g, ";").trim(); currentInput.value = parts.join(";").replace(/;;+/g, ";").trim();
// 如果当前部分不为空且不以分号结尾,则添加分号
if (currentInput.value && !currentInput.value.endsWith(";")) {
currentInput.value += ";";
}
// 保持建议框显示,允许继续编辑 // 保持建议框显示,允许继续编辑
setTimeout(() => { setTimeout(() => {
handleInput(currentInput.value); handleInput(currentInput.value);
@ -971,7 +976,7 @@ const getOperator = (conditionValue) => {
// 选择建议项 - 支持替换已有条件的值 // 选择建议项 - 支持替换已有条件的值
const selectSuggestion = (item) => { const selectSuggestion = (item) => {
const parts = currentInput.value.split(";"); const parts = currentInput.value.split(/[;;]/);
let targetIndex = let targetIndex =
selectedConditionIndex.value >= 0 selectedConditionIndex.value >= 0
? selectedConditionIndex.value ? selectedConditionIndex.value
@ -1011,9 +1016,14 @@ const selectSuggestion = (item) => {
} }
} }
// 重新拼接条件,清理多余分号 // 重新拼接条件,清理多余分号,并确保末尾有分号
currentInput.value = parts.join(";").replace(/;;+/g, ";").trim(); currentInput.value = parts.join(";").replace(/;;+/g, ";").trim();
// 如果当前部分不为空且不以分号结尾,则添加分号
if (currentInput.value && !currentInput.value.endsWith(";")) {
currentInput.value += ";";
}
// 保持建议框显示,允许继续编辑 // 保持建议框显示,允许继续编辑
setTimeout(() => { setTimeout(() => {
handleInput(currentInput.value); handleInput(currentInput.value);
@ -1216,6 +1226,12 @@ const removeCondition = (index) => {
.join(";") .join(";")
.replace(/[;;]+/g, ";") .replace(/[;;]+/g, ";")
.trim(); .trim();
// 确保末尾有分号
if (currentInput.value && !currentInput.value.endsWith(";")) {
currentInput.value += ";";
}
parsedConditions.value = parseConditions(currentInput.value); parsedConditions.value = parseConditions(currentInput.value);
filteredData.value = filterData(parsedConditions.value).map((item) => ({ filteredData.value = filterData(parsedConditions.value).map((item) => ({
...item, ...item,