UpdateCapacity.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('storage.text_59')">
  9. <a-input style="width: 150px" name="capacity" v-decorator="decorators.capacity" @blur="handelBlur">
  10. <span slot="addonAfter">
  11. GB
  12. </span>
  13. </a-input>
  14. </a-form-item>
  15. </a-form>
  16. </div>
  17. <div slot="footer">
  18. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import { formItemLayout } from '@Storage/constants/index.js'
  25. import DialogMixin from '@/mixins/dialog'
  26. import WindowsMixin from '@/mixins/windows'
  27. export default {
  28. name: 'BlockStorageUpdateCapacityDialog',
  29. mixins: [DialogMixin, WindowsMixin],
  30. data () {
  31. return {
  32. loading: false,
  33. formItemLayout,
  34. form: {
  35. fc: this.$form.createForm(this),
  36. },
  37. }
  38. },
  39. provide () {
  40. return {
  41. form: this.form,
  42. }
  43. },
  44. computed: {
  45. initCapacity () {
  46. const { data = [] } = this.params
  47. if (data.length > 0) {
  48. return Math.round(parseFloat(data[0].capacity / 1024))
  49. }
  50. return 0
  51. },
  52. decorators () {
  53. return {
  54. capacity: [
  55. 'capacity',
  56. {
  57. initialValue: this.initCapacity,
  58. },
  59. ],
  60. }
  61. },
  62. },
  63. methods: {
  64. handelBlur ({ target }) {
  65. const { value, name } = target
  66. if (!/^\d+$/.test(value)) {
  67. this.form.fc.setFieldsValue({
  68. [name]: this.initCapacity,
  69. })
  70. }
  71. },
  72. async handleConfirm () {
  73. this.loading = true
  74. try {
  75. const { capacity } = await this.form.fc.validateFields()
  76. const manager = new this.$Manager('storages', 'v2')
  77. await manager.update({
  78. id: this.params.data[0].id,
  79. data: {
  80. capacity: parseFloat(capacity) * 1024,
  81. },
  82. })
  83. this.cancelDialog()
  84. this.params.refresh()
  85. this.loading = false
  86. } catch (error) {
  87. this.loading = false
  88. throw error
  89. }
  90. },
  91. },
  92. }
  93. </script>