CreateDisk.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.snapshot')" :count="params.data.length" :action="action" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('compute.text_297', [$t('dictionary.project')])">
  11. <domain-project :decorators="decorators.projectDomain" :fc="form.fc" :labelInValue="false" />
  12. </a-form-item>
  13. <a-form-item :label="$t('compute.text_228')">
  14. <a-input v-decorator="decorators.name" :placeholder="$t('validator.resourceCreateName')" />
  15. </a-form-item>
  16. </a-form>
  17. </div>
  18. <div slot="footer">
  19. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  20. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  21. </div>
  22. </base-dialog>
  23. </template>
  24. <script>
  25. import DomainProject from '@/sections/DomainProject'
  26. import DialogMixin from '@/mixins/dialog'
  27. import WindowsMixin from '@/mixins/windows'
  28. export default {
  29. name: 'SnapshotCreateDiskDialog',
  30. components: {
  31. DomainProject,
  32. },
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. const { domain_id, tenant_id } = this.params.data[0]
  36. return {
  37. loading: false,
  38. action: this.$t('compute.create_disk'),
  39. form: {
  40. fc: this.$form.createForm(this),
  41. },
  42. decorators: {
  43. projectDomain: {
  44. project: [
  45. 'project',
  46. {
  47. initialValue: tenant_id,
  48. },
  49. ],
  50. domain: [
  51. 'domain',
  52. {
  53. initialValue: domain_id,
  54. },
  55. ],
  56. },
  57. name: [
  58. 'name',
  59. {
  60. validateFirst: true,
  61. rules: [
  62. { required: true, message: this.$t('compute.text_210') },
  63. { validator: this.$validate('resourceCreateName') },
  64. ],
  65. },
  66. ],
  67. },
  68. disabled: false,
  69. formItemLayout: {
  70. wrapperCol: {
  71. span: 21,
  72. },
  73. labelCol: {
  74. span: 3,
  75. },
  76. },
  77. }
  78. },
  79. computed: {
  80. columns () {
  81. const showFields = ['name', 'size', 'storage_type']
  82. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  83. },
  84. },
  85. methods: {
  86. async doCreateDiskSubmit (values) {
  87. const manager = new this.$Manager('disks')
  88. return manager.create({
  89. data: {
  90. project_id: values.project,
  91. name: values.name,
  92. snapshot_id: this.params.data[0].id,
  93. },
  94. })
  95. },
  96. async handleConfirm () {
  97. this.loading = true
  98. try {
  99. const values = await this.form.fc.getFieldsValue()
  100. await this.doCreateDiskSubmit(values)
  101. this.loading = false
  102. this.$message.success(this.$t('k8s.text_184'))
  103. this.$router.push('/disk')
  104. this.cancelDialog()
  105. } catch (error) {
  106. this.loading = false
  107. }
  108. },
  109. },
  110. }
  111. </script>