UpdateWeight.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('network.text_352')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.lb_backend')" :count="params.data.length" :action="$t('network.text_352')" />
  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 v-if="params.updateFields.weight" :label="$t('network.text_166')">
  9. <a-input-number :min="0" :max="maxWeight" v-decorator="decorators.weight" />
  10. </a-form-item>
  11. <a-form-item v-if="params.updateFields.port" :label="$t('network.text_165')">
  12. <a-input-number :min="1" :max="65535" v-decorator="decorators.port" />
  13. </a-form-item>
  14. <a-form-item v-if="params.updateFields.status" :label="$t('network.text_189')">
  15. <a-switch v-decorator="decorators.status" />
  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 DialogMixin from '@/mixins/dialog'
  27. import WindowsMixin from '@/mixins/windows'
  28. import expectStatus from '@/constants/expectStatus'
  29. export default {
  30. name: 'BackendUpdateDialog',
  31. components: {
  32. },
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. loading: false,
  37. form: {
  38. fc: this.$form.createForm(this),
  39. },
  40. decorators: {
  41. weight: [
  42. 'weight',
  43. {
  44. initialValue: this.params.data[0].weight,
  45. validateFirst: true,
  46. rules: [
  47. { type: 'integer', required: true, message: this.$t('network.text_177'), trigger: 'blur' },
  48. { type: 'integer', min: 0, max: this.maxWeight, message: this.$t('network.text_353', [this.maxWeight]), trigger: 'blur' },
  49. ],
  50. },
  51. ],
  52. port: [
  53. 'port',
  54. {
  55. initialValue: this.params.data[0].port,
  56. validateFirst: true,
  57. rules: [
  58. { type: 'integer', required: true, message: this.$t('network.text_176'), trigger: 'blur' },
  59. ],
  60. },
  61. ],
  62. status: [
  63. 'status',
  64. {
  65. valuePropName: 'checked',
  66. initialValue: this.params.data[0].status === 'enabled',
  67. },
  68. ],
  69. },
  70. formItemLayout: {
  71. wrapperCol: {
  72. span: 20,
  73. },
  74. labelCol: {
  75. span: 4,
  76. },
  77. },
  78. }
  79. },
  80. computed: {
  81. maxWeight () {
  82. const w100Providers = ['aliyun', 'huawei', 'qcloud', 'aws']
  83. let maxWeight = 256
  84. const val = this.params.data[0]
  85. if (val && val.provider) {
  86. if (w100Providers.includes(val.provider.toLowerCase())) {
  87. maxWeight = 100
  88. }
  89. }
  90. return maxWeight
  91. },
  92. },
  93. methods: {
  94. doUpdate (id, values) {
  95. const data = {}
  96. if (this.params.updateFields.weight) {
  97. data.weight = values.weight
  98. }
  99. if (this.params.updateFields.port) {
  100. data.port = values.port
  101. }
  102. if (this.params.updateFields.status) {
  103. data.status = values.status ? 'enabled' : 'disabled'
  104. }
  105. return this.params.onManager('update', {
  106. id,
  107. managerArgs: {
  108. data,
  109. },
  110. steadyStatus: {
  111. status: Object.values(expectStatus.lb).flat(),
  112. },
  113. })
  114. },
  115. async handleConfirm () {
  116. this.loading = true
  117. try {
  118. const values = await this.form.fc.validateFields()
  119. await this.doUpdate(this.params.data[0].id, values)
  120. this.loading = false
  121. this.cancelDialog()
  122. } catch (error) {
  123. this.loading = false
  124. }
  125. },
  126. },
  127. }
  128. </script>