@@ -195,33 +195,21 @@ export default {
195195 }
196196 return this .networkMaps
197197 },
198+ /** form.fi.capability 与 store 可能不同步,合并后再驱动网络类型 */
199+ effectiveAutoAllocNetworkCountTt () {
200+ const cap = this .form .fi ? .capability
201+ if (cap && Object .prototype .hasOwnProperty .call (cap, ' auto_alloc_network_count' )) {
202+ return cap .auto_alloc_network_count
203+ }
204+ return this .$store .getters .capability ? .auto_alloc_network_count
205+ },
198206 },
199207 watch: {
200- ' form.fi.capability.auto_alloc_network_count' (val) {
201- if (val === 0 ) {
202- const { hypervisor } = this .form .fd || {}
203- if (hypervisor !== HYPERVISORS_MAP .proxmox .key ) {
204- this .$delete (this .networkMaps , NETWORK_OPTIONS_MAP .default .key )
205- }
206- this .form .fc .setFieldsValue ({
207- networkType: NETWORK_OPTIONS_MAP .manual .key ,
208- })
209- this .networkComponent = ' config'
210- } else {
211- const maps = { ... NETWORK_OPTIONS_MAP }
212- if (! this .defaultNetwork ) delete maps[NETWORK_OPTIONS_MAP .default .key ]
213- if (this .allowNetworkTypes && this .allowNetworkTypes .length ) {
214- this .allowNetworkTypes .forEach (key => {
215- delete maps[key]
216- })
217- }
218- this .networkMaps = maps
219- const value = {
220- networkType: NETWORK_OPTIONS_MAP [Object .keys (maps)[0 ]].key ,
221- }
222- this .form .fc .setFieldsValue (value)
223- this .networkComponent = value .networkType === NETWORK_OPTIONS_MAP .default .key ? ' ' : ' config'
224- }
208+ effectiveAutoAllocNetworkCountTt: {
209+ handler () {
210+ this .applyNetworkTypeByAutoAllocCountTt ()
211+ },
212+ immediate: true ,
225213 },
226214 async hypervisor (val , oldVal ) {
227215 if (val === HYPERVISORS_MAP .esxi .key || oldVal === HYPERVISORS_MAP .esxi .key ) {
@@ -259,6 +247,44 @@ export default {
259247 },
260248 },
261249 methods: {
250+ /** 无自动分配(0 / 未下发 / 空)时网络类型应为「指定 IP 子网」(compute.text_2,界面常称「其他」) */
251+ applyNetworkTypeByAutoAllocCountTt () {
252+ const val = this .effectiveAutoAllocNetworkCountTt
253+ const noAutoAlloc = val == null || val === ' ' || Number (val) <= 0
254+ if (noAutoAlloc) {
255+ const { hypervisor } = this .form .fd || {}
256+ if (hypervisor !== HYPERVISORS_MAP .proxmox .key ) {
257+ this .$delete (this .networkMaps , NETWORK_OPTIONS_MAP .default .key )
258+ }
259+ const manual = NETWORK_OPTIONS_MAP .manual .key
260+ this .$nextTick (() => {
261+ this .form .fc .setFieldsValue ({ networkType: manual })
262+ if (this .form .fd ) {
263+ this .form .fd .networkType = manual
264+ }
265+ this .networkComponent = ' config'
266+ })
267+ } else {
268+ const maps = { ... NETWORK_OPTIONS_MAP }
269+ if (! this .defaultNetwork ) delete maps[NETWORK_OPTIONS_MAP .default .key ]
270+ if (this .allowNetworkTypes && this .allowNetworkTypes .length ) {
271+ this .allowNetworkTypes .forEach (key => {
272+ delete maps[key]
273+ })
274+ }
275+ this .networkMaps = maps
276+ const value = {
277+ networkType: NETWORK_OPTIONS_MAP [Object .keys (maps)[0 ]].key ,
278+ }
279+ this .$nextTick (() => {
280+ this .form .fc .setFieldsValue (value)
281+ if (this .form .fd ) {
282+ this .form .fd .networkType = value .networkType
283+ }
284+ this .networkComponent = value .networkType === NETWORK_OPTIONS_MAP .default .key ? ' ' : ' config'
285+ })
286+ }
287+ },
262288 change (e ) {
263289 if (this .form .fd ) {
264290 this .form .fd .networkType = e .target .value
0 commit comments