BindLb.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <a-input-group compact>
  3. <a-form-item style="width: 28%" :wrapperCol="{ span: 24 }">
  4. <a-select class="w-100" @change="handleLbChange" v-decorator="decorators.loadbalancer_id" :placeholder="$t('compute.text_866')">
  5. <a-select-option v-for="item in loadbalancerList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
  6. </a-select>
  7. <div slot="extra" style="white-space:nowrap;">{{$t('compute.text_867')}}</div>
  8. </a-form-item>
  9. <a-form-item style="width: 28%" :wrapperCol="{ span: 24 }">
  10. <a-select class="w-100" v-decorator="decorators.lb_backend_group" :placeholder="$t('compute.text_868')">
  11. <a-select-option v-for="item in groupList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
  12. </a-select>
  13. </a-form-item>
  14. <a-row style="width: 28%">
  15. <a-col :span="11" style="text-align: right;">
  16. <span class="ant-form-item-label">{{$t('compute.text_869')}}</span>
  17. </a-col>
  18. <a-col :span="12">
  19. <a-form-item :wrapperCol="{ span: 24 }">
  20. <a-tooltip :title="$t('compute.text_870')" placement="top">
  21. <a-input-number class="w-100" :min="1" :max="65535" v-decorator="decorators.loadbalancer_backend_port" />
  22. </a-tooltip>
  23. </a-form-item>
  24. </a-col>
  25. </a-row>
  26. <a-row style="width: 15%">
  27. <a-col :span="10" style="text-align: right;">
  28. <span class="ant-form-item-label">{{$t('compute.text_871')}}</span>
  29. </a-col>
  30. <a-col :span="14">
  31. <a-form-item :wrapperCol="{ span: 24 }">
  32. <a-tooltip :title="$t('compute.text_872')" placement="top">
  33. <a-input-number class="w-100" :min="1" :max="256" v-decorator="decorators.loadbalancer_backend_weight" />
  34. </a-tooltip>
  35. </a-form-item>
  36. </a-col>
  37. </a-row>
  38. </a-input-group>
  39. </template>
  40. <script>
  41. import { DECORATORS } from '../constants'
  42. export default {
  43. name: 'BindLb',
  44. props: ['fc'],
  45. data () {
  46. return {
  47. decorators: DECORATORS,
  48. loadbalancerListLoading: false,
  49. loadbalancerList: [],
  50. groupListLoading: false,
  51. groupList: [],
  52. }
  53. },
  54. methods: {
  55. handleLbChange (id) {
  56. this.fetchQueyrGroups(id)
  57. },
  58. async fetchQueryLbs (vpc) {
  59. if (!vpc) {
  60. this.loadbalancerList = []
  61. this.groupList = []
  62. this.fc.setFieldsValue({
  63. loadbalancer_id: undefined,
  64. lb_backend_group: undefined,
  65. })
  66. return false
  67. }
  68. const manager = new this.$Manager('loadbalancers')
  69. this.loadbalancerListLoading = true
  70. try {
  71. const { data } = await manager.list({
  72. params: {
  73. limit: 0,
  74. vpc,
  75. status: 'enabled',
  76. scope: this.$store.getters.scope,
  77. },
  78. })
  79. this.loadbalancerList = data.data || []
  80. } catch (err) {
  81. throw err
  82. } finally {
  83. this.loadbalancerListLoading = false
  84. const list = this.loadbalancerList
  85. const id = (list && list.length > 0) ? list[0].id : undefined
  86. this.fc.setFieldsValue({
  87. loadbalancer_id: id,
  88. }, () => {
  89. if (id) {
  90. this.fetchQueyrGroups(id)
  91. }
  92. })
  93. }
  94. },
  95. async fetchQueyrGroups (loadbalancer) {
  96. const manager = new this.$Manager('loadbalancerbackendgroups')
  97. try {
  98. this.groupListLoading = false
  99. const { data } = await manager.list({
  100. params: {
  101. limit: 0,
  102. loadbalancer,
  103. },
  104. })
  105. this.groupList = data.data || []
  106. } catch (err) {
  107. throw err
  108. } finally {
  109. this.groupListLoading = false
  110. }
  111. },
  112. },
  113. }
  114. </script>