Commit b481e3199bdb2f3a6bb745ede38d7704ffaf469d
1 parent
7be76707
fix: 产品详情物模型,新增验证结构体中的标识符是否存在一致的情况
Showing
2 changed files
with
20 additions
and
2 deletions
| ... | ... | @@ -7,21 +7,28 @@ |
| 7 | 7 | import { BasicForm, useForm } from '/@/components/Form'; |
| 8 | 8 | import { formSchemas } from './config'; |
| 9 | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
| 10 | - import { OpenModalMode, OpenModalParams } from './type'; | |
| 10 | + import { OpenModalMode, OpenModalParams, StructRecord } from './type'; | |
| 11 | 11 | import { ref, unref } from 'vue'; |
| 12 | 12 | import { transfromToStructJSON } from './util'; |
| 13 | 13 | import { cloneDeep } from 'lodash-es'; |
| 14 | 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| 15 | 15 | import { isArray } from '/@/utils/is'; |
| 16 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
| 16 | 17 | |
| 17 | 18 | const modalReceiveRecord = ref<OpenModalParams>({ |
| 18 | 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 | 28 | const emit = defineEmits(['register', 'submit']); |
| 24 | 29 | |
| 30 | + const { createMessage } = useMessage(); | |
| 31 | + | |
| 25 | 32 | const [register, { validate, setFieldsValue, setProps }] = useForm({ |
| 26 | 33 | labelWidth: 100, |
| 27 | 34 | schemas: formSchemas(props.hasStructForm), |
| ... | ... | @@ -52,6 +59,10 @@ |
| 52 | 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 | 66 | const handleSubmit = async () => { |
| 56 | 67 | try { |
| 57 | 68 | const _value = await validate(); |
| ... | ... | @@ -62,6 +73,12 @@ |
| 62 | 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 | 82 | emit('submit', unref(modalReceiveRecord).mode, cloneDeep(value)); |
| 66 | 83 | closeModal(); |
| 67 | 84 | } catch (error) {} | ... | ... |