3939 <a-form-item
4040 name =" vlanRangeStart"
4141 ref =" vlanRangeStart"
42+ :validate-status =" validStatus"
4243 has-feedback
4344 :style =" { display: 'inline-block', width: 'calc(50% - 12px)' }" >
4445 <a-input-number
5354 <a-form-item
5455 name =" vlanRangeEnd"
5556 ref =" vlanRangeEnd"
56- has-feedback
5757 :style =" { display: 'inline-block', width: 'calc(50% - 12px)' }" >
5858 <a-input-number
5959 v-model:value =" form.vlanRangeEnd"
@@ -102,9 +102,24 @@ export default {
102102 labelCol: { span: 8 },
103103 wrapperCol: { span: 12 }
104104 },
105- validStatus: ' ' ,
106- validMessage: ' ' ,
107- formModel: {}
105+ validStatus: ' error' ,
106+ validMessage: this .$t (' message.error.vlan.range' ),
107+ formModel: {},
108+ rangeLimits: {
109+ VLAN : {
110+ min: 1 ,
111+ max: 4094
112+ },
113+ VXLAN : {
114+ min: 4096 ,
115+ max: 16777214
116+ },
117+ GRE : {
118+ min: 0 ,
119+ max: 4294967295
120+ }
121+ },
122+ isolationMethod: ' '
108123 }
109124 },
110125 watch: {
@@ -120,6 +135,7 @@ export default {
120135 this .initForm ()
121136 },
122137 mounted () {
138+ this .getIsolationMethod ()
123139 this .fillValue ()
124140 },
125141 methods: {
@@ -143,9 +159,15 @@ export default {
143159 })
144160 },
145161 fillValue () {
146- this .form .vlanRangeStart = this .getPrefilled (' vlanRangeStart' )
147- this .form .vlanRangeEnd = this .getPrefilled (' vlanRangeEnd' )
162+ const vlanStart = this .getPrefilled (' vlanRangeStart' )
163+ const vlanEnd = this .getPrefilled (' vlanRangeEnd' )
164+ this .form .vlanRangeStart = vlanStart
165+ this .form .vlanRangeEnd = vlanEnd
148166 this .formModel = toRaw (this .form )
167+ if (this .checkFromTo (vlanStart, vlanEnd)) {
168+ this .validStatus = ' success'
169+ this .validMessage = ' '
170+ }
149171 },
150172 getPrefilled (key ) {
151173 console .log (' key :>> ' , key)
@@ -158,7 +180,7 @@ export default {
158180
159181 this .formRef .value .validate ().then (() => {
160182 const values = toRaw (this .form )
161- if (! values . vlanRangeStart || ( values . vlanRangeEnd && ! this .checkFromTo (values .vlanRangeStart , values .vlanRangeEnd ) )) {
183+ if (! this .checkFromTo (values .vlanRangeStart , values .vlanRangeEnd )) {
162184 this .validStatus = ' error'
163185 this .validMessage = this .$t (' message.error.vlan.range' )
164186 return
@@ -187,19 +209,30 @@ export default {
187209 toVal = value
188210 fromVal = this .form [rule .compare ]
189211 }
190- if (fromVal && toVal && ! this .checkFromTo (fromVal, toVal)) {
212+ if (! this .checkFromTo (fromVal, toVal)) {
191213 this .validStatus = ' error'
192214 this .validMessage = this .$t (' message.error.vlan.range' )
193215 }
194216 return Promise .resolve ()
195217 },
196218 checkFromTo (fromVal , toVal ) {
197- if (! fromVal) fromVal = 0
198- if (! toVal) toVal = 0
199- if (fromVal > toVal) {
200- return false
219+ const vlanRange = this .rangeLimits [this .isolationMethod ] ? this .rangeLimits [this .isolationMethod ] : this .rangeLimits .VLAN
220+ switch (true ) {
221+ case ((fromVal === null ) || (toVal === null )):
222+ case fromVal === toVal:
223+ case fromVal > toVal:
224+ case toVal > vlanRange .max :
225+ case fromVal < vlanRange .min :
226+ return false
227+ default :
228+ this .validStatus = ' success'
229+ this .validMessage = ' '
230+ return true
201231 }
202- return true
232+ },
233+ getIsolationMethod () {
234+ const phyNetworks = this .getPrefilled (' physicalNetworks' )
235+ this .isolationMethod = phyNetworks[phyNetworks .length - 1 ].isolationMethod
203236 }
204237 }
205238}
0 commit comments