Showing
1 changed file
with
26 additions
and
2 deletions
1 | 1 | <script setup lang="ts"> |
2 | 2 | import { Button, Tooltip } from 'ant-design-vue'; |
3 | - import { nextTick, ref, unref, watch } from 'vue'; | |
3 | + import { computed, nextTick, ref, unref, watch } from 'vue'; | |
4 | 4 | import { useForm, BasicForm } from '/@/components/Form'; |
5 | 5 | import { Specs } from '/@/api/device/model/modelOfMatterModel'; |
6 | 6 | import { Icon } from '/@/components/Icon'; |
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | import { FormActionType } from '../../../types/form'; |
9 | 9 | import { buildUUID } from '/@/utils/uuid'; |
10 | 10 | import { DataTypeEnum } from '/@/enums/objectModelEnum'; |
11 | + import { isNullOrUnDef } from '/@/utils/is'; | |
11 | 12 | |
12 | 13 | const props = defineProps<{ disabled?: boolean; value?: Specs[] }>(); |
13 | 14 | |
... | ... | @@ -29,10 +30,27 @@ |
29 | 30 | item.formActionType = el as unknown as FormActionType; |
30 | 31 | }; |
31 | 32 | |
33 | + const getEnumsLimit = computed(() => unref(enumsListElRef).length >= 100); | |
34 | + | |
35 | + const hasSameEnum = ref(false); | |
36 | + | |
37 | + const validateSameEnum = () => { | |
38 | + const value = getFieldsValue(); | |
39 | + hasSameEnum.value = false; | |
40 | + const values = value.map((item) => item.value).filter((value) => !isNullOrUnDef(value)); | |
41 | + const names = value.map((item) => item.name).filter((value) => !isNullOrUnDef(value)); | |
42 | + | |
43 | + if (values.length !== new Set(values).size || names.length !== new Set(names).size) { | |
44 | + hasSameEnum.value = true; | |
45 | + } | |
46 | + }; | |
47 | + | |
32 | 48 | const validate = async () => { |
49 | + if (unref(hasSameEnum)) throw Error('存在相同的枚举'); | |
33 | 50 | for (const enumElItem of unref(enumsListElRef)) { |
34 | 51 | await enumElItem.formActionType?.validate?.(); |
35 | 52 | } |
53 | + validateSameEnum(); | |
36 | 54 | }; |
37 | 55 | |
38 | 56 | const getFieldsValue = () => { |
... | ... | @@ -107,6 +125,7 @@ |
107 | 125 | @register="registerForm" |
108 | 126 | class="enums-form" |
109 | 127 | :disabled="disabled" |
128 | + @field-value-change="validateSameEnum" | |
110 | 129 | > |
111 | 130 | <template #division> |
112 | 131 | <div>~</div> |
... | ... | @@ -122,7 +141,12 @@ |
122 | 141 | </Button> |
123 | 142 | </section> |
124 | 143 | </main> |
125 | - <Button type="link" @click="handleAddEnums" :disabled="disabled">+添加枚举项</Button> | |
144 | + <div v-if="hasSameEnum" class="text-red-400">枚举项中存在相同的参数值或参数描述</div> | |
145 | + <Tooltip title="枚举项最多创建 100 个"> | |
146 | + <Button type="link" @click="handleAddEnums" :disabled="disabled || getEnumsLimit"> | |
147 | + +添加枚举项 | |
148 | + </Button> | |
149 | + </Tooltip> | |
126 | 150 | </section> |
127 | 151 | </template> |
128 | 152 | ... | ... |