SwitchBackup.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1259')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1259')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" hideRequiredMark>
  8. <a-form-item :label="$t('compute.text_1209')" v-bind="formItemLayout" :extra="$t('compute.text_1260')">
  9. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.delete_backup" />
  10. </a-form-item>
  11. </a-form>
  12. </div>
  13. <div slot="footer">
  14. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  15. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  16. </div>
  17. </base-dialog>
  18. </template>
  19. <script>
  20. import DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'VmSwitchBackupDialog',
  24. mixins: [DialogMixin, WindowsMixin],
  25. data () {
  26. return {
  27. loading: false,
  28. form: {
  29. fc: this.$form.createForm(this),
  30. },
  31. decorators: {
  32. delete_backup: [
  33. 'delete_backup',
  34. {
  35. initialValue: true,
  36. valuePropName: 'checked',
  37. },
  38. ],
  39. },
  40. formItemLayout: {
  41. wrapperCol: {
  42. span: 21,
  43. },
  44. labelCol: {
  45. span: 3,
  46. },
  47. },
  48. purge_backup: false,
  49. }
  50. },
  51. computed: {
  52. columns () {
  53. const col = this.params.columns.slice(0, 3)
  54. col.push({
  55. field: 'backup_host_status',
  56. title: this.$t('compute.text_1163'),
  57. width: 120,
  58. showOverflow: 'ellipsis',
  59. slots: {
  60. default: ({ row }) => {
  61. return [<status status={ row.backup_host_status } statusModule='host_status'/>]
  62. },
  63. },
  64. })
  65. return col
  66. },
  67. },
  68. created () {
  69. this.fetchHosts(this.params.data[0])
  70. },
  71. methods: {
  72. async fetchHosts (data) {
  73. this.loading = true
  74. try {
  75. const manager = new this.$Manager('hosts')
  76. const response = await manager.get({ id: data.host_id })
  77. if (response.data.host_status !== 'online') {
  78. this.form.fc.setFieldsValue({
  79. delete_backup: true,
  80. })
  81. this.purge_backup = true
  82. } else {
  83. this.form.fc.setFieldsValue({
  84. delete_backup: false,
  85. })
  86. this.purge_backup = false
  87. }
  88. } finally {
  89. this.loading = false
  90. }
  91. },
  92. async handleConfirm () {
  93. this.loading = true
  94. try {
  95. const values = await this.form.fc.validateFields()
  96. const ids = this.params.data.map(item => item.id)
  97. const purgeBackup = values.delete_backup ? this.purge_backup : false
  98. const data = { delete_backup: values.delete_backup, purge_backup: purgeBackup }
  99. await this.params.onManager('batchPerformAction', {
  100. id: ids,
  101. steadyStatus: ['running', 'ready'],
  102. managerArgs: {
  103. action: 'switch-to-backup',
  104. data,
  105. },
  106. })
  107. this.cancelDialog()
  108. } finally {
  109. this.loading = false
  110. }
  111. },
  112. },
  113. }
  114. </script>