1
1
<template >
2
- <el-form-item label =" 数据类型" prop =" dataType" >
2
+ <el-form-item
3
+ :rules =" [{ required: true, message: '请选择数据类型', trigger: 'change' }]"
4
+ label =" 数据类型"
5
+ prop =" property.dataType"
6
+ >
3
7
<el-select v-model =" property.dataType" placeholder =" 请选择数据类型" @change =" handleChange" >
4
8
<el-option
5
9
v-for =" option in dataTypeOptions"
24
28
v-model =" property.dataSpecsList"
25
29
/>
26
30
<!-- 布尔型配置 -->
27
- <el-form-item v-if =" property.dataType === DataSpecsDataType.BOOL" label =" 布尔值" prop =" bool" >
28
- <template v-for =" item in property .dataSpecsList " :key =" item .value " >
31
+ <el-form-item
32
+ v-if =" property.dataType === DataSpecsDataType.BOOL"
33
+ :rules =" [{ required: true, message: '请输入布尔值名称', trigger: 'blur' }]"
34
+ label =" 布尔值"
35
+ prop =" property.dataSpecsList"
36
+ >
37
+ <template v-for =" (item , index ) in property .dataSpecsList " :key =" item .value " >
29
38
<div class =" flex items-center justify-start w-1/1 mb-5px" >
30
39
<span >{{ item.value }}</span >
31
40
<span class =" mx-2" >-</span >
32
- <el-input
33
- v-model =" item.name"
34
- :placeholder =" `如:${item.value === 0 ? '关' : '开'}`"
35
- class =" w-255px!"
36
- />
41
+ <el-form-item
42
+ :prop =" `property.dataSpecsList[${index}].name`"
43
+ :rules =" [
44
+ { required: true, message: '枚举描述不能为空' },
45
+ { validator: validateBoolName, trigger: 'blur' }
46
+ ]"
47
+ class =" flex-1 mb-0"
48
+ >
49
+ <el-input
50
+ v-model =" item.name"
51
+ :placeholder =" `如:${item.value === 0 ? '关' : '开'}`"
52
+ class =" w-255px!"
53
+ />
54
+ </el-form-item >
37
55
</div >
38
56
</template >
39
57
</el-form-item >
40
58
<!-- 文本型配置 -->
41
- <el-form-item v-if =" property.dataType === DataSpecsDataType.TEXT" label =" 数据长度" prop =" text" >
59
+ <el-form-item
60
+ v-if =" property.dataType === DataSpecsDataType.TEXT"
61
+ :rules =" [
62
+ { required: true, message: '请输入文本字节长度', trigger: 'blur' },
63
+ { validator: validateTextLength, trigger: 'blur' }
64
+ ]"
65
+ label =" 数据长度"
66
+ prop =" property.dataSpecs.length"
67
+ >
42
68
<el-input v-model =" property.dataSpecs.length" class =" w-255px!" placeholder =" 请输入文本字节长度" >
43
69
<template #append >字节</template >
44
70
</el-input >
53
79
v-model =" property.dataSpecs"
54
80
/>
55
81
<!-- TODO puhui999: Struct 属性待完善 -->
56
- <el-form-item label =" 读写类型" prop =" accessMode" >
82
+ <el-form-item
83
+ :rules =" [{ required: true, message: '请选择读写类型', trigger: 'change' }]"
84
+ label =" 读写类型"
85
+ prop =" property.accessMode"
86
+ >
57
87
<el-radio-group v-model =" property.accessMode" >
58
88
<el-radio label =" rw" >读写</el-radio >
59
89
<el-radio label =" r" >只读</el-radio >
60
90
</el-radio-group >
61
91
</el-form-item >
62
92
<el-form-item label =" 属性描述" prop =" description" >
63
- <el-input v-model =" property.description" placeholder =" 请输入属性描述" type =" textarea" />
93
+ <el-input
94
+ v-model =" property.description"
95
+ :maxlength =" 200"
96
+ :rows =" 3"
97
+ placeholder =" 请输入属性描述"
98
+ type =" textarea"
99
+ />
64
100
</el-form-item >
65
101
</template >
66
102
@@ -73,6 +109,7 @@ import {
73
109
ThingModelNumberTypeDataSpecs
74
110
} from ' ./dataSpecs'
75
111
import { ThingModelProperty } from ' @/api/iot/thinkmodelfunction'
112
+ import { isEmpty } from ' @/utils/is'
76
113
77
114
/** 物模型数据 */
78
115
defineOptions ({ name: ' ThingModelDataSpecs' })
@@ -105,6 +142,53 @@ const handleChange = (dataType: any) => {
105
142
break
106
143
}
107
144
}
145
+
146
+ /** 校验布尔值名称 */
147
+ const validateBoolName = (_ : any , value : string , callback : any ) => {
148
+ if (isEmpty (value )) {
149
+ callback (new Error (' 布尔值名称不能为空' ))
150
+ return
151
+ }
152
+
153
+ // 检查开头字符
154
+ if (! / ^ [\u4e00 -\u9fa5 a-zA-Z0-9 ] / .test (value )) {
155
+ callback (new Error (' 布尔值名称必须以中文、英文字母或数字开头' ))
156
+ return
157
+ }
158
+
159
+ // 检查整体格式
160
+ if (! / ^ [\u4e00 -\u9fa5 a-zA-Z0-9 ][a-zA-Z0-9\u4e00 -\u9fa5 _-] * $ / .test (value )) {
161
+ callback (new Error (' 布尔值名称只能包含中文、英文字母、数字、下划线和短划线' ))
162
+ return
163
+ }
164
+
165
+ // 检查长度(一个中文算一个字符)
166
+ if (value .length > 20 ) {
167
+ callback (new Error (' 布尔值名称长度不能超过20个字符' ))
168
+ return
169
+ }
170
+
171
+ callback ()
172
+ }
173
+
174
+ /** 校验文本长度 */
175
+ const validateTextLength = (_ : any , value : any , callback : any ) => {
176
+ if (isEmpty (value )) {
177
+ callback (new Error (' 文本长度不能为空' ))
178
+ return
179
+ }
180
+ if (isNaN (Number (value ))) {
181
+ callback (new Error (' 文本长度必须是数字' ))
182
+ return
183
+ }
184
+ callback ()
185
+ }
108
186
</script >
109
187
110
- <style lang="scss" scoped></style >
188
+ <style lang="scss" scoped>
189
+ :deep(.el-form-item ) {
190
+ .el-form-item {
191
+ margin-bottom : 0 ;
192
+ }
193
+ }
194
+ </style >
0 commit comments