11<template >
22 <div class =" attr-header" >
3- <span class =" header-title" >自定义属性 </span >
3+ <span class =" header-title" >原生属性 </span >
44 <tiny-popover
55 v-model =" state.visible"
66 placement =" bottom"
1111 >
1212 <div class =" attr-form" >
1313 <icon-close class =" icon-close" @click =" closePopover" ></icon-close >
14- <tiny-form label-position =" left" label-width =" 53px" >
15- <tiny-form-item label =" name" >
14+ <tiny-form
15+ ref =" attrFormRef"
16+ :model =" state.formData"
17+ :rules =" rules"
18+ validate-type =" text"
19+ label-position =" left"
20+ label-width =" 53px"
21+ >
22+ <tiny-form-item label =" name" prop =" key" >
1623 <tiny-input v-model =" state.formData.key" ></tiny-input >
1724 </tiny-form-item >
18- <tiny-form-item label =" value" >
25+ <tiny-form-item label =" value" prop = " value " >
1926 <tiny-input v-model =" state.formData.value" ></tiny-input >
2027 </tiny-form-item >
2128 <div class =" footer" >
@@ -80,9 +87,18 @@ export default {
8087 currentAttr: {}
8188 })
8289
90+ const attrFormRef = ref ()
8391 const attrs = ref ([])
8492 const properties = [' style' ]
8593
94+ const rules = {
95+ key: [
96+ { required: true , message: ' 名称必填' , trigger: ' blur' },
97+ { max: 20 , message: ' 长度不大于20' , trigger: ' change' }
98+ ],
99+ value: [{ max: 200 , message: ' 长度不大于200' , trigger: ' change' }]
100+ }
101+
86102 watchEffect (() => {
87103 if (! useProperties ().getSchema ()? .props ) {
88104 return
@@ -143,24 +159,29 @@ export default {
143159 }
144160
145161 const save = () => {
146- state .visible = false
147- const data = {}
148- let index = - 1
162+ attrFormRef .value .validate ((valid ) => {
163+ if (! valid) {
164+ return
165+ }
166+ state .visible = false
167+ const data = {}
168+ let index = - 1
149169
150- if (state .currentAttr .id ) {
151- index = attrs .value .findIndex ((item ) => item .id === state .currentAttr .id )
152- data .id = state .currentAttr .id
153- state .currentAttr = {}
154- } else {
155- data .id = utils .guid ()
156- index = attrs .value .length
157- }
170+ if (state .currentAttr .id ) {
171+ index = attrs .value .findIndex ((item ) => item .id === state .currentAttr .id )
172+ data .id = state .currentAttr .id
173+ state .currentAttr = {}
174+ } else {
175+ data .id = utils .guid ()
176+ index = attrs .value .length
177+ }
158178
159- data .text = ` ${ state .formData .key } = '${ state .formData .value } '`
160- data .data = { key: state .formData .key , value: state .formData .value }
179+ data .text = ` ${ state .formData .key } = '${ state .formData .value } '`
180+ data .data = { key: state .formData .key , value: state .formData .value }
161181
162- attrs .value .splice (index, 1 , data)
163- updateSchema ()
182+ attrs .value .splice (index, 1 , data)
183+ updateSchema ()
184+ })
164185 }
165186
166187 const edit = (attr ) => {
@@ -186,7 +207,9 @@ export default {
186207 }
187208
188209 return {
210+ attrFormRef,
189211 state,
212+ rules,
190213 cancel,
191214 save,
192215 attrs,
@@ -247,6 +270,11 @@ export default {
247270 display: grid;
248271 grid- template- columns: 3fr auto;
249272
273+ .item - content {
274+ word- wrap: break - word;
275+ white- space: normal;
276+ word- break: break - all;
277+ }
250278 .item - controller {
251279 display: grid;
252280 column- gap: 3px ;
0 commit comments