bfg-common 1.4.818 → 1.4.820

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,693 +1,694 @@
1
- <template>
2
- <common-vm-actions-common-customize-hardware-virtual-hardware-new
3
- v-if="isNewView"
4
- v-model:cpu-invalid="cpuInvalid"
5
- v-model:memory-invalid="memoryInvalid"
6
- v-model:video-card-invalid="videoCardInvalid"
7
- :nodes="props.nodes"
8
- :files="props.files"
9
- :is-edit="props.isEdit"
10
- :storage="props.storage"
11
- :project="props.project"
12
- :max-cpus="props.maxCpus"
13
- :max-memory="props.maxMemory"
14
- :cpu-models="props.cpuModels"
15
- :datastore="props.datastore"
16
- :networks-type="networksType"
17
- :networks-table="props.networksTable"
18
- :dropdown-items="dropdownItems"
19
- :hard-disks-type="hardDisksType"
20
- :networks-index="networksIndex"
21
- :hard-disks-index="hardDisksIndex"
22
- :pci-devices-type="pciDevicesType"
23
- :is-show-file-modal="isShowFileModal"
24
- :pci-devices-index="pciDevicesIndex"
25
- :cd-dvd-drives-type="cdDvdDrivesType"
26
- :cd-dvd-drives-index="cdDvdDrivesIndex"
27
- :error-validation-fields="errorValidationFields"
28
- :get-datastore-table-func="getDatastoreTableFunc"
29
- :cpu="cpu"
30
- :state="state"
31
- :memory="memory"
32
- :networks="networksLocal"
33
- :hard-disks="hardDisksLocal"
34
- :video-card="videoCard"
35
- :pci-devices="pciDevicesLocal"
36
- :cd-dvd-drives="cdDvdDrivesLocal"
37
- :usb-controller="usbController"
38
- :guest-machine-type="guestMachineType"
39
- :passthrough-devices="passthroughDevices"
40
- :mediated-devices="mediatedDevices"
41
- :vm-cpu-help-text-second="vmCpuHelpTextSecond"
42
- @add-device="onAddDevice"
43
- @get-storage="emits('get-storage', $event)"
44
- @remove-network="onRemoveNetwork"
45
- @hide-file-modal="isShowFileModal = false"
46
- @remove-hard-disk="onRemoveHardDisk(...$event)"
47
- @remove-pci-device="onRemovePciDevice"
48
- @get-networks-table="emits('get-networks-table', $event)"
49
- @add-exist-hard-disk="onAddExistHardDisk"
50
- @roll-back-hard-disk="onRollBackHardDisk"
51
- @set-invalid-network="onSetInvalidNetwork(...$event)"
52
- @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
53
- @show-datastore-child="emits('show-datastore-child', $event)"
54
- @get-folders-or-files="emits('get-folders-or-files', $event)"
55
- @send-data-cpu-method="onSendDataCpuMethod"
56
- @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
57
- @remove-error-by-title="emits('remove-error-by-title', $event)"
58
- @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
59
- @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
60
- @get-active-device-child="emits('get-active-device-child', $event)"
61
- @send-data-memory-method="onSendDataMemoryMethod"
62
- @send-data-video-card-method="onSendDataVideoCardMethod"
63
- @send-data-new-network-method="sendDataNewNetworkMethod(...$event)"
64
- @send-data-pci-devices-method="onSendDataPciDevicesMethod(...$event)"
65
- @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
66
- @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
67
- @send-data-new-usb-controller-method="onSendDataNewUsbControllerMethod"
68
- />
69
- <common-vm-actions-common-customize-hardware-virtual-hardware-old
70
- v-else
71
- v-model:cpu-invalid="cpuInvalid"
72
- v-model:memory-invalid="memoryInvalid"
73
- v-model:video-card-invalid="videoCardInvalid"
74
- :nodes="props.nodes"
75
- :files="props.files"
76
- :is-edit="props.isEdit"
77
- :storage="props.storage"
78
- :project="props.project"
79
- :max-cpus="props.maxCpus"
80
- :max-memory="props.maxMemory"
81
- :cpu-models="props.cpuModels"
82
- :datastore="props.datastore"
83
- :networks-type="networksType"
84
- :networks-table="props.networksTable"
85
- :dropdown-items="dropdownItems"
86
- :hard-disks-type="hardDisksType"
87
- :networks-index="networksIndex"
88
- :hard-disks-index="hardDisksIndex"
89
- :pci-devices-type="pciDevicesType"
90
- :is-show-file-modal="isShowFileModal"
91
- :pci-devices-index="pciDevicesIndex"
92
- :cd-dvd-drives-type="cdDvdDrivesType"
93
- :cd-dvd-drives-index="cdDvdDrivesIndex"
94
- :error-validation-fields="errorValidationFields"
95
- :get-datastore-table-func="getDatastoreTableFunc"
96
- :cpu="cpu"
97
- :state="state"
98
- :memory="memory"
99
- :networks="networksLocal"
100
- :hard-disks="hardDisksLocal"
101
- :video-card="videoCard"
102
- :pci-devices="pciDevicesLocal"
103
- :cd-dvd-drives="cdDvdDrivesLocal"
104
- :usb-controller="usbController"
105
- :guest-machine-type="guestMachineType"
106
- :passthrough-devices="passthroughDevices"
107
- :mediated-devices="mediatedDevices"
108
- :vm-cpu-help-text-second="vmCpuHelpTextSecond"
109
- @add-device="onAddDevice"
110
- @get-storage="emits('get-storage', $event)"
111
- @remove-network="onRemoveNetwork"
112
- @hide-file-modal="isShowFileModal = false"
113
- @remove-hard-disk="onRemoveHardDisk(...$event)"
114
- @remove-pci-device="onRemovePciDevice"
115
- @get-networks-table="emits('get-networks-table', $event)"
116
- @add-exist-hard-disk="onAddExistHardDisk"
117
- @roll-back-hard-disk="onRollBackHardDisk"
118
- @set-invalid-network="onSetInvalidNetwork(...$event)"
119
- @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
120
- @show-datastore-child="emits('show-datastore-child', $event)"
121
- @get-folders-or-files="emits('get-folders-or-files', $event)"
122
- @send-data-cpu-method="onSendDataCpuMethod"
123
- @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
124
- @remove-error-by-title="emits('remove-error-by-title', $event)"
125
- @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
126
- @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
127
- @get-active-device-child="emits('get-active-device-child', $event)"
128
- @send-data-memory-method="onSendDataMemoryMethod"
129
- @send-data-video-card-method="onSendDataVideoCardMethod"
130
- @send-data-new-network-method="sendDataNewNetworkMethod(...$event)"
131
- @send-data-pci-devices-method="onSendDataPciDevicesMethod(...$event)"
132
- @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
133
- @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
134
- @send-data-new-usb-controller-method="onSendDataNewUsbControllerMethod"
135
- />
136
- </template>
137
-
138
- <script setup lang="ts">
139
- import type { UI_T_Project } from '~/lib/models/types'
140
- import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
141
- import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
142
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
143
- import type { UI_I_FolderOrFileTreePayload } from '~/lib/models/store/storage/interfaces'
144
- import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
145
- import type {
146
- UI_I_SendDataCpu,
147
- UI_I_SendDataMemory,
148
- UI_I_SendDataNewHardDisk,
149
- UI_I_SendDataNewNetwork,
150
- UI_I_SendDataVideoCard,
151
- UI_I_InvalidKeys,
152
- UI_I_SendDataVirtualHardware,
153
- UI_I_SendDataNewCdDvdDrive,
154
- // UI_I_HardDisk,
155
- UI_I_SendDataNewPciDevice,
156
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
157
- import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
158
- import type {
159
- UI_T_HardDiskType,
160
- UI_T_NetworkType,
161
- UI_T_CdDvdType,
162
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/types'
163
- import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
164
- import type {
165
- UI_I_DropdownTreeItem,
166
- UI_I_DropdownTreeItemChild,
167
- } from '~/components/atoms/dropdown/tree/lib/models/interfaces'
168
- import type { UI_I_Localization } from '~/lib/models/interfaces'
169
- import type {
170
- API_UI_I_VmEditCpu,
171
- API_UI_I_VmEditMemory, UI_I_MediatedDevice,
172
- UI_I_PciDevice,
173
- } from '~/lib/models/store/vm/interfaces'
174
- import { dropdownItemsFunc } from './lib/config/dropdownItems'
175
-
176
- const props = defineProps<{
177
- storage: UI_I_DatastoreTableItem | null
178
- cpuModels: UI_I_OptionItem[]
179
- maxCpus: number
180
- maxMemory: number
181
- isEdit: boolean
182
- isClone: boolean
183
- errorValidationFields: UI_I_ErrorValidationField<string>[]
184
- nodes: UI_I_FileTreeNode[]
185
- files: UI_I_FileTreeNode[]
186
- networksTable: UI_I_NetworkTableItem[]
187
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
188
- datastore: UI_I_DatastoreTableItem[]
189
- state?: string | number
190
- cpu?: API_UI_I_VmEditCpu
191
- memory?: API_UI_I_VmEditMemory
192
- vmCpuHelpTextSecond?: string
193
- hardDisks?: UI_I_SendDataNewHardDisk[] | null
194
- cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
195
- networks?: UI_I_SendDataNewNetwork[] | null
196
- videoCard?: UI_I_SendDataVideoCard
197
- usbController?: string
198
- pciDevices?: UI_I_SendDataNewPciDevice[]
199
- passthroughDevices?: UI_I_PciDevice[]
200
- mediatedDevices?: UI_I_MediatedDevice[]
201
- project: UI_T_Project
202
- guestMachineType?: UI_I_OptionItem | null
203
- }>()
204
- const emits = defineEmits<{
205
- (event: 'send-data', value: UI_I_SendDataVirtualHardware): void
206
- (event: 'invalid', value: string[]): void
207
- (event: 'get-storage', value: UI_I_TablePayload): void
208
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
209
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
210
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
211
- (event: 'remove-error-by-title', value: string): void
212
- (event: 'get-networks-table', value: UI_I_TablePayload): void
213
- (event: 'get-pci-devices'): void
214
- }>()
215
-
216
- const { $store, $binary }: any = useNuxtApp()
217
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
218
-
219
- const localization = computed<UI_I_Localization>(() => useLocal())
220
-
221
- const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
222
- dropdownItemsFunc(
223
- localization.value,
224
- props.state,
225
- props.passthroughDevices,
226
- props.mediatedDevices
227
- )
228
- )
229
-
230
- const hardDisksIndex = ref<number[]>([0])
231
- const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
232
- const hardDisksLocal = ref<UI_I_SendDataNewHardDisk[]>([
233
- {
234
- create: true,
235
- size: 90,
236
- source: '',
237
- boot_order: -1,
238
- },
239
- ])
240
- watch(
241
- () => props.hardDisks,
242
- (newValue) => {
243
- if ((!props.isEdit && !props.isClone) || !newValue) return
244
-
245
- const count = newValue?.length || 0
246
- hardDisksIndex.value = [...Array(count).keys()]
247
- hardDisksLocal.value = newValue
248
- if (props.isEdit) {
249
- hardDisksType.value = Array(count).fill('edit')
250
- } else if (props.isClone) {
251
- hardDisksType.value = Array(count).fill('new')
252
- hardDisksLocal.value = newValue.map((hardDisk) => {
253
- hardDisk.create = true
254
- return hardDisk
255
- })
256
- }
257
- },
258
- { immediate: true }
259
- )
260
-
261
- const addHardDisk = (
262
- create = true,
263
- size = 90,
264
- source = '',
265
- type: UI_T_HardDiskType = 'new',
266
- provisioned_type?: number // При добавлении существующей
267
- ): void => {
268
- const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
269
- hardDisksIndex.value.push(newIndex)
270
- hardDisksType.value.push(type)
271
-
272
- let provisionType = 'thick'
273
- if (provisioned_type === 1) provisionType = 'thin'
274
-
275
- hardDisksLocal.value.push({
276
- create,
277
- size,
278
- source,
279
- attach: true,
280
- boot_order: 0, // Убираем галочку
281
- provision_type: provisionType,
282
- })
283
- sendData()
284
- }
285
- const onAddExistHardDisk = (file: UI_I_FileTreeNode): void => {
286
- addHardDisk(
287
- false,
288
- $binary.bToGb(file.size),
289
- file.path,
290
- 'exist',
291
- file.provisioned_type
292
- )
293
- }
294
- const onRemoveHardDisk = (
295
- index: number,
296
- hardDisk: UI_I_SendDataNewHardDisk
297
- ): void => {
298
- const removeIndex = hardDisksIndex.value.indexOf(index)
299
-
300
- if (!hardDisk.create && !hardDisk.attach) {
301
- hardDisksType.value = hardDisksType.value.map((item, key) => {
302
- if (key === removeIndex) return 'removed'
303
- return item
304
- })
305
- sendData()
306
- return
307
- }
308
-
309
- hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
310
- hardDisksType.value = hardDisksType.value.filter(
311
- (_item, key) => key !== removeIndex
312
- )
313
-
314
- hardDisksLocal.value = hardDisksLocal.value.filter(
315
- (_hardDisk, key: number) => {
316
- return removeIndex !== key
317
- }
318
- )
319
-
320
- delete newHardDiskInvalidKeys.value[index]
321
- delete sendDataNewHardDisk.value[index]
322
- sendData()
323
- }
324
- const onRollBackHardDisk = (index: number): void => {
325
- const removeIndex = hardDisksIndex.value.indexOf(index)
326
- hardDisksType.value = hardDisksType.value.map((item, key) => {
327
- if (key === removeIndex) return 'edit'
328
- return item
329
- })
330
- }
331
-
332
- const defaultNetwork = {
333
- network: '',
334
- net_bridge: '',
335
- mac: '',
336
- target: '',
337
- model: '',
338
- boot_order: -1,
339
- }
340
- const networksLocal = ref<UI_I_SendDataNewNetwork[]>([
341
- useDeepCopy(defaultNetwork),
342
- ])
343
- const networksType = ref<UI_T_NetworkType[]>(['new'])
344
- const networksIndex = ref<number[]>([0])
345
- watch(
346
- () => props.networks,
347
- (newValue) => {
348
- if ((!props.isEdit && !props.isClone) || !newValue) return
349
-
350
- // networksLocal.value = newValue
351
- // networksType.value = Array(newValue.length).fill('edit')
352
- const count = newValue?.length || 0
353
- networksIndex.value = [...Array(count).keys()]
354
- networksLocal.value = newValue
355
- if (props.isEdit) {
356
- networksType.value = Array(count).fill('edit')
357
- } else if (props.isClone) {
358
- networksType.value = Array(count).fill('new')
359
- }
360
- },
361
- { immediate: true }
362
- )
363
- const addNetwork = (): void => {
364
- const index = (networksIndex.value.at(-1) ?? -1) + 1
365
- networksIndex.value.push(index)
366
- networksType.value.push('new')
367
-
368
- networksLocal.value.push({
369
- ...useDeepCopy(defaultNetwork),
370
- boot_order: 0, // Убираем галочку
371
- })
372
- }
373
- const onRemoveNetwork = (index: number): void => {
374
- const removeIndex = networksIndex.value.indexOf(index)
375
- networksIndex.value = networksIndex.value.filter((item) => item !== index)
376
- networksType.value = networksType.value.filter(
377
- (_item, key) => key !== removeIndex
378
- )
379
- networksLocal.value = networksLocal.value.filter(
380
- (_network, key: number) => removeIndex !== key
381
- )
382
-
383
- delete newNetworkInvalidKeys.value[index]
384
- delete sendDataNewNetwork.value[index]
385
- sendData()
386
- }
387
-
388
- const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
389
- create: false,
390
- attach: false,
391
- source: '',
392
- bus: '',
393
- device_type: 'cdrom',
394
- boot_order: -1,
395
- }
396
- const cdDvdDrivesLocal = ref<UI_I_SendDataNewCdDvdDrive[]>([
397
- useDeepCopy(defaultCdDvdDriver),
398
- ])
399
- const cdDvdDrivesIndex = ref<number[]>([0])
400
- const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
401
- watch(
402
- () => props.cdDvdDrives,
403
- (newValue) => {
404
- if ((!props.isEdit && !props.isClone) || !newValue) return
405
-
406
- // cdDvdDrivesLocal.value = newValue
407
- // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
408
- const count = newValue?.length || 0
409
- cdDvdDrivesIndex.value = [...Array(count).keys()]
410
- cdDvdDrivesLocal.value = newValue
411
- if (props.isEdit) {
412
- cdDvdDrivesType.value = Array(count).fill('edit')
413
- } else if (props.isClone) {
414
- cdDvdDrivesType.value = Array(count).fill('new')
415
- }
416
- },
417
- { immediate: true }
418
- )
419
- const addCdDvdDrive = (): void => {
420
- const value = (cdDvdDrivesIndex.value.at(-1) ?? -1) + 1
421
- cdDvdDrivesIndex.value.push(value)
422
- cdDvdDrivesType.value.push('new')
423
- cdDvdDrivesLocal.value.push({
424
- ...useDeepCopy(defaultCdDvdDriver),
425
- attach: true,
426
- boot_order: 0, // Убираем галочку
427
- })
428
- }
429
- const onRemoveCdDvdDrive = (
430
- index: number,
431
- cdDvdDrive: UI_I_SendDataNewCdDvdDrive
432
- ): void => {
433
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
434
-
435
- // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
436
- if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
437
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
438
- if (key === removeIndex) return 'removed'
439
- return item
440
- })
441
- sendData()
442
- return
443
- }
444
-
445
- cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
446
- (cdDvdDrive) => cdDvdDrive !== index
447
- )
448
- cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
449
- (_item, key) => key !== index
450
- )
451
- cdDvdDrivesLocal.value = cdDvdDrivesLocal.value.filter(
452
- (_cdDvdDrive, key: number) => removeIndex !== key
453
- )
454
-
455
- delete sendDataNewCdDvdDrive.value[index]
456
- sendData()
457
- }
458
- const onRollBackCdDvdDrive = (index: number): void => {
459
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
460
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
461
- if (key === removeIndex) return 'edit'
462
- return item
463
- })
464
- }
465
-
466
- const defaultPciDevice: UI_I_SendDataNewPciDevice = {
467
- address: '',
468
- vendor_name: '',
469
- class_name: '',
470
- device_name: '',
471
- }
472
- const pciDevicesIndex = ref<number[]>([0])
473
- const pciDevicesType = ref<('new' | 'edit' | 'removed')[]>(['new'])
474
- const pciDevicesLocal = ref<UI_I_SendDataNewPciDevice[]>([])
475
- watch(
476
- () => props.pciDevices,
477
- (newValue) => {
478
- if ((!props.isEdit && !props.isClone) || !newValue) return
479
-
480
- const count = newValue?.length || 0
481
- pciDevicesIndex.value = [...Array(count).keys()]
482
- pciDevicesLocal.value = newValue || []
483
- if (props.isEdit) {
484
- pciDevicesType.value = Array(count).fill('edit')
485
- } else if (props.isClone) {
486
- pciDevicesType.value = Array(count).fill('new')
487
- }
488
- },
489
- { immediate: true }
490
- )
491
-
492
- const addPciDevice = (): void => {
493
- const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
494
- pciDevicesIndex.value.push(newIndex)
495
- pciDevicesType.value.push('new')
496
-
497
- pciDevicesLocal.value.push(useDeepCopy(defaultPciDevice))
498
- }
499
- const onRemovePciDevice = (index: number): void => {
500
- const removeIndex = pciDevicesIndex.value.indexOf(index)
501
- pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
502
- pciDevicesType.value = pciDevicesType.value.filter(
503
- (_item, key) => key !== removeIndex
504
- )
505
-
506
- pciDevicesLocal.value = pciDevicesLocal.value.filter(
507
- (_pciDevice, key: number) => {
508
- return removeIndex !== key
509
- }
510
- )
511
-
512
- delete newPciDeviceInvalidKeys.value[index]
513
- delete sendDataNewPciDevices.value[index]
514
- sendData()
515
- }
516
-
517
- const isShowFileModal = ref<boolean>(false)
518
- const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
519
- switch (item.value) {
520
- case 1:
521
- addHardDisk()
522
- break
523
- case 2:
524
- isShowFileModal.value = true
525
- break
526
- case 5:
527
- addCdDvdDrive()
528
- break
529
- case 10:
530
- addPciDevice()
531
- break
532
- case 14:
533
- addNetwork()
534
- break
535
- }
536
- }
537
-
538
- const cpuInvalid = ref<boolean>(false)
539
- const sendDataCpu = ref<UI_I_SendDataCpu | null>(null)
540
- const onSendDataCpuMethod = (data: UI_I_SendDataCpu): void => {
541
- sendDataCpu.value = data
542
- sendData()
543
- }
544
- const sendDataMemory = ref<UI_I_SendDataMemory | null>(null)
545
- const onSendDataMemoryMethod = (data: UI_I_SendDataMemory): void => {
546
- sendDataMemory.value = data
547
- sendData()
548
- }
549
- const sendDataNewHardDisk = ref<UI_I_SendDataNewHardDisk[]>([])
550
- const onSendDataNewHardDiskMethod = (
551
- data: UI_I_SendDataNewHardDisk,
552
- index: number
553
- ): void => {
554
- sendDataNewHardDisk.value[index] = data
555
- sendData()
556
- }
557
- const sendDataNewNetwork = ref<UI_I_SendDataNewNetwork[]>([])
558
- const sendDataNewNetworkMethod = (
559
- data: UI_I_SendDataNewNetwork,
560
- index: number
561
- ): void => {
562
- sendDataNewNetwork.value[index] = data
563
- sendData()
564
- }
565
- const sendDataNewCdDvdDrive = ref<UI_I_SendDataNewCdDvdDrive[]>([])
566
- const sendDataNewCdDvdDriveMethod = (
567
- data: UI_I_SendDataNewCdDvdDrive,
568
- index: number
569
- ): void => {
570
- sendDataNewCdDvdDrive.value[index] = data
571
- sendData()
572
- }
573
- const sendDataNewUsbController = ref<string | null>(null)
574
- const onSendDataNewUsbControllerMethod = (data: string): void => {
575
- sendDataNewUsbController.value = data
576
- sendData()
577
- }
578
- const sendDataNewPciDevices = ref<UI_I_SendDataNewPciDevice[]>([])
579
- const onSendDataPciDevicesMethod = (
580
- data: UI_I_SendDataNewPciDevice,
581
- index: number
582
- ): void => {
583
- sendDataNewPciDevices.value[index] = data
584
- sendData()
585
- }
586
- const sendDataVideoCard = ref<UI_I_SendDataVideoCard | null>(null)
587
- const onSendDataVideoCardMethod = (data: UI_I_SendDataVideoCard): void => {
588
- sendDataVideoCard.value = data
589
- sendData()
590
- }
591
-
592
- const sendData = (): void => {
593
- const cpu = sendDataCpu.value
594
- const memory = sendDataMemory.value
595
- const hardDisks = sendDataNewHardDisk.value.flat(2)
596
- const networks = sendDataNewNetwork.value.flat(2)
597
- const cdDvdDrives = sendDataNewCdDvdDrive.value.flat(2)
598
- const pciDevices = sendDataNewPciDevices.value.flat()
599
- const usbController = sendDataNewUsbController.value
600
- const videoCard = sendDataVideoCard.value
601
-
602
- const sendData: UI_I_SendDataVirtualHardware = {
603
- cpu,
604
- memory,
605
- usbController,
606
- pciDevices,
607
- networks,
608
- hardDisks,
609
- cdDvdDrives,
610
- videoCard,
611
- }
612
- emits('send-data', sendData)
613
- }
614
-
615
- const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
616
- newHardDiskInvalidKeys.value[index] = invalid
617
- }
618
-
619
- const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
620
- newNetworkInvalidKeys.value[key] = invalid
621
- }
622
-
623
- const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
624
- newPciDeviceInvalidKeys.value[key] = invalid
625
- }
626
-
627
- const memoryInvalid = ref<boolean>(false)
628
- const videoCardInvalid = ref<boolean>(false)
629
- const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
630
- const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
631
- const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
632
-
633
- watch(
634
- [
635
- cpuInvalid,
636
- memoryInvalid,
637
- newHardDiskInvalidKeys,
638
- newNetworkInvalidKeys,
639
- newPciDeviceInvalidKeys,
640
- videoCardInvalid,
641
- ],
642
- () => {
643
- const cpu = cpuInvalid.value ? localization.value.common.cpu : ''
644
- const memory = memoryInvalid.value ? localization.value.common.memory : ''
645
- const videoCard = videoCardInvalid.value
646
- ? localization.value.common.videoCard
647
- : ''
648
- let newHardDisk = ''
649
- Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
650
- if (!newHardDiskInvalidKeys.value[+key]) {
651
- return
652
- }
653
-
654
- newHardDisk +=
655
- (newHardDisk ? ', ' : '') +
656
- localization.value.common.newHardDisk +
657
- ' ' +
658
- (+key + 1)
659
- })
660
- let newNetwork = ''
661
- Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
662
- if (!newNetworkInvalidKeys.value[+key]) {
663
- return
664
- }
665
-
666
- newNetwork +=
667
- (newNetwork ? ', ' : '') +
668
- localization.value.common.newNetwork +
669
- ' ' +
670
- (+key + 1)
671
- })
672
- // let pciDevice = ''
673
- // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
674
- // if (!newPciDeviceInvalidKeys.value[+key]) {
675
- // return
676
- // }
677
- //
678
- // pciDevice +=
679
- // (pciDevice ? ', ' : '') +
680
- // localization.value.common.pciDevice +
681
- // ' ' +
682
- // (+key + 1)
683
- // })
684
-
685
- emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
686
- },
687
- { deep: true }
688
- )
689
-
690
- emits('get-pci-devices')
691
- </script>
692
-
693
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <common-vm-actions-common-customize-hardware-virtual-hardware-new
3
+ v-if="isNewView"
4
+ v-model:cpu-invalid="cpuInvalid"
5
+ v-model:memory-invalid="memoryInvalid"
6
+ v-model:video-card-invalid="videoCardInvalid"
7
+ :nodes="props.nodes"
8
+ :files="props.files"
9
+ :is-edit="props.isEdit"
10
+ :storage="props.storage"
11
+ :project="props.project"
12
+ :max-cpus="props.maxCpus"
13
+ :max-memory="props.maxMemory"
14
+ :cpu-models="props.cpuModels"
15
+ :datastore="props.datastore"
16
+ :networks-type="networksType"
17
+ :networks-table="props.networksTable"
18
+ :dropdown-items="dropdownItems"
19
+ :hard-disks-type="hardDisksType"
20
+ :networks-index="networksIndex"
21
+ :hard-disks-index="hardDisksIndex"
22
+ :pci-devices-type="pciDevicesType"
23
+ :is-show-file-modal="isShowFileModal"
24
+ :pci-devices-index="pciDevicesIndex"
25
+ :cd-dvd-drives-type="cdDvdDrivesType"
26
+ :cd-dvd-drives-index="cdDvdDrivesIndex"
27
+ :error-validation-fields="errorValidationFields"
28
+ :get-datastore-table-func="getDatastoreTableFunc"
29
+ :cpu="cpu"
30
+ :state="state"
31
+ :memory="memory"
32
+ :networks="networksLocal"
33
+ :hard-disks="hardDisksLocal"
34
+ :video-card="videoCard"
35
+ :pci-devices="pciDevicesLocal"
36
+ :cd-dvd-drives="cdDvdDrivesLocal"
37
+ :usb-controller="usbController"
38
+ :guest-machine-type="guestMachineType"
39
+ :passthrough-devices="passthroughDevices"
40
+ :mediated-devices="mediatedDevices"
41
+ :vm-cpu-help-text-second="vmCpuHelpTextSecond"
42
+ @add-device="onAddDevice"
43
+ @get-storage="emits('get-storage', $event)"
44
+ @remove-network="onRemoveNetwork"
45
+ @hide-file-modal="isShowFileModal = false"
46
+ @remove-hard-disk="onRemoveHardDisk(...$event)"
47
+ @remove-pci-device="onRemovePciDevice"
48
+ @get-networks-table="emits('get-networks-table', $event)"
49
+ @add-exist-hard-disk="onAddExistHardDisk"
50
+ @roll-back-hard-disk="onRollBackHardDisk"
51
+ @set-invalid-network="onSetInvalidNetwork(...$event)"
52
+ @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
53
+ @show-datastore-child="emits('show-datastore-child', $event)"
54
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
55
+ @send-data-cpu-method="onSendDataCpuMethod"
56
+ @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
57
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
58
+ @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
59
+ @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
60
+ @get-active-device-child="emits('get-active-device-child', $event)"
61
+ @send-data-memory-method="onSendDataMemoryMethod"
62
+ @send-data-video-card-method="onSendDataVideoCardMethod"
63
+ @send-data-new-network-method="sendDataNewNetworkMethod(...$event)"
64
+ @send-data-pci-devices-method="onSendDataPciDevicesMethod(...$event)"
65
+ @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
66
+ @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
67
+ @send-data-new-usb-controller-method="onSendDataNewUsbControllerMethod"
68
+ />
69
+ <common-vm-actions-common-customize-hardware-virtual-hardware-old
70
+ v-else
71
+ v-model:cpu-invalid="cpuInvalid"
72
+ v-model:memory-invalid="memoryInvalid"
73
+ v-model:video-card-invalid="videoCardInvalid"
74
+ :nodes="props.nodes"
75
+ :files="props.files"
76
+ :is-edit="props.isEdit"
77
+ :storage="props.storage"
78
+ :project="props.project"
79
+ :max-cpus="props.maxCpus"
80
+ :max-memory="props.maxMemory"
81
+ :cpu-models="props.cpuModels"
82
+ :datastore="props.datastore"
83
+ :networks-type="networksType"
84
+ :networks-table="props.networksTable"
85
+ :dropdown-items="dropdownItems"
86
+ :hard-disks-type="hardDisksType"
87
+ :networks-index="networksIndex"
88
+ :hard-disks-index="hardDisksIndex"
89
+ :pci-devices-type="pciDevicesType"
90
+ :is-show-file-modal="isShowFileModal"
91
+ :pci-devices-index="pciDevicesIndex"
92
+ :cd-dvd-drives-type="cdDvdDrivesType"
93
+ :cd-dvd-drives-index="cdDvdDrivesIndex"
94
+ :error-validation-fields="errorValidationFields"
95
+ :get-datastore-table-func="getDatastoreTableFunc"
96
+ :cpu="cpu"
97
+ :state="state"
98
+ :memory="memory"
99
+ :networks="networksLocal"
100
+ :hard-disks="hardDisksLocal"
101
+ :video-card="videoCard"
102
+ :pci-devices="pciDevicesLocal"
103
+ :cd-dvd-drives="cdDvdDrivesLocal"
104
+ :usb-controller="usbController"
105
+ :guest-machine-type="guestMachineType"
106
+ :passthrough-devices="passthroughDevices"
107
+ :mediated-devices="mediatedDevices"
108
+ :vm-cpu-help-text-second="vmCpuHelpTextSecond"
109
+ @add-device="onAddDevice"
110
+ @get-storage="emits('get-storage', $event)"
111
+ @remove-network="onRemoveNetwork"
112
+ @hide-file-modal="isShowFileModal = false"
113
+ @remove-hard-disk="onRemoveHardDisk(...$event)"
114
+ @remove-pci-device="onRemovePciDevice"
115
+ @get-networks-table="emits('get-networks-table', $event)"
116
+ @add-exist-hard-disk="onAddExistHardDisk"
117
+ @roll-back-hard-disk="onRollBackHardDisk"
118
+ @set-invalid-network="onSetInvalidNetwork(...$event)"
119
+ @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
120
+ @show-datastore-child="emits('show-datastore-child', $event)"
121
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
122
+ @send-data-cpu-method="onSendDataCpuMethod"
123
+ @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
124
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
125
+ @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
126
+ @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
127
+ @get-active-device-child="emits('get-active-device-child', $event)"
128
+ @send-data-memory-method="onSendDataMemoryMethod"
129
+ @send-data-video-card-method="onSendDataVideoCardMethod"
130
+ @send-data-new-network-method="sendDataNewNetworkMethod(...$event)"
131
+ @send-data-pci-devices-method="onSendDataPciDevicesMethod(...$event)"
132
+ @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
133
+ @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
134
+ @send-data-new-usb-controller-method="onSendDataNewUsbControllerMethod"
135
+ />
136
+ </template>
137
+
138
+ <script setup lang="ts">
139
+ import type { UI_T_Project } from '~/lib/models/types'
140
+ import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
141
+ import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
142
+ import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
143
+ import type { UI_I_FolderOrFileTreePayload } from '~/lib/models/store/storage/interfaces'
144
+ import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
145
+ import type {
146
+ UI_I_SendDataCpu,
147
+ UI_I_SendDataMemory,
148
+ UI_I_SendDataNewHardDisk,
149
+ UI_I_SendDataNewNetwork,
150
+ UI_I_SendDataVideoCard,
151
+ UI_I_InvalidKeys,
152
+ UI_I_SendDataVirtualHardware,
153
+ UI_I_SendDataNewCdDvdDrive,
154
+ // UI_I_HardDisk,
155
+ UI_I_SendDataNewPciDevice,
156
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
157
+ import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
158
+ import type {
159
+ UI_T_HardDiskType,
160
+ UI_T_NetworkType,
161
+ UI_T_CdDvdType,
162
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/types'
163
+ import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
164
+ import type {
165
+ UI_I_DropdownTreeItem,
166
+ UI_I_DropdownTreeItemChild,
167
+ } from '~/components/atoms/dropdown/tree/lib/models/interfaces'
168
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
169
+ import type {
170
+ API_UI_I_VmEditCpu,
171
+ API_UI_I_VmEditMemory,
172
+ UI_I_MediatedDevice,
173
+ UI_I_PciDevice,
174
+ } from '~/lib/models/store/vm/interfaces'
175
+ import { dropdownItemsFunc } from './lib/config/dropdownItems'
176
+
177
+ const props = defineProps<{
178
+ storage: UI_I_DatastoreTableItem | null
179
+ cpuModels: UI_I_OptionItem[]
180
+ maxCpus: number
181
+ maxMemory: number
182
+ isEdit: boolean
183
+ isClone: boolean
184
+ errorValidationFields: UI_I_ErrorValidationField<string>[]
185
+ nodes: UI_I_FileTreeNode[]
186
+ files: UI_I_FileTreeNode[]
187
+ networksTable: UI_I_NetworkTableItem[]
188
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
189
+ datastore: UI_I_DatastoreTableItem[]
190
+ state?: string | number
191
+ cpu?: API_UI_I_VmEditCpu
192
+ memory?: API_UI_I_VmEditMemory
193
+ vmCpuHelpTextSecond?: string
194
+ hardDisks?: UI_I_SendDataNewHardDisk[] | null
195
+ cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
196
+ networks?: UI_I_SendDataNewNetwork[] | null
197
+ videoCard?: UI_I_SendDataVideoCard
198
+ usbController?: string
199
+ pciDevices?: UI_I_SendDataNewPciDevice[]
200
+ passthroughDevices?: UI_I_PciDevice[]
201
+ mediatedDevices?: UI_I_MediatedDevice[]
202
+ project: UI_T_Project
203
+ guestMachineType?: UI_I_OptionItem | null
204
+ }>()
205
+ const emits = defineEmits<{
206
+ (event: 'send-data', value: UI_I_SendDataVirtualHardware): void
207
+ (event: 'invalid', value: string[]): void
208
+ (event: 'get-storage', value: UI_I_TablePayload): void
209
+ (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
210
+ (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
211
+ (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
212
+ (event: 'remove-error-by-title', value: string): void
213
+ (event: 'get-networks-table', value: UI_I_TablePayload): void
214
+ (event: 'get-pci-devices'): void
215
+ }>()
216
+
217
+ const { $store, $binary }: any = useNuxtApp()
218
+ const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
219
+
220
+ const localization = computed<UI_I_Localization>(() => useLocal())
221
+
222
+ const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
223
+ dropdownItemsFunc(
224
+ localization.value,
225
+ props.state,
226
+ props.passthroughDevices,
227
+ props.mediatedDevices
228
+ )
229
+ )
230
+
231
+ const hardDisksIndex = ref<number[]>([0])
232
+ const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
233
+ const hardDisksLocal = ref<UI_I_SendDataNewHardDisk[]>([
234
+ {
235
+ create: true,
236
+ size: 90,
237
+ source: '',
238
+ boot_order: -1,
239
+ },
240
+ ])
241
+ watch(
242
+ () => props.hardDisks,
243
+ (newValue) => {
244
+ if ((!props.isEdit && !props.isClone) || !newValue) return
245
+
246
+ const count = newValue?.length || 0
247
+ hardDisksIndex.value = [...Array(count).keys()]
248
+ hardDisksLocal.value = newValue
249
+ if (props.isEdit) {
250
+ hardDisksType.value = Array(count).fill('edit')
251
+ } else if (props.isClone) {
252
+ hardDisksType.value = Array(count).fill('clone')
253
+ hardDisksLocal.value = newValue.map((hardDisk) => {
254
+ hardDisk.create = true
255
+ return hardDisk
256
+ })
257
+ }
258
+ },
259
+ { immediate: true }
260
+ )
261
+
262
+ const addHardDisk = (
263
+ create = true,
264
+ size = 90,
265
+ source = '',
266
+ type: UI_T_HardDiskType = 'new',
267
+ provisioned_type?: number // При добавлении существующей
268
+ ): void => {
269
+ const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
270
+ hardDisksIndex.value.push(newIndex)
271
+ hardDisksType.value.push(type)
272
+
273
+ let provisionType = 'thick'
274
+ if (provisioned_type === 1) provisionType = 'thin'
275
+
276
+ hardDisksLocal.value.push({
277
+ create,
278
+ size,
279
+ source,
280
+ attach: true,
281
+ boot_order: 0, // Убираем галочку
282
+ provision_type: provisionType,
283
+ })
284
+ sendData()
285
+ }
286
+ const onAddExistHardDisk = (file: UI_I_FileTreeNode): void => {
287
+ addHardDisk(
288
+ false,
289
+ $binary.bToGb(file.size),
290
+ file.path,
291
+ 'exist',
292
+ file.provisioned_type
293
+ )
294
+ }
295
+ const onRemoveHardDisk = (
296
+ index: number,
297
+ hardDisk: UI_I_SendDataNewHardDisk
298
+ ): void => {
299
+ const removeIndex = hardDisksIndex.value.indexOf(index)
300
+
301
+ if (!hardDisk.create && !hardDisk.attach) {
302
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
303
+ if (key === removeIndex) return 'removed'
304
+ return item
305
+ })
306
+ sendData()
307
+ return
308
+ }
309
+
310
+ hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
311
+ hardDisksType.value = hardDisksType.value.filter(
312
+ (_item, key) => key !== removeIndex
313
+ )
314
+
315
+ hardDisksLocal.value = hardDisksLocal.value.filter(
316
+ (_hardDisk, key: number) => {
317
+ return removeIndex !== key
318
+ }
319
+ )
320
+
321
+ delete newHardDiskInvalidKeys.value[index]
322
+ delete sendDataNewHardDisk.value[index]
323
+ sendData()
324
+ }
325
+ const onRollBackHardDisk = (index: number): void => {
326
+ const removeIndex = hardDisksIndex.value.indexOf(index)
327
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
328
+ if (key === removeIndex) return 'edit'
329
+ return item
330
+ })
331
+ }
332
+
333
+ const defaultNetwork = {
334
+ network: '',
335
+ net_bridge: '',
336
+ mac: '',
337
+ target: '',
338
+ model: '',
339
+ boot_order: -1,
340
+ }
341
+ const networksLocal = ref<UI_I_SendDataNewNetwork[]>([
342
+ useDeepCopy(defaultNetwork),
343
+ ])
344
+ const networksType = ref<UI_T_NetworkType[]>(['new'])
345
+ const networksIndex = ref<number[]>([0])
346
+ watch(
347
+ () => props.networks,
348
+ (newValue) => {
349
+ if ((!props.isEdit && !props.isClone) || !newValue) return
350
+
351
+ // networksLocal.value = newValue
352
+ // networksType.value = Array(newValue.length).fill('edit')
353
+ const count = newValue?.length || 0
354
+ networksIndex.value = [...Array(count).keys()]
355
+ networksLocal.value = newValue
356
+ if (props.isEdit) {
357
+ networksType.value = Array(count).fill('edit')
358
+ } else if (props.isClone) {
359
+ networksType.value = Array(count).fill('clone')
360
+ }
361
+ },
362
+ { immediate: true }
363
+ )
364
+ const addNetwork = (): void => {
365
+ const index = (networksIndex.value.at(-1) ?? -1) + 1
366
+ networksIndex.value.push(index)
367
+ networksType.value.push('new')
368
+
369
+ networksLocal.value.push({
370
+ ...useDeepCopy(defaultNetwork),
371
+ boot_order: 0, // Убираем галочку
372
+ })
373
+ }
374
+ const onRemoveNetwork = (index: number): void => {
375
+ const removeIndex = networksIndex.value.indexOf(index)
376
+ networksIndex.value = networksIndex.value.filter((item) => item !== index)
377
+ networksType.value = networksType.value.filter(
378
+ (_item, key) => key !== removeIndex
379
+ )
380
+ networksLocal.value = networksLocal.value.filter(
381
+ (_network, key: number) => removeIndex !== key
382
+ )
383
+
384
+ delete newNetworkInvalidKeys.value[index]
385
+ delete sendDataNewNetwork.value[index]
386
+ sendData()
387
+ }
388
+
389
+ const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
390
+ create: false,
391
+ attach: false,
392
+ source: '',
393
+ bus: '',
394
+ device_type: 'cdrom',
395
+ boot_order: -1,
396
+ }
397
+ const cdDvdDrivesLocal = ref<UI_I_SendDataNewCdDvdDrive[]>([
398
+ useDeepCopy(defaultCdDvdDriver),
399
+ ])
400
+ const cdDvdDrivesIndex = ref<number[]>([0])
401
+ const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
402
+ watch(
403
+ () => props.cdDvdDrives,
404
+ (newValue) => {
405
+ if ((!props.isEdit && !props.isClone) || !newValue) return
406
+
407
+ // cdDvdDrivesLocal.value = newValue
408
+ // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
409
+ const count = newValue?.length || 0
410
+ cdDvdDrivesIndex.value = [...Array(count).keys()]
411
+ cdDvdDrivesLocal.value = newValue
412
+ if (props.isEdit) {
413
+ cdDvdDrivesType.value = Array(count).fill('edit')
414
+ } else if (props.isClone) {
415
+ cdDvdDrivesType.value = Array(count).fill('new')
416
+ }
417
+ },
418
+ { immediate: true }
419
+ )
420
+ const addCdDvdDrive = (): void => {
421
+ const value = (cdDvdDrivesIndex.value.at(-1) ?? -1) + 1
422
+ cdDvdDrivesIndex.value.push(value)
423
+ cdDvdDrivesType.value.push('new')
424
+ cdDvdDrivesLocal.value.push({
425
+ ...useDeepCopy(defaultCdDvdDriver),
426
+ attach: true,
427
+ boot_order: 0, // Убираем галочку
428
+ })
429
+ }
430
+ const onRemoveCdDvdDrive = (
431
+ index: number,
432
+ cdDvdDrive: UI_I_SendDataNewCdDvdDrive
433
+ ): void => {
434
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
435
+
436
+ // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
437
+ if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
438
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
439
+ if (key === removeIndex) return 'removed'
440
+ return item
441
+ })
442
+ sendData()
443
+ return
444
+ }
445
+
446
+ cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
447
+ (cdDvdDrive) => cdDvdDrive !== index
448
+ )
449
+ cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
450
+ (_item, key) => key !== index
451
+ )
452
+ cdDvdDrivesLocal.value = cdDvdDrivesLocal.value.filter(
453
+ (_cdDvdDrive, key: number) => removeIndex !== key
454
+ )
455
+
456
+ delete sendDataNewCdDvdDrive.value[index]
457
+ sendData()
458
+ }
459
+ const onRollBackCdDvdDrive = (index: number): void => {
460
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
461
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
462
+ if (key === removeIndex) return 'edit'
463
+ return item
464
+ })
465
+ }
466
+
467
+ const defaultPciDevice: UI_I_SendDataNewPciDevice = {
468
+ address: '',
469
+ vendor_name: '',
470
+ class_name: '',
471
+ device_name: '',
472
+ }
473
+ const pciDevicesIndex = ref<number[]>([0])
474
+ const pciDevicesType = ref<('new' | 'edit' | 'removed')[]>(['new'])
475
+ const pciDevicesLocal = ref<UI_I_SendDataNewPciDevice[]>([])
476
+ watch(
477
+ () => props.pciDevices,
478
+ (newValue) => {
479
+ if ((!props.isEdit && !props.isClone) || !newValue) return
480
+
481
+ const count = newValue?.length || 0
482
+ pciDevicesIndex.value = [...Array(count).keys()]
483
+ pciDevicesLocal.value = newValue || []
484
+ if (props.isEdit) {
485
+ pciDevicesType.value = Array(count).fill('edit')
486
+ } else if (props.isClone) {
487
+ pciDevicesType.value = Array(count).fill('new')
488
+ }
489
+ },
490
+ { immediate: true }
491
+ )
492
+
493
+ const addPciDevice = (): void => {
494
+ const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
495
+ pciDevicesIndex.value.push(newIndex)
496
+ pciDevicesType.value.push('new')
497
+
498
+ pciDevicesLocal.value.push(useDeepCopy(defaultPciDevice))
499
+ }
500
+ const onRemovePciDevice = (index: number): void => {
501
+ const removeIndex = pciDevicesIndex.value.indexOf(index)
502
+ pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
503
+ pciDevicesType.value = pciDevicesType.value.filter(
504
+ (_item, key) => key !== removeIndex
505
+ )
506
+
507
+ pciDevicesLocal.value = pciDevicesLocal.value.filter(
508
+ (_pciDevice, key: number) => {
509
+ return removeIndex !== key
510
+ }
511
+ )
512
+
513
+ delete newPciDeviceInvalidKeys.value[index]
514
+ delete sendDataNewPciDevices.value[index]
515
+ sendData()
516
+ }
517
+
518
+ const isShowFileModal = ref<boolean>(false)
519
+ const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
520
+ switch (item.value) {
521
+ case 1:
522
+ addHardDisk()
523
+ break
524
+ case 2:
525
+ isShowFileModal.value = true
526
+ break
527
+ case 5:
528
+ addCdDvdDrive()
529
+ break
530
+ case 10:
531
+ addPciDevice()
532
+ break
533
+ case 14:
534
+ addNetwork()
535
+ break
536
+ }
537
+ }
538
+
539
+ const cpuInvalid = ref<boolean>(false)
540
+ const sendDataCpu = ref<UI_I_SendDataCpu | null>(null)
541
+ const onSendDataCpuMethod = (data: UI_I_SendDataCpu): void => {
542
+ sendDataCpu.value = data
543
+ sendData()
544
+ }
545
+ const sendDataMemory = ref<UI_I_SendDataMemory | null>(null)
546
+ const onSendDataMemoryMethod = (data: UI_I_SendDataMemory): void => {
547
+ sendDataMemory.value = data
548
+ sendData()
549
+ }
550
+ const sendDataNewHardDisk = ref<UI_I_SendDataNewHardDisk[]>([])
551
+ const onSendDataNewHardDiskMethod = (
552
+ data: UI_I_SendDataNewHardDisk,
553
+ index: number
554
+ ): void => {
555
+ sendDataNewHardDisk.value[index] = data
556
+ sendData()
557
+ }
558
+ const sendDataNewNetwork = ref<UI_I_SendDataNewNetwork[]>([])
559
+ const sendDataNewNetworkMethod = (
560
+ data: UI_I_SendDataNewNetwork,
561
+ index: number
562
+ ): void => {
563
+ sendDataNewNetwork.value[index] = data
564
+ sendData()
565
+ }
566
+ const sendDataNewCdDvdDrive = ref<UI_I_SendDataNewCdDvdDrive[]>([])
567
+ const sendDataNewCdDvdDriveMethod = (
568
+ data: UI_I_SendDataNewCdDvdDrive,
569
+ index: number
570
+ ): void => {
571
+ sendDataNewCdDvdDrive.value[index] = data
572
+ sendData()
573
+ }
574
+ const sendDataNewUsbController = ref<string | null>(null)
575
+ const onSendDataNewUsbControllerMethod = (data: string): void => {
576
+ sendDataNewUsbController.value = data
577
+ sendData()
578
+ }
579
+ const sendDataNewPciDevices = ref<UI_I_SendDataNewPciDevice[]>([])
580
+ const onSendDataPciDevicesMethod = (
581
+ data: UI_I_SendDataNewPciDevice,
582
+ index: number
583
+ ): void => {
584
+ sendDataNewPciDevices.value[index] = data
585
+ sendData()
586
+ }
587
+ const sendDataVideoCard = ref<UI_I_SendDataVideoCard | null>(null)
588
+ const onSendDataVideoCardMethod = (data: UI_I_SendDataVideoCard): void => {
589
+ sendDataVideoCard.value = data
590
+ sendData()
591
+ }
592
+
593
+ const sendData = (): void => {
594
+ const cpu = sendDataCpu.value
595
+ const memory = sendDataMemory.value
596
+ const hardDisks = sendDataNewHardDisk.value.flat(2)
597
+ const networks = sendDataNewNetwork.value.flat(2)
598
+ const cdDvdDrives = sendDataNewCdDvdDrive.value.flat(2)
599
+ const pciDevices = sendDataNewPciDevices.value.flat()
600
+ const usbController = sendDataNewUsbController.value
601
+ const videoCard = sendDataVideoCard.value
602
+
603
+ const sendData: UI_I_SendDataVirtualHardware = {
604
+ cpu,
605
+ memory,
606
+ usbController,
607
+ pciDevices,
608
+ networks,
609
+ hardDisks,
610
+ cdDvdDrives,
611
+ videoCard,
612
+ }
613
+ emits('send-data', sendData)
614
+ }
615
+
616
+ const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
617
+ newHardDiskInvalidKeys.value[index] = invalid
618
+ }
619
+
620
+ const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
621
+ newNetworkInvalidKeys.value[key] = invalid
622
+ }
623
+
624
+ const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
625
+ newPciDeviceInvalidKeys.value[key] = invalid
626
+ }
627
+
628
+ const memoryInvalid = ref<boolean>(false)
629
+ const videoCardInvalid = ref<boolean>(false)
630
+ const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
631
+ const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
632
+ const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
633
+
634
+ watch(
635
+ [
636
+ cpuInvalid,
637
+ memoryInvalid,
638
+ newHardDiskInvalidKeys,
639
+ newNetworkInvalidKeys,
640
+ newPciDeviceInvalidKeys,
641
+ videoCardInvalid,
642
+ ],
643
+ () => {
644
+ const cpu = cpuInvalid.value ? localization.value.common.cpu : ''
645
+ const memory = memoryInvalid.value ? localization.value.common.memory : ''
646
+ const videoCard = videoCardInvalid.value
647
+ ? localization.value.common.videoCard
648
+ : ''
649
+ let newHardDisk = ''
650
+ Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
651
+ if (!newHardDiskInvalidKeys.value[+key]) {
652
+ return
653
+ }
654
+
655
+ newHardDisk +=
656
+ (newHardDisk ? ', ' : '') +
657
+ localization.value.common.newHardDisk +
658
+ ' ' +
659
+ (+key + 1)
660
+ })
661
+ let newNetwork = ''
662
+ Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
663
+ if (!newNetworkInvalidKeys.value[+key]) {
664
+ return
665
+ }
666
+
667
+ newNetwork +=
668
+ (newNetwork ? ', ' : '') +
669
+ localization.value.common.newNetwork +
670
+ ' ' +
671
+ (+key + 1)
672
+ })
673
+ // let pciDevice = ''
674
+ // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
675
+ // if (!newPciDeviceInvalidKeys.value[+key]) {
676
+ // return
677
+ // }
678
+ //
679
+ // pciDevice +=
680
+ // (pciDevice ? ', ' : '') +
681
+ // localization.value.common.pciDevice +
682
+ // ' ' +
683
+ // (+key + 1)
684
+ // })
685
+
686
+ emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
687
+ },
688
+ { deep: true }
689
+ )
690
+
691
+ emits('get-pci-devices')
692
+ </script>
693
+
694
+ <style scoped lang="scss"></style>