SetSpeed.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="action" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item v-for="(obj, idx) in disksInfo" :key="idx">
  10. <a-card size="small">
  11. <div slot="title"><a-tag>{{ obj.disk_type === 'sys' ? $t('common_432') : $t('common_433') }}</a-tag> {{obj.name}}</div>
  12. <a-row>
  13. <a-col :span="12">
  14. <a-form-item v-bind="formItemLayout" :extra="$t('compute.not_limited')">
  15. <span slot="label">
  16. {{ $t('compute.iops') }}&nbsp;
  17. <a-tooltip :title="$t('compute.text_1248_tip')">
  18. <a-icon type="question-circle-o" />
  19. </a-tooltip>
  20. </span>
  21. <span>
  22. <a-input-number :min="0" :step="50" v-decorator="decorators.iops(idx)" />
  23. </span>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :span="12">
  27. <a-form-item v-bind="formItemLayout" :extra="$t('compute.not_limited')">
  28. <span slot="label">
  29. {{ $t('compute.bps') }}&nbsp;
  30. <a-tooltip :title="$t('compute.text_1248_1_tip')">
  31. <a-icon type="question-circle-o" />
  32. </a-tooltip>
  33. </span>
  34. <span>
  35. <a-input-number :min="0" :step="50" v-decorator="decorators.bps(idx)" />
  36. </span>
  37. <span class="ml-2">M/s</span>
  38. </a-form-item>
  39. </a-col>
  40. </a-row>
  41. </a-card>
  42. </a-form-item>
  43. </a-form>
  44. </div>
  45. <div slot="footer">
  46. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  47. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  48. </div>
  49. </base-dialog>
  50. </template>
  51. <script>
  52. import DialogMixin from '@/mixins/dialog'
  53. import WindowsMixin from '@/mixins/windows'
  54. export default {
  55. name: 'VmSetSpeedDialog',
  56. mixins: [DialogMixin, WindowsMixin],
  57. data () {
  58. return {
  59. loading: false,
  60. action: this.$t('compute.text_1249'),
  61. form: {
  62. fc: this.$form.createForm(this),
  63. fi: {},
  64. },
  65. decorators: {
  66. iops: i => [
  67. `iops${i}`,
  68. {
  69. initialValue: 0,
  70. rules: [
  71. { required: true, message: this.$t('compute.text_1250') },
  72. ],
  73. },
  74. ],
  75. bps: i => [
  76. `bps${i}`,
  77. {
  78. initialValue: 0,
  79. rules: [
  80. { required: true, message: this.$t('compute.text_1250_1') },
  81. ],
  82. },
  83. ],
  84. unit: [
  85. 'unit',
  86. {
  87. initialValue: 'M',
  88. },
  89. ],
  90. },
  91. formItemLayout: {
  92. wrapperCol: {
  93. span: 12,
  94. },
  95. labelCol: {
  96. span: 8,
  97. },
  98. },
  99. }
  100. },
  101. computed: {
  102. disksInfo () {
  103. return this.params.data[0].disks_info
  104. },
  105. },
  106. created () {
  107. this.initialValue()
  108. },
  109. methods: {
  110. initialValue () {
  111. this.$nextTick(() => {
  112. this.disksInfo.forEach((o, i) => {
  113. this.form.fc.setFieldsValue({
  114. [`iops${i}`]: o.iops,
  115. [`bps${i}`]: o.bps / 1024 / 1024,
  116. })
  117. })
  118. })
  119. },
  120. async doSetSpeedSubmit (values) {
  121. const bps = {}
  122. const iops = {}
  123. this.disksInfo.forEach((o, i) => {
  124. bps[o.id] = +(values[`bps${i}`]) * 1024 * 1024
  125. iops[o.id] = values[`iops${i}`]
  126. })
  127. const params = {
  128. bps,
  129. iops,
  130. }
  131. const ids = this.params.data.map(item => item.id)
  132. return this.params.onManager('batchPerformAction', {
  133. id: ids,
  134. steadyStatus: ['running', 'ready'],
  135. managerArgs: {
  136. action: 'io-throttle',
  137. data: params,
  138. },
  139. })
  140. },
  141. async handleConfirm () {
  142. this.loading = true
  143. try {
  144. const values = await this.form.fc.validateFields()
  145. await this.doSetSpeedSubmit(values)
  146. this.loading = false
  147. this.cancelDialog()
  148. } catch (error) {
  149. this.loading = false
  150. }
  151. },
  152. },
  153. }
  154. </script>