Skip to content

Commit 6b9aaf3

Browse files
author
puhui999
committed
【功能完善】IOT: 产品物模型-数组型的 dataSpecs 校验规则完善
1 parent 12abcdd commit 6b9aaf3

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed
Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
11
<template>
2-
<el-form-item label="元素类型" prop="childDataType">
2+
<el-form-item
3+
:rules="[{ required: true, message: '元素类型不能为空' }]"
4+
label="元素类型"
5+
prop="property.dataSpecs.childDataType"
6+
>
37
<el-radio-group v-model="dataSpecs.childDataType">
48
<template v-for="item in dataTypeOptions" :key="item.value">
59
<el-radio
6-
:value="item.value"
710
v-if="
811
!(
912
[DataSpecsDataType.ENUM, DataSpecsDataType.ARRAY, DataSpecsDataType.DATE] as any[]
1013
).includes(item.value)
1114
"
15+
:value="item.value"
1216
>
1317
{{ item.label }}
1418
</el-radio>
1519
</template>
1620
</el-radio-group>
1721
</el-form-item>
18-
<el-form-item label="元素个数" prop="size">
22+
<el-form-item
23+
:rules="[
24+
{ required: true, message: '元素个数不能为空' },
25+
{ validator: validateSize, trigger: 'blur' }
26+
]"
27+
label="元素个数"
28+
prop="property.dataSpecs.size"
29+
>
1930
<el-input v-model="dataSpecs.size" placeholder="请输入数组中的元素个数" />
2031
</el-form-item>
2132
</template>
2233

2334
<script lang="ts" setup>
2435
import { useVModel } from '@vueuse/core'
2536
import { DataSpecsDataType, dataTypeOptions } from '../config'
37+
import { isEmpty } from '@/utils/is'
2638
2739
/** 数组型的 dataSpecs 配置组件 */
2840
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
2941
const props = defineProps<{ modelValue: any }>()
3042
const emits = defineEmits(['update:modelValue'])
3143
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>
44+
45+
/** 校验元素个数 */
46+
const validateSize = (_: any, value: any, callback: any) => {
47+
if (isEmpty(value)) {
48+
callback(new Error('元素个数不能为空'))
49+
return
50+
}
51+
if (isNaN(Number(value))) {
52+
callback(new Error('元素个数必须是数字'))
53+
return
54+
}
55+
callback()
56+
}
3257
</script>
3358

3459
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)