UpdateBucketLimit.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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('storage.text_18')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('storage.text_59')">
  9. <a-input class="w-50" name="size_bytes" v-decorator="decorators.size_bytes" @blur="handelBlur">
  10. <a-select slot="addonAfter" style="width: 80px" v-decorator="decorators.size_bytes_unit">
  11. <a-select-option v-for="item in sizeUnitOpts" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
  12. </a-select>
  13. </a-input>
  14. <span slot="extra">{{$t('storage.text_127')}}</span>
  15. </a-form-item>
  16. <a-form-item :label="$t('storage.text_128')">
  17. <a-input class="w-50" name="object_count" v-decorator="decorators.object_count" @blur="handelBlur">
  18. <a-select slot="addonAfter" type="number" style="width: 80px" v-decorator="decorators.object_count_unit">
  19. <a-select-option v-for="item in unitOpts" :key="item.value" :value="item.value">{{item.label}}</a-select-option>
  20. </a-select>
  21. </a-input>
  22. <span slot="extra">{{$t('storage.text_127')}}</span>
  23. </a-form-item>
  24. </a-form>
  25. </div>
  26. <div slot="footer">
  27. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $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 { formItemLayout } from '@Storage/constants/index.js'
  34. import { sizestrC } from '@/utils/utils'
  35. import DialogMixin from '@/mixins/dialog'
  36. import WindowsMixin from '@/mixins/windows'
  37. export default {
  38. name: 'BucketUpdateBucketLimitDialog',
  39. components: {
  40. },
  41. mixins: [DialogMixin, WindowsMixin],
  42. data () {
  43. return {
  44. loading: false,
  45. formItemLayout,
  46. form: {
  47. fc: this.$form.createForm(this),
  48. },
  49. sizeUnitOpts: [
  50. { value: Math.pow(1024, 3), label: 'GB' },
  51. { value: Math.pow(1024, 4), label: 'TB' },
  52. { value: Math.pow(1024, 5), label: 'PB' },
  53. { value: Math.pow(1024, 6), label: 'EB' },
  54. ],
  55. unitOpts: [
  56. { value: 1, label: this.$t('storage.text_129') },
  57. { value: 10, label: this.$t('storage.text_130') },
  58. { value: 100, label: this.$t('storage.text_131') },
  59. { value: 1000, label: this.$t('storage.text_132') },
  60. { value: 10000, label: this.$t('storage.text_133') },
  61. ],
  62. }
  63. },
  64. provide () {
  65. return {
  66. form: this.form,
  67. }
  68. },
  69. computed: {
  70. columns () {
  71. return [
  72. this.params.columns[0],
  73. {
  74. field: 'size_bytes_limit',
  75. title: this.$t('storage.text_134'),
  76. width: 120,
  77. formatter: ({ row }) => {
  78. return sizestrC(row.size_bytes_limit, 'B', 1024)
  79. },
  80. },
  81. {
  82. field: 'object_cnt_limit',
  83. title: this.$t('storage.text_135'),
  84. width: 120,
  85. formatter: ({ row }) => {
  86. return row.object_cnt_limit
  87. },
  88. },
  89. ]
  90. },
  91. decorators () {
  92. const { data } = this.params
  93. // eslint-disable-next-line camelcase
  94. const { size_bytes_limit = 0, object_cnt_limit = 0 } = data.length === 1 ? data[0] : {}
  95. return {
  96. size_bytes: [
  97. 'size_bytes',
  98. {
  99. // eslint-disable-next-line camelcase
  100. initialValue: Math.round(size_bytes_limit / (1024 * 1024 * 1024)),
  101. validateFirst: true,
  102. rules: [
  103. { required: true, message: this.$t('storage.text_136') },
  104. ],
  105. },
  106. ],
  107. size_bytes_unit: ['size_bytes_unit', {
  108. initialValue: Math.pow(1024, 3),
  109. }],
  110. object_count: [
  111. 'object_count',
  112. {
  113. initialValue: Math.round(object_cnt_limit),
  114. validateFirst: true,
  115. rules: [
  116. { required: true, message: this.$t('storage.text_137') },
  117. ],
  118. },
  119. ],
  120. object_count_unit: ['object_count_unit', {
  121. initialValue: 1,
  122. }],
  123. }
  124. },
  125. },
  126. methods: {
  127. validateForm () {
  128. return new Promise((resolve, reject) => {
  129. this.form.fc.validateFields((err, values) => {
  130. if (err) return reject(err)
  131. // eslint-disable-next-line camelcase
  132. const { size_bytes, size_bytes_unit, object_count, object_count_unit } = values
  133. const limit = {
  134. size_bytes: parseInt(size_bytes) * parseInt(size_bytes_unit),
  135. object_count: parseInt(object_count) * parseInt(object_count_unit),
  136. }
  137. resolve({
  138. limit,
  139. })
  140. })
  141. })
  142. },
  143. async handleConfirm () {
  144. this.loading = true
  145. try {
  146. const values = await this.validateForm()
  147. const { data } = this.params
  148. await this.params.onManager('batchPerformAction', {
  149. id: data.map(item => item.id),
  150. steadyStatus: ['ready', 'create_fail', 'deleted', 'delete_fail'],
  151. managerArgs: {
  152. action: 'limit',
  153. data: values,
  154. },
  155. })
  156. this.params.refresh()
  157. this.cancelDialog()
  158. } catch (error) {
  159. this.loading = false
  160. throw error
  161. }
  162. },
  163. handelBlur ({ target }) {
  164. const { value, name } = target
  165. if (!/^\d+$/.test(value)) {
  166. this.form.fc.setFieldsValue({
  167. [name]: 0,
  168. })
  169. }
  170. },
  171. },
  172. }
  173. </script>