SetNicNumQueue.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('compute.set_nic_num_queue') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('compute.text_193')" :count="params.data.length" :action="$t('compute.set_nic_num_queue')" />
  6. <dialog-table :data="params.data" :columns="params.columns.filter(item => ['index', 'ifname', 'mac_addr', 'num_queues'].includes(item.field))" />
  7. <a-form-model
  8. ref="form"
  9. class="mt-3"
  10. :model="form"
  11. :rules="rules"
  12. v-bind="formItemLayout">
  13. <a-form-model-item :label="$t('compute.num_queues')" prop="num_queues">
  14. <a-input-number
  15. v-model="form.num_queues"
  16. :min="1"
  17. style="width: 100%" />
  18. </a-form-model-item>
  19. </a-form-model>
  20. </div>
  21. <div slot="footer">
  22. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  23. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  24. </div>
  25. </base-dialog>
  26. </template>
  27. <script>
  28. import DialogMixin from '@/mixins/dialog'
  29. import WindowsMixin from '@/mixins/windows'
  30. export default {
  31. name: 'VmSetNicNumQueueDialog',
  32. mixins: [DialogMixin, WindowsMixin],
  33. data () {
  34. const currentNic = this.params.data[0] || {}
  35. return {
  36. loading: false,
  37. form: {
  38. num_queues: currentNic.num_queues || 1,
  39. },
  40. formItemLayout: {
  41. wrapperCol: {
  42. span: 20,
  43. },
  44. labelCol: {
  45. span: 4,
  46. },
  47. },
  48. }
  49. },
  50. computed: {
  51. currentNic () {
  52. return this.params.data[0] || {}
  53. },
  54. rules () {
  55. const nic = this.currentNic
  56. return {
  57. num_queues: [
  58. { required: true, message: this.$t('compute.set_nic_num_queue.validate_error', ['']), trigger: 'blur' },
  59. {
  60. validator: (rule, value, callback) => {
  61. if (!value || value < 1 || !Number.isInteger(value)) {
  62. const nicName = nic.ifname || nic.name || String(nic.index)
  63. callback(new Error(this.$t('compute.set_nic_num_queue.validate_error', [nicName])))
  64. } else {
  65. callback()
  66. }
  67. },
  68. trigger: 'blur',
  69. },
  70. ],
  71. }
  72. },
  73. },
  74. methods: {
  75. async updateNicNumQueues (values) {
  76. const serverId = this.params.server.id
  77. const nic = this.currentNic
  78. const originalNumQueues = nic.num_queues || 1
  79. // 如果没有变化,直接返回
  80. if (values.num_queues === originalNumQueues) {
  81. return { success: true, message: this.$t('compute.set_nic_num_queue.no_changes') }
  82. }
  83. return new this.$Manager('servers').performAction({
  84. id: serverId,
  85. action: 'set-network-num-queues',
  86. data: {
  87. num_queues: values.num_queues,
  88. mac: nic.mac_addr || nic.mac,
  89. },
  90. })
  91. },
  92. async handleConfirm () {
  93. this.loading = true
  94. try {
  95. await this.$refs.form.validate()
  96. const values = this.form
  97. await this.updateNicNumQueues(values)
  98. this.params.refresh()
  99. this.cancelDialog()
  100. this.$message.success(this.$t('compute.text_423'))
  101. } catch (error) {
  102. if (error.errorFields) {
  103. // 表单验证错误
  104. return
  105. }
  106. this.$message.error(error.message || this.$t('compute.set_nic_num_queue.update_failed'))
  107. } finally {
  108. this.loading = false
  109. }
  110. },
  111. },
  112. }
  113. </script>