CreateBackupDialog.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.create_disk_backup')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="$t('compute.create_disk_backup')" :name="$t('dictionary.disk')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('compute.backup_name')">
  11. <a-input v-decorator="decorators.name" />
  12. </a-form-item>
  13. <a-form-item
  14. :label="$t('compute.backup_storage')">
  15. <base-select
  16. style="width: 100%"
  17. v-decorator="decorators.storage"
  18. :params="storageParams"
  19. :select-props="{ placeholder: $t('compute.text_1022', [$t('compute.backup_storage')]) }"
  20. resource="backupstorages"
  21. :filterable="true"
  22. :isDefaultSelect="true" />
  23. </a-form-item>
  24. </a-form>
  25. </div>
  26. <div slot="footer">
  27. <a-button type="primary" @click="handleConfirm" :loading="loading" :disabled="confirmDisabled">{{ $t('dialog.ok') }}</a-button>
  28. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  29. </div>
  30. </base-dialog>
  31. </template>
  32. <script>
  33. import DialogMixin from '@/mixins/dialog'
  34. import WindowsMixin from '@/mixins/windows'
  35. export default {
  36. name: 'DiskCreateBackupDialog',
  37. mixins: [DialogMixin, WindowsMixin],
  38. data () {
  39. return {
  40. loading: false,
  41. form: {
  42. fc: this.$form.createForm(this),
  43. },
  44. decorators: {
  45. name: [
  46. 'name',
  47. {
  48. validateFirst: true,
  49. rules: [
  50. { required: true, message: this.$t('compute.text_416') },
  51. // { validator: this.$validate('snapshotName') },
  52. ],
  53. },
  54. ],
  55. storage: [
  56. 'storage',
  57. {
  58. rules: [
  59. { required: true, message: this.$t('compute.text_1022', [this.$t('compute.backup_storage')]), trigger: 'change' },
  60. ],
  61. },
  62. ],
  63. },
  64. formItemLayout: {
  65. wrapperCol: {
  66. span: 21,
  67. },
  68. labelCol: {
  69. span: 3,
  70. },
  71. },
  72. storageParams: {},
  73. }
  74. },
  75. methods: {
  76. validateForm () {
  77. return new Promise((resolve, reject) => {
  78. this.form.fc.validateFields((err, values) => {
  79. if (!err) {
  80. resolve(values)
  81. } else {
  82. reject(err)
  83. }
  84. })
  85. })
  86. },
  87. doCreate (data) {
  88. return new this.$Manager('diskbackups').create({ data })
  89. },
  90. async handleConfirm () {
  91. this.loading = true
  92. try {
  93. let values = await this.validateForm()
  94. values = {
  95. name: values.name,
  96. backup_storage_id: values.storage,
  97. disk_id: this.params.data[0].id,
  98. }
  99. this.loading = true
  100. await this.doCreate(values)
  101. this.loading = false
  102. this.params.refresh()
  103. this.cancelDialog()
  104. } catch (error) {
  105. this.loading = false
  106. }
  107. },
  108. },
  109. }
  110. </script>