RollbackHostDialog.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ params.title }}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" :message="$t('compute.text_1354')" banner />
  6. <dialog-selected-tips :count="params.data.length" :action="$t('compute.text_1355')" :name="params.name" />
  7. <dialog-table :data="params.data" :columns="columns" />
  8. <a-form
  9. :form="form.fc">
  10. <a-form-item :label="$t('compute.text_494')" :extra="$t('compute.text_1356')" v-bind="formItemLayout">
  11. <a-switch v-decorator="decorators.auto_start" :checked-children="$t('compute.text_115')" :un-checked-children="$t('compute.text_116')" />
  12. </a-form-item>
  13. <a-form-item v-if="hasMemorySnapshot">
  14. <a-checkbox
  15. v-decorator="decorators.with_memory">
  16. {{$t('compute.rollback_mem_snapshot_same_time')}}
  17. </a-checkbox>
  18. </a-form-item>
  19. </a-form>
  20. </div>
  21. <div slot="footer">
  22. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  23. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  24. </div>
  25. </base-dialog>
  26. </template>
  27. <script>
  28. import { mapGetters } from 'vuex'
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. export default {
  32. name: 'RollbackHostDialog',
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. loading: false,
  37. form: {
  38. fc: this.$form.createForm(this),
  39. },
  40. decorators: {
  41. auto_start: [
  42. 'auto_start',
  43. {
  44. valuePropName: 'checked',
  45. initialValue: true,
  46. },
  47. ],
  48. with_memory: [
  49. 'with_memory',
  50. ],
  51. },
  52. formItemLayout: {
  53. wrapperCol: {
  54. span: 21,
  55. },
  56. labelCol: {
  57. span: 3,
  58. },
  59. },
  60. }
  61. },
  62. computed: {
  63. ...mapGetters(['isAdminMode', 'isDomainMode', 'scope']),
  64. columns () {
  65. const showFields = ['name', 'guest', 'brand']
  66. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  67. },
  68. hasMemorySnapshot () {
  69. return this.params.data[0].with_memory
  70. },
  71. },
  72. methods: {
  73. doRollback (data) {
  74. const guestId = this.params.data[0] && this.params.data[0].guest_id
  75. return new this.$Manager('servers').performAction({
  76. action: 'instance-snapshot-reset',
  77. id: guestId,
  78. data,
  79. })
  80. },
  81. async handleConfirm () {
  82. this.loading = true
  83. try {
  84. const values = await this.form.fc.validateFields()
  85. this.loading = true
  86. values.instance_snapshot = this.params.data[0].id
  87. await this.doRollback(values)
  88. this.loading = false
  89. this.params.refresh()
  90. this.cancelDialog()
  91. } catch (error) {
  92. this.loading = false
  93. throw error
  94. }
  95. },
  96. },
  97. }
  98. </script>