Update.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_247')}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" :message="$t('compute.need_reboot_prompt')" banner />
  6. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_247')" />
  7. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form
  9. :form="form.fc"
  10. v-bind="formItemLayout">
  11. <!-- <a-form-item :label="$t('common.text00076')" v-bind="formItemLayout">
  12. <a-radio-group v-decorator="decorators.disable_delete">
  13. <a-radio-button
  14. v-for="item of disableDeleteOptions"
  15. :key="item.key"
  16. :value="item.key">{{ item.label }}</a-radio-button>
  17. </a-radio-group>
  18. </a-form-item> -->
  19. <template v-if="isKvm">
  20. <!-- <a-form-item :label="$t('compute.text_1269')" v-bind="formItemLayout">
  21. <a-radio-group v-decorator="decorators.boot_order">
  22. <a-radio-button
  23. v-for="item of bootOrderOptions"
  24. :key="item.key"
  25. :value="item.key">{{ item.label }}</a-radio-button>
  26. </a-radio-group>
  27. </a-form-item> -->
  28. <a-form-item :label="$t('compute.text_1155')">
  29. <bios :decorator="decorators.bios" :isArm="isArm" />
  30. </a-form-item>
  31. <a-form-item :label="$t('compute.vdi_protocol')">
  32. <vdi :decorator="decorators.vdi" @change="handleVdiChange" />
  33. </a-form-item>
  34. <a-form-item :label="$t('compute.vga')">
  35. <vga :decorator="decorators.vga" :vdi="vdi" :form="form" />
  36. </a-form-item>
  37. <a-form-item :label="$t('compute.machine')">
  38. <machine :decorator="decorators.machine" :isArm="isArm" />
  39. </a-form-item>
  40. <a-form-item v-if="isKvm" :label="$t('compute.usb_kbd')">
  41. <a-switch v-decorator="decorators.disable_usb_kbd" />
  42. </a-form-item>
  43. <a-form-item :label="$t('compute.text_494')" :extra="$t('compute.daemon.tooltip')" v-if="canAdminUpdate">
  44. <a-switch v-model="is_daemon" />
  45. </a-form-item>
  46. </template>
  47. </a-form>
  48. </div>
  49. <div slot="footer">
  50. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  51. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  52. </div>
  53. </base-dialog>
  54. </template>
  55. <script>
  56. import DialogMixin from '@/mixins/dialog'
  57. import WindowsMixin from '@/mixins/windows'
  58. import { hasPermission } from '@/utils/auth'
  59. import Bios from '@Compute/sections/BIOS'
  60. import Vdi from '@Compute/sections/VDI'
  61. import Vga from '@Compute/sections/VGA'
  62. import Machine from '@Compute/sections/Machine'
  63. export default {
  64. name: 'VmUpdateDialog',
  65. components: {
  66. Bios,
  67. Vdi,
  68. Vga,
  69. Machine,
  70. },
  71. mixins: [DialogMixin, WindowsMixin],
  72. data () {
  73. return {
  74. loading: false,
  75. form: {
  76. fc: this.$form.createForm(this),
  77. },
  78. vdi: 'vnc',
  79. is_daemon: false,
  80. decorators: {
  81. disable_delete: [
  82. 'disable_delete',
  83. {
  84. rules: [
  85. { required: true, message: this.$t('compute.text_1270') },
  86. ],
  87. },
  88. ],
  89. // boot_order: [
  90. // 'boot_order',
  91. // {
  92. // rules: [
  93. // { required: true, message: this.$t('compute.text_1271') },
  94. // ],
  95. // },
  96. // ],
  97. bios: [
  98. 'bios',
  99. {
  100. rules: [
  101. { required: true, message: this.$t('compute.text_1272') },
  102. ],
  103. },
  104. ],
  105. vdi: [
  106. 'vdi',
  107. {
  108. rules: [
  109. { required: true, message: this.$t('compute.prompt_vdi') },
  110. ],
  111. },
  112. ],
  113. vga: [
  114. 'vga',
  115. {
  116. rules: [
  117. { required: true, message: this.$t('compute.prompt_vga') },
  118. ],
  119. },
  120. ],
  121. machine: [
  122. 'machine',
  123. {
  124. rules: [
  125. { required: true, message: this.$t('compute.prompt_machine') },
  126. ],
  127. },
  128. ],
  129. disable_usb_kbd: [
  130. 'disable_usb_kbd',
  131. {
  132. initialValue: this.params.data[0]?.metadata?.disable_usb_kbd === 'true',
  133. valuePropName: 'checked',
  134. },
  135. ],
  136. },
  137. bootOrderOptions: [
  138. {
  139. label: this.$t('compute.text_100'),
  140. key: 'cdn',
  141. },
  142. {
  143. label: this.$t('compute.text_1273'),
  144. key: 'dcn',
  145. },
  146. {
  147. label: this.$t('compute.text_104'),
  148. key: 'ncd',
  149. },
  150. ],
  151. disableDeleteOptions: [
  152. {
  153. label: this.$t('compute.text_656'),
  154. key: true,
  155. },
  156. {
  157. label: this.$t('compute.text_569'),
  158. key: false,
  159. },
  160. ],
  161. formItemLayout: {
  162. wrapperCol: {
  163. span: 20,
  164. },
  165. labelCol: {
  166. span: 4,
  167. },
  168. },
  169. }
  170. },
  171. computed: {
  172. isKvm () {
  173. return this.params.data.length >= 1 && this.params.data[0].hypervisor === 'kvm'
  174. },
  175. isArm () {
  176. return this.params.data.length >= 1 && (this.params.data[0].os_arch === 'arm' || this.params.data[0].os_arch === 'aarch64')
  177. },
  178. canAdminUpdate () {
  179. return hasPermission({ key: 'server_update', resourceData: this.params.data[0] }) && this.$store.getters.isAdminMode
  180. },
  181. },
  182. created () {
  183. this.initFormValue(this.params.data[0])
  184. },
  185. methods: {
  186. async handleConfirm () {
  187. this.loading = true
  188. try {
  189. const values = await this.form.fc.validateFields()
  190. values.is_daemon = this.is_daemon
  191. const ids = this.params.data.map(item => item.id)
  192. await this.params.onManager('batchUpdate', {
  193. id: ids,
  194. managerArgs: {
  195. data: values,
  196. },
  197. })
  198. const syncIds = this.params.data.filter(item => item.status === 'ready').map(item => item.id)
  199. if (syncIds && syncIds.length > 0) {
  200. await this.params.onManager('batchPerformAction', {
  201. id: syncIds,
  202. managerArgs: {
  203. action: 'sync',
  204. },
  205. })
  206. }
  207. if (this.isKvm) {
  208. await this.params.onManager('batchPerformAction', {
  209. id: ids,
  210. managerArgs: {
  211. action: 'set-qemu-params',
  212. data: {
  213. disable_usb_kbd: values.disable_usb_kbd,
  214. },
  215. },
  216. })
  217. }
  218. this.loading = false
  219. this.cancelDialog()
  220. } catch (error) {
  221. this.loading = false
  222. }
  223. },
  224. initFormValue (data) {
  225. this.$nextTick(() => {
  226. const updateObj = {
  227. disable_delete: data.disable_delete,
  228. }
  229. if (this.isKvm) {
  230. // updateObj.boot_order = data.boot_order
  231. updateObj.bios = data.bios || (this.isArm ? 'UEFI' : 'BIOS')
  232. updateObj.vdi = data.vdi ? data.vdi : 'vnc'
  233. updateObj.vga = data.vga ? data.vga : 'std'
  234. this.vdi = updateObj.vdi
  235. updateObj.machine = data.machine ? data.machine : (this.isArm ? 'virt' : 'pc')
  236. // updateObj.is_daemon = data.is_daemon
  237. this.is_daemon = data.is_daemon
  238. }
  239. this.form.fc.setFieldsValue(updateObj)
  240. })
  241. },
  242. handleVdiChange (data) {
  243. this.vdi = data.value
  244. },
  245. },
  246. }
  247. </script>