|
1 | 1 | <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 | + > |
3 | 7 | <el-radio-group v-model="dataSpecs.childDataType">
|
4 | 8 | <template v-for="item in dataTypeOptions" :key="item.value">
|
5 | 9 | <el-radio
|
6 |
| - :value="item.value" |
7 | 10 | v-if="
|
8 | 11 | !(
|
9 | 12 | [DataSpecsDataType.ENUM, DataSpecsDataType.ARRAY, DataSpecsDataType.DATE] as any[]
|
10 | 13 | ).includes(item.value)
|
11 | 14 | "
|
| 15 | + :value="item.value" |
12 | 16 | >
|
13 | 17 | {{ item.label }}
|
14 | 18 | </el-radio>
|
15 | 19 | </template>
|
16 | 20 | </el-radio-group>
|
17 | 21 | </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 | + > |
19 | 30 | <el-input v-model="dataSpecs.size" placeholder="请输入数组中的元素个数" />
|
20 | 31 | </el-form-item>
|
21 | 32 | </template>
|
22 | 33 |
|
23 | 34 | <script lang="ts" setup>
|
24 | 35 | import { useVModel } from '@vueuse/core'
|
25 | 36 | import { DataSpecsDataType, dataTypeOptions } from '../config'
|
| 37 | +import { isEmpty } from '@/utils/is' |
26 | 38 |
|
27 | 39 | /** 数组型的 dataSpecs 配置组件 */
|
28 | 40 | defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
|
29 | 41 | const props = defineProps<{ modelValue: any }>()
|
30 | 42 | const emits = defineEmits(['update:modelValue'])
|
31 | 43 | 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 | +} |
32 | 57 | </script>
|
33 | 58 |
|
34 | 59 | <style lang="scss" scoped></style>
|
0 commit comments