ImportUnpackDialog.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc" hideRequiredMark v-bind="formItemLayout">
  6. <a-form-item :label="$t('compute.text_297', [$t('dictionary.project')])" class="mb-0">
  7. <domain-project
  8. :fc="form.fc"
  9. :form-layout="formLayout"
  10. :decorators="{
  11. project: decorators.project,
  12. domain: decorators.domain
  13. }" />
  14. </a-form-item>
  15. <a-form-item :label="$t('compute.instance_backup_name')">
  16. <a-input
  17. v-decorator="decorators.name"
  18. :placeholder="$t('common.tips.input', [$t('compute.instance_backup_name')])" />
  19. </a-form-item>
  20. <a-form-item
  21. :label="$t('compute.backup_storage')">
  22. <base-select
  23. style="width: 100%"
  24. v-decorator="decorators.storage"
  25. :params="storageParams"
  26. :select-props="{ placeholder: $t('compute.text_1022', [$t('compute.backup_storage')]) }"
  27. resource="backupstorages"
  28. :filterable="true"
  29. :isDefaultSelect="true" />
  30. </a-form-item>
  31. <a-form-item :label="$t('compute.unpack_name')">
  32. <a-input
  33. v-decorator="decorators.package_name"
  34. :placeholder="$t('common.tips.input', [$t('compute.unpack_name')])" />
  35. </a-form-item>
  36. </a-form>
  37. </div>
  38. <div slot="footer">
  39. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  40. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  41. </div>
  42. </base-dialog>
  43. </template>
  44. <script>
  45. import DialogMixin from '@/mixins/dialog'
  46. import WindowsMixin from '@/mixins/windows'
  47. import DomainProject from '@/sections/DomainProject'
  48. import { isRequired } from '@/utils/validate'
  49. export default {
  50. name: 'ImportUnpackDialog',
  51. components: {
  52. DomainProject,
  53. },
  54. mixins: [DialogMixin, WindowsMixin],
  55. data () {
  56. return {
  57. loading: false,
  58. action: this.$t('compute.text_679'),
  59. form: {
  60. fc: this.$form.createForm(this),
  61. },
  62. decorators: {
  63. domain: [
  64. 'domain',
  65. {
  66. initialValue: this.$store.getters.userInfo.projectDomainId,
  67. rules: [
  68. { validator: isRequired(), message: this.$t('rules.domain'), trigger: 'change' },
  69. ],
  70. },
  71. ],
  72. project: [
  73. 'project',
  74. {
  75. initialValue: this.$store.getters.userInfo.projectId,
  76. rules: [
  77. { validator: isRequired(), message: this.$t('rules.project'), trigger: 'change' },
  78. ],
  79. },
  80. ],
  81. name: [
  82. 'name',
  83. {
  84. rules: [
  85. { required: true, message: this.$t('common.tips.input', [this.$t('compute.instance_backup_name')]) },
  86. ],
  87. },
  88. ],
  89. storage: [
  90. 'storage',
  91. {
  92. rules: [
  93. { required: true, message: this.$t('compute.text_1022', [this.$t('compute.backup_storage')]), trigger: 'change' },
  94. ],
  95. },
  96. ],
  97. package_name: [
  98. 'package_name',
  99. {
  100. rules: [
  101. { required: true, message: this.$t('common.tips.input', [this.$t('compute.unpack_name')]) },
  102. ],
  103. },
  104. ],
  105. },
  106. formItemLayout: {
  107. wrapperCol: {
  108. span: 19,
  109. },
  110. labelCol: {
  111. span: 5,
  112. },
  113. },
  114. storageParams: {},
  115. }
  116. },
  117. methods: {
  118. doImportUnpackSubmit (values) {
  119. const { name, package_name, storage, project } = values
  120. const params = {
  121. package_name,
  122. name,
  123. backup_storage_id: storage,
  124. project_id: project.key,
  125. }
  126. return this.params.onManager('create', {
  127. managerArgs: {
  128. data: params,
  129. },
  130. })
  131. },
  132. async handleConfirm () {
  133. this.loading = false
  134. try {
  135. const values = await this.form.fc.validateFields()
  136. await this.doImportUnpackSubmit(values)
  137. this.params.refresh && this.params.refresh()
  138. this.cancelDialog()
  139. } catch (error) {
  140. throw error
  141. } finally {
  142. this.loading = false
  143. }
  144. },
  145. },
  146. }
  147. </script>