List.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions" />
  7. </template>
  8. <script>
  9. import * as R from 'ramda'
  10. import ListMixin from '@/mixins/list'
  11. import WindowsMixin from '@/mixins/windows'
  12. import { getNameFilter } from '@/utils/common/tableFilter'
  13. import expectStatus from '@/constants/expectStatus'
  14. import ColumnsMixin from '../mixins/columns'
  15. import SingleActionsMixin from '../mixins/singleActions'
  16. export default {
  17. name: 'LoadbalancerbackendList',
  18. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  19. props: {
  20. id: String,
  21. getParams: {
  22. type: [Function, Object],
  23. },
  24. data: { // 后端服务器组的数据
  25. type: Object,
  26. required: true,
  27. },
  28. isListenerSidepage: {
  29. type: Boolean,
  30. default: false,
  31. },
  32. lbData: {
  33. type: Object,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. id: 'LoadbalancerbackendList',
  40. resource: 'loadbalancerbackends',
  41. getParams: this.getParam,
  42. fetchDataCb: this.fetchDataCb,
  43. filterOptions: {
  44. name: getNameFilter(),
  45. },
  46. steadyStatus: {
  47. status: Object.values(expectStatus.lb).flat(),
  48. },
  49. }),
  50. }
  51. },
  52. computed: {
  53. isAliyunDefaultBackendGroup () {
  54. const provider = this.data && this.data.provider ? this.data.provider : ''
  55. if (provider.toLowerCase() === 'aliyun' && this.data.type === 'default') {
  56. return true
  57. }
  58. return false
  59. },
  60. groupActions () {
  61. if (this.isListenerSidepage) { // 监听抽屉里面不能直接新建后端服务器
  62. return []
  63. }
  64. const provider = R.path(['provider'], this.lbData)
  65. if (provider && (provider.toLowerCase() === 'azure' || provider.toLowerCase() === 'google')) return []
  66. return [
  67. {
  68. label: this.$t('network.text_26'),
  69. permission: 'lb_loadbalancerbackends_create',
  70. action: () => {
  71. const w100Providers = ['aliyun', 'huawei', 'qcloud', 'aws', 'cloudflare']
  72. let maxWeight = 256
  73. if (this.data && this.data.provider) {
  74. if (w100Providers.includes(this.data.provider.toLowerCase())) {
  75. maxWeight = 100
  76. }
  77. }
  78. this.createDialog('LoadbalancerbackendCreateDialog', {
  79. title: this.$t('network.text_26'),
  80. data: this.list.selectedItems,
  81. onManager: this.onManager,
  82. refresh: this.refresh,
  83. lbBackendgroupData: this.data,
  84. maxWeight,
  85. lbData: this.lbData,
  86. listData: this.list.data,
  87. })
  88. },
  89. meta: () => {
  90. return {
  91. validate: !this.isAliyunDefaultBackendGroup,
  92. buttonType: 'primary',
  93. }
  94. },
  95. },
  96. ]
  97. },
  98. },
  99. created () {
  100. if (!this.getParam().backend_group) {
  101. this.list.configLoaded = true // 手动把list.configLoaded变为true,确保list的表头正确渲染
  102. return
  103. }
  104. this.list.fetchData()
  105. },
  106. methods: {
  107. fetchDataCb () {
  108. if (this.list.total > 0 && this.data.provider === 'Google') {
  109. for (const item in this.list.data) {
  110. const data = this.list.data[item].data
  111. data.provider = this.data.provider
  112. data.cloudregion = this.data.cloudregion
  113. data.cloudregion_id = this.data.cloudregion_id
  114. data.region = this.data.region
  115. data.region_ext_id = this.data.region_ext_id
  116. data.region_external_id = this.data.region_external_id
  117. data.region_id = this.data.region_id
  118. }
  119. }
  120. },
  121. getParam () {
  122. const ret = {
  123. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  124. details: true,
  125. }
  126. return ret
  127. },
  128. handleOpenSidepage (row) {
  129. this.sidePageTriggerHandle(this, 'LoadbalancerbackendSidePage', {
  130. id: row.id,
  131. resource: 'loadbalancerbackends',
  132. getParams: this.getParam,
  133. }, {
  134. list: this.list,
  135. })
  136. },
  137. },
  138. }
  139. </script>