UpdateStorage.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="$t('dictionary.blockstorage')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <form-items :storage_type="storage_type" :edit="true" :editData="editData" />
  9. <!-- <a-form-item :label="$t('storage.text_60')" v-if="params.data[0].brand.toLowerCase() !== 'zstack'">
  10. <a-input-number :step="0.1" v-decorator="decorators.commit_bound" :min="0" />
  11. </a-form-item> -->
  12. <a-form-item :label="$t('storage.text_39')">
  13. <a-select v-decorator="decorators.medium_type" style="width: 200px">
  14. <a-select-option v-for="(val, key) in MEDIUM_TYPES" :key="key" :value="key">{{val}}</a-select-option>
  15. </a-select>
  16. </a-form-item>
  17. </a-form>
  18. </div>
  19. <div slot="footer">
  20. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  21. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  22. </div>
  23. </base-dialog>
  24. </template>
  25. <script>
  26. import { formItemLayout, MEDIUM_TYPES } from '@Storage/constants/index.js'
  27. import FormItems from '@Storage/views/blockstorage/components/FormItems'
  28. import { getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. export default {
  32. name: 'BlockStorageUpdateStorageDialog',
  33. components: {
  34. FormItems,
  35. },
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. MEDIUM_TYPES,
  40. loading: false,
  41. formItemLayout,
  42. form: {
  43. fc: this.$form.createForm(this),
  44. },
  45. columns: [
  46. getCopyWithContentTableColumn(),
  47. {
  48. field: 'medium_type',
  49. title: this.$t('storage.text_39'),
  50. formatter: ({ row }) => {
  51. return MEDIUM_TYPES[row.medium_type] || row.medium_type
  52. },
  53. },
  54. ],
  55. }
  56. },
  57. provide () {
  58. return {
  59. form: this.form,
  60. }
  61. },
  62. computed: {
  63. editData () {
  64. if (this.params.data && this.params.data.length > 0) {
  65. return this.params.data[0]
  66. }
  67. return undefined
  68. },
  69. storage_type () {
  70. if (this.params.data && this.params.data.length > 0) {
  71. return this.params.data[0].storage_type
  72. }
  73. return undefined
  74. },
  75. decorators () {
  76. return {
  77. commit_bound: [
  78. 'commit_bound',
  79. {
  80. initialValue: this.params.data[0].commit_bound || 1,
  81. rules: [
  82. { required: true, message: this.$t('storage.text_61') },
  83. ],
  84. },
  85. ],
  86. medium_type: [
  87. 'medium_type',
  88. {
  89. initialValue: this.params.data[0].medium_type,
  90. },
  91. ],
  92. }
  93. },
  94. },
  95. methods: {
  96. validateForm () {
  97. return new Promise((resolve, reject) => {
  98. this.form.fc.validateFields((err, values) => {
  99. if (err) return reject(err)
  100. resolve(values)
  101. })
  102. })
  103. },
  104. async handleConfirm () {
  105. this.loading = true
  106. try {
  107. const values = await this.validateForm()
  108. if (values.commit_bound) {
  109. values.cmtbound = values.commit_bound
  110. Reflect.deleteProperty(values, 'commit_bound')
  111. }
  112. const data = {}
  113. Object.keys(values).map(key => {
  114. if (this.storage_type === 'rbd') {
  115. if (key.startsWith('rbd_')) {
  116. data.storage_conf = { ...(data.storage_conf || {}) }
  117. data.storage_conf[key.replace('rbd_', '')] = values[key]
  118. } else {
  119. data[key] = values[key]
  120. }
  121. } else if (this.storage_type === 'nfs') {
  122. if (key.startsWith('nfs_')) {
  123. data.storage_conf = { ...(data.storage_conf || {}) }
  124. data.storage_conf[key] = values[key]
  125. } else {
  126. data[key] = values[key]
  127. }
  128. } else if (this.storage_type === 'slvm') {
  129. if (key.startsWith('slvm_')) {
  130. data.storage_conf = { ...(data.storage_conf || {}) }
  131. data.storage_conf[key] = values[key]
  132. } else {
  133. data[key] = values[key]
  134. }
  135. } else {
  136. data[key] = values[key]
  137. }
  138. })
  139. const manager = new this.$Manager('storages', 'v2')
  140. await manager.update({ id: this.params.data[0].id, data })
  141. this.cancelDialog()
  142. this.params.refresh()
  143. this.loading = false
  144. } catch (error) {
  145. this.loading = false
  146. throw error
  147. }
  148. },
  149. },
  150. }
  151. </script>