RollbackDisk.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <div slot="message">{{$t('compute.text_1067')}}</div>
  7. </a-alert>
  8. <dialog-selected-tips :name="$t('dictionary.snapshot')" :count="params.data.length" :action="action" />
  9. <dialog-table :data="params.data" :columns="columns" />
  10. <a-form
  11. :form="form.fc">
  12. <a-form-item :label="$t('compute.text_494')" v-bind="formItemLayout" :extra="$t('compute.text_1068')">
  13. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.autoStart" :disabled="disabled" />
  14. </a-form-item>
  15. </a-form>
  16. </div>
  17. <div slot="footer">
  18. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import DialogMixin from '@/mixins/dialog'
  25. import WindowsMixin from '@/mixins/windows'
  26. export default {
  27. name: 'DiskRollbackDialog',
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. return {
  31. loading: false,
  32. action: this.$t('compute.text_1069'),
  33. form: {
  34. fc: this.$form.createForm(this),
  35. },
  36. decorators: {
  37. autoStart: [
  38. 'autoStart',
  39. {
  40. valuePropName: 'checked',
  41. initialValue: true,
  42. },
  43. ],
  44. },
  45. disabled: false,
  46. formItemLayout: {
  47. wrapperCol: {
  48. span: 21,
  49. },
  50. labelCol: {
  51. span: 3,
  52. },
  53. },
  54. }
  55. },
  56. computed: {
  57. columns () {
  58. const showFields = ['name', 'brand', 'disk_type']
  59. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  60. },
  61. },
  62. watch: {
  63. 'params.data': {
  64. immediate: true,
  65. deep: true,
  66. handler (val) {
  67. if (val.some(v => !v.guest)) {
  68. this.disabled = true
  69. this.$nextTick(() => {
  70. this.form.fc.setFieldsValue({ autoStart: false })
  71. })
  72. } else {
  73. this.disabled = false
  74. this.$nextTick(() => {
  75. this.form.fc.setFieldsValue({ autoStart: true })
  76. })
  77. }
  78. },
  79. },
  80. },
  81. methods: {
  82. async doRollbackDiskSubmit (values) {
  83. const params = {
  84. snapshot_id: this.params.data[0].id,
  85. auto_start: values.autoStart,
  86. }
  87. const ids = this.params.data.map(item => item.disk_id)
  88. const manager = new this.$Manager('disks')
  89. return manager.performAction({
  90. id: ids[0],
  91. action: 'disk-reset',
  92. data: params,
  93. })
  94. },
  95. async handleConfirm () {
  96. this.loading = true
  97. try {
  98. const values = await this.form.fc.getFieldsValue()
  99. await this.doRollbackDiskSubmit(values)
  100. this.params.refresh()
  101. this.loading = false
  102. this.cancelDialog()
  103. } catch (error) {
  104. this.loading = false
  105. }
  106. },
  107. },
  108. }
  109. </script>