Commit b481e3199bdb2f3a6bb745ede38d7704ffaf469d
1 parent
7be76707
fix: 产品详情物模型,新增验证结构体中的标识符是否存在一致的情况
Showing
2 changed files
with
20 additions
and
2 deletions
| @@ -110,6 +110,7 @@ | @@ -110,6 +110,7 @@ | ||
| 110 | <StructFormModel | 110 | <StructFormModel |
| 111 | :has-struct-form="$props.hasStructForm!" | 111 | :has-struct-form="$props.hasStructForm!" |
| 112 | :disabled="$props.disabled" | 112 | :disabled="$props.disabled" |
| 113 | + :value-list="getValue" | ||
| 113 | @register="registerModal" | 114 | @register="registerModal" |
| 114 | @submit="handleSaveStruct" | 115 | @submit="handleSaveStruct" |
| 115 | /> | 116 | /> |
| @@ -7,21 +7,28 @@ | @@ -7,21 +7,28 @@ | ||
| 7 | import { BasicForm, useForm } from '/@/components/Form'; | 7 | import { BasicForm, useForm } from '/@/components/Form'; |
| 8 | import { formSchemas } from './config'; | 8 | import { formSchemas } from './config'; |
| 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
| 10 | - import { OpenModalMode, OpenModalParams } from './type'; | 10 | + import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
| 11 | import { ref, unref } from 'vue'; | 11 | import { ref, unref } from 'vue'; |
| 12 | import { transfromToStructJSON } from './util'; | 12 | import { transfromToStructJSON } from './util'; |
| 13 | import { cloneDeep } from 'lodash-es'; | 13 | import { cloneDeep } from 'lodash-es'; |
| 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| 15 | import { isArray } from '/@/utils/is'; | 15 | import { isArray } from '/@/utils/is'; |
| 16 | + import { useMessage } from '/@/hooks/web/useMessage'; | ||
| 16 | 17 | ||
| 17 | const modalReceiveRecord = ref<OpenModalParams>({ | 18 | const modalReceiveRecord = ref<OpenModalParams>({ |
| 18 | mode: OpenModalMode.CREATE, | 19 | mode: OpenModalMode.CREATE, |
| 19 | }); | 20 | }); |
| 20 | 21 | ||
| 21 | - const props = defineProps<{ disabled: boolean; hasStructForm: boolean }>(); | 22 | + const props = defineProps<{ |
| 23 | + disabled: boolean; | ||
| 24 | + hasStructForm: boolean; | ||
| 25 | + valueList: StructRecord[]; | ||
| 26 | + }>(); | ||
| 22 | 27 | ||
| 23 | const emit = defineEmits(['register', 'submit']); | 28 | const emit = defineEmits(['register', 'submit']); |
| 24 | 29 | ||
| 30 | + const { createMessage } = useMessage(); | ||
| 31 | + | ||
| 25 | const [register, { validate, setFieldsValue, setProps }] = useForm({ | 32 | const [register, { validate, setFieldsValue, setProps }] = useForm({ |
| 26 | labelWidth: 100, | 33 | labelWidth: 100, |
| 27 | schemas: formSchemas(props.hasStructForm), | 34 | schemas: formSchemas(props.hasStructForm), |
| @@ -52,6 +59,10 @@ | @@ -52,6 +59,10 @@ | ||
| 52 | setProps({ disabled: props.disabled }); | 59 | setProps({ disabled: props.disabled }); |
| 53 | }); | 60 | }); |
| 54 | 61 | ||
| 62 | + const validateRepeat = (value: StructRecord, valueList: StructRecord[]) => { | ||
| 63 | + return valueList.filter((item) => item.identifier === value.identifier).length >= 1; | ||
| 64 | + }; | ||
| 65 | + | ||
| 55 | const handleSubmit = async () => { | 66 | const handleSubmit = async () => { |
| 56 | try { | 67 | try { |
| 57 | const _value = await validate(); | 68 | const _value = await validate(); |
| @@ -62,6 +73,12 @@ | @@ -62,6 +73,12 @@ | ||
| 62 | ? { id: unref(modalReceiveRecord)?.record?.id } | 73 | ? { id: unref(modalReceiveRecord)?.record?.id } |
| 63 | : {}), | 74 | : {}), |
| 64 | }; | 75 | }; |
| 76 | + | ||
| 77 | + if (validateRepeat(_value, props.valueList)) { | ||
| 78 | + createMessage.error('存在一致的标识符'); | ||
| 79 | + return; | ||
| 80 | + } | ||
| 81 | + | ||
| 65 | emit('submit', unref(modalReceiveRecord).mode, cloneDeep(value)); | 82 | emit('submit', unref(modalReceiveRecord).mode, cloneDeep(value)); |
| 66 | closeModal(); | 83 | closeModal(); |
| 67 | } catch (error) {} | 84 | } catch (error) {} |