UnMountUpdateDialog.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.disk_perform_detach')}}</div>
  4. <div slot="body">
  5. <a-alert :message="$t('compute.text_440')" banner />
  6. <dialog-selected-tips :count="params.data.length" :action="$t('compute.disk_perform_detach')" :name="$t('dictionary.disk')" />
  7. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form :form="form.fc" hideRequiredMark>
  9. <a-form-item class="mb-0">
  10. <a-checkbox v-decorator="decorators.keep_disk" :disabled="disabledKeepDisk">{{ $t('compute.disk.detach') }}</a-checkbox>
  11. </a-form-item>
  12. </a-form>
  13. </div>
  14. <div slot="footer">
  15. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  16. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  17. </div>
  18. </base-dialog>
  19. </template>
  20. <script>
  21. import DialogMixin from '@/mixins/dialog'
  22. import WindowsMixin from '@/mixins/windows'
  23. export default {
  24. name: 'DiskUnMountUpdateDialog',
  25. mixins: [DialogMixin, WindowsMixin],
  26. data () {
  27. const initKeepDisk = this.params.data[0] && (this.params.data[0].provider === 'VMware' || this.params.data[0].provider === 'Nutanix')
  28. return {
  29. loading: false,
  30. form: {
  31. fc: this.$form.createForm(this),
  32. },
  33. decorators: {
  34. keep_disk: [
  35. 'keep_disk',
  36. {
  37. valuePropName: 'checked',
  38. initialValue: initKeepDisk,
  39. },
  40. ],
  41. },
  42. disabledKeepDisk: initKeepDisk,
  43. }
  44. },
  45. created () {
  46. const params = {
  47. details: false,
  48. disk: this.params.data[0].id,
  49. }
  50. new this.$Manager('servers').list({ params })
  51. .then((res) => {
  52. this.serversOpts = res.data.data
  53. })
  54. },
  55. methods: {
  56. async doUpdate (data) {
  57. const guestId = this.params.data[0] && this.params.data[0].guests[0] && this.params.data[0].guests[0].id
  58. const diskId = this.params.data[0] && this.params.data[0].id
  59. // 删除前先先将auto_delete改为true
  60. if (data.keep_disk) {
  61. await new this.$Manager('disks').update({
  62. id: diskId,
  63. data: {
  64. auto_delete: true,
  65. },
  66. })
  67. }
  68. return new this.$Manager('servers').performAction({
  69. action: 'detachdisk',
  70. id: guestId,
  71. data: {
  72. disk_id: this.params.data[0].id,
  73. keep_disk: !data.keep_disk,
  74. },
  75. })
  76. },
  77. async handleConfirm () {
  78. this.loading = true
  79. try {
  80. this.loading = true
  81. const values = await this.form.fc.validateFields()
  82. await this.doUpdate(values)
  83. this.loading = false
  84. this.params.refresh()
  85. this.cancelDialog()
  86. } catch (error) {
  87. this.loading = false
  88. }
  89. },
  90. },
  91. }
  92. </script>