DeleteBackup.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1209')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1209')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" hideRequiredMark>
  8. <a-form-item :label="$t('compute.text_1210')" v-bind="formItemLayout" :extra="$t('compute.text_1211')">
  9. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" :disabled="disableAutoPurge" v-decorator="decorators.purge" />
  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: 'VmDeleteBackupDialog',
  24. mixins: [DialogMixin, WindowsMixin],
  25. data () {
  26. return {
  27. loading: false,
  28. form: {
  29. fc: this.$form.createForm(this),
  30. },
  31. decorators: {
  32. purge: [
  33. 'purge',
  34. {
  35. initialValue: false,
  36. valuePropName: 'checked',
  37. },
  38. ],
  39. },
  40. formItemLayout: {
  41. wrapperCol: {
  42. span: 21,
  43. },
  44. labelCol: {
  45. span: 3,
  46. },
  47. },
  48. }
  49. },
  50. computed: {
  51. columns () {
  52. const col = this.params.columns.slice(0, 3)
  53. col.push({
  54. field: 'backup_host_status',
  55. title: this.$t('compute.text_1163'),
  56. width: 120,
  57. showOverflow: 'ellipsis',
  58. slots: {
  59. default: ({ row }) => {
  60. return [<status status={ row.backup_host_status } statusModule='host_status'/>]
  61. },
  62. },
  63. })
  64. return col
  65. },
  66. disableAutoPurge () {
  67. return this.params.data.some((obj) => { return obj.backup_host_status === 'online' })
  68. },
  69. },
  70. mounted () {
  71. const isOnline = this.params.data.some((obj) => { return obj.backup_host_status === 'online' })
  72. if (!isOnline) {
  73. this.form.fc.setFieldsValue({
  74. purge: true,
  75. })
  76. }
  77. },
  78. methods: {
  79. async handleConfirm () {
  80. this.loading = true
  81. try {
  82. const values = await this.form.fc.validateFields()
  83. const ids = this.params.data.map(item => item.id)
  84. await this.params.onManager('batchPerformAction', {
  85. id: ids,
  86. steadyStatus: ['running', 'ready'],
  87. managerArgs: {
  88. action: 'delete-backup',
  89. data: values,
  90. },
  91. })
  92. this.cancelDialog()
  93. } finally {
  94. this.loading = false
  95. }
  96. },
  97. },
  98. }
  99. </script>