|
|
@@ -14,9 +14,11 @@
|
|
|
<template #default="{ row }">
|
|
|
<el-input
|
|
|
spellcheck="false"
|
|
|
- v-model="row.name"
|
|
|
+ :model-value="row.name"
|
|
|
placeholder="请输入"
|
|
|
- @input="(val) => handleVariableNameInput(row, val)"
|
|
|
+ @update:model-value="
|
|
|
+ (val) => handleVariableNameInput(row, val, pageVariables || [])
|
|
|
+ "
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -94,9 +96,11 @@
|
|
|
<template #default="{ row }">
|
|
|
<el-input
|
|
|
spellcheck="false"
|
|
|
- v-model="row.name"
|
|
|
+ :model-value="row.name"
|
|
|
placeholder="请输入"
|
|
|
- @input="(val) => handleVariableNameInput(row, val)"
|
|
|
+ @update:model-value="
|
|
|
+ (val) => handleVariableNameInput(row, val, item.variables)
|
|
|
+ "
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -145,12 +149,12 @@
|
|
|
<script setup lang="ts">
|
|
|
import { computed, ref } from 'vue'
|
|
|
import { ArrowRight, Plus, Delete } from '@element-plus/icons-vue'
|
|
|
-import { ElMessageBox } from 'element-plus'
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { variableType } from '@/constants'
|
|
|
import { v4 } from 'uuid'
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
-import { findVariableUsages } from '@/utils/variableBinding'
|
|
|
+import { findVariableUsages, unbindAllVariableReferences } from '@/utils/variableBinding'
|
|
|
import { SplitterCollapse, SplitterCollapseItem } from '@/components/SplitterCollapse'
|
|
|
|
|
|
import type { Variable, VariableGroup } from '@/types/variables'
|
|
|
@@ -185,14 +189,34 @@ const normalizeCVariableName = (value: string) => {
|
|
|
return validChars.replace(/^[0-9]+/, '')
|
|
|
}
|
|
|
|
|
|
-const handleVariableNameInput = (row: Variable, value: string) => {
|
|
|
- row.name = normalizeCVariableName(value)
|
|
|
+const isDuplicateVariableName = (variables: Variable[], row: Variable, name: string) => {
|
|
|
+ return !!name && variables.some((item) => item.id !== row.id && item.name === name)
|
|
|
+}
|
|
|
+
|
|
|
+const handleVariableNameInput = (row: Variable, value: string, variables: Variable[]) => {
|
|
|
+ const name = normalizeCVariableName(value)
|
|
|
+
|
|
|
+ if (isDuplicateVariableName(variables, row, name)) {
|
|
|
+ ElMessage.warning('同一组下变量名不能重复')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ row.name = name
|
|
|
}
|
|
|
|
|
|
const addVariables = (variables) => {
|
|
|
+ const names = new Set(variables.map((item) => item.name))
|
|
|
+ let index = variables.length + 1
|
|
|
+ let name = `var_${index}`
|
|
|
+
|
|
|
+ while (names.has(name)) {
|
|
|
+ index += 1
|
|
|
+ name = `var_${index}`
|
|
|
+ }
|
|
|
+
|
|
|
variables.unshift({
|
|
|
id: v4(),
|
|
|
- name: `var_${variables.length + 1}`,
|
|
|
+ name,
|
|
|
value: '',
|
|
|
type: 'char'
|
|
|
})
|
|
|
@@ -251,17 +275,15 @@ const handleVariablesRemove = (
|
|
|
}
|
|
|
|
|
|
const pages = projectStore.project?.screens.flatMap((item) => item.pages) || []
|
|
|
- const usageCount = findVariableUsages(varItem.id, [
|
|
|
- { children: pages }
|
|
|
- ] as unknown as BaseWidget[]).length
|
|
|
+ const usages = findVariableUsages(varItem.id, [{ children: pages }] as unknown as BaseWidget[])
|
|
|
|
|
|
- if (usageCount === 0) {
|
|
|
+ if (usages.length === 0) {
|
|
|
deleteVariable()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
ElMessageBox.confirm(
|
|
|
- `当前变量已被 ${usageCount} 处${scope === 'global' ? '控件属性' : '页面控件属性'}使用,删除后相关绑定将失效,是否继续删除?`,
|
|
|
+ `当前变量已被 ${usages.length} 处${scope === 'global' ? '控件属性' : '页面控件属性'}使用,删除后相关绑定将失效,是否继续删除?`,
|
|
|
'提示',
|
|
|
{
|
|
|
confirmButtonText: '确定',
|
|
|
@@ -270,6 +292,7 @@ const handleVariablesRemove = (
|
|
|
}
|
|
|
).then(() => {
|
|
|
deleteVariable()
|
|
|
+ unbindAllVariableReferences(varItem.id, [{ children: pages }] as unknown as BaseWidget[])
|
|
|
})
|
|
|
}
|
|
|
|