List.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions"
  7. :expand-config="{ lazy: true, loadMethod: loadListeners, accordion: true }" />
  8. </template>
  9. <script>
  10. import * as R from 'ramda'
  11. import ListMixin from '@/mixins/list'
  12. import WindowsMixin from '@/mixins/windows'
  13. import { getNameFilter } from '@/utils/common/tableFilter'
  14. import expectStatus from '@/constants/expectStatus'
  15. import ColumnsMixin from '../mixins/columns'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. export default {
  18. name: 'LoadbalancerbackendgroupsList',
  19. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  20. props: {
  21. id: String,
  22. getParams: {
  23. type: [Function, Object],
  24. },
  25. resId: {
  26. type: String,
  27. required: true,
  28. },
  29. data: {
  30. type: Object,
  31. },
  32. },
  33. data () {
  34. let groupActions = []
  35. const provider = R.path(['provider'], this.data)
  36. if (provider && (provider.toLowerCase() !== 'azure' && provider.toLowerCase() !== 'google')) {
  37. groupActions = [
  38. {
  39. label: this.$t('network.text_26'),
  40. permission: 'lb_loadbalancerbackendgroups_create',
  41. action: () => {
  42. this.createDialog('LoadbalancerbackendgroupsCreateDialog', {
  43. title: this.$t('network.text_26'),
  44. loadbalancer: this.resId,
  45. lbData: this.data,
  46. onManager: this.onManager,
  47. refresh: this.refresh,
  48. })
  49. },
  50. meta: () => {
  51. return {
  52. buttonType: 'primary',
  53. }
  54. },
  55. },
  56. {
  57. label: this.$t('network.text_131'),
  58. permission: 'lb_loadbalancerbackendgroups_delete',
  59. action: () => {
  60. this.createDialog('DeleteResDialog', {
  61. vm: this,
  62. data: this.list.selectedItems,
  63. columns: this.columns,
  64. title: this.$t('network.text_131'),
  65. name: this.$t('network.text_139'),
  66. onManager: this.onManager,
  67. })
  68. },
  69. meta: () => {
  70. if (this.list.selectedItems.length > 0) {
  71. const noAliyunDefaultBackendGroup = this.list.selectedItems.every((item) => !this.isAliyunDefaultBackendGroup(item))
  72. if (!noAliyunDefaultBackendGroup) {
  73. return {
  74. validate: false,
  75. tooltip: this.$t('network.lb.default_backendgroup.tips'),
  76. }
  77. }
  78. }
  79. this.$getDeleteResult(this.list.selectedItems)
  80. },
  81. },
  82. ]
  83. }
  84. return {
  85. list: this.$list.createList(this, {
  86. id: 'LoadbalancerBackendgroupList',
  87. resource: 'loadbalancerbackendgroups',
  88. getParams: this.getParam,
  89. fetchDataCb: this.fetchDataCb,
  90. filterOptions: {
  91. name: getNameFilter(),
  92. },
  93. steadyStatus: {
  94. status: Object.values(expectStatus.lb).flat(),
  95. },
  96. }),
  97. groupActions: groupActions,
  98. }
  99. },
  100. created () {
  101. this.list.fetchData()
  102. },
  103. methods: {
  104. fetchDataCb () {
  105. if (this.list.total > 0 && this.data.provider === 'Google') {
  106. for (const item in this.list.data) {
  107. const data = this.list.data[item].data
  108. data.provider = this.data.provider
  109. data.cloudregion = this.data.cloudregion
  110. data.cloudregion_id = this.data.cloudregion_id
  111. data.region = this.data.region
  112. data.region_ext_id = this.data.region_ext_id
  113. data.region_external_id = this.data.region_external_id
  114. data.region_id = this.data.region_id
  115. }
  116. }
  117. },
  118. isAliyunDefaultBackendGroup (obj) {
  119. const provider = obj && obj.provider ? obj.provider : ''
  120. if (provider.toLowerCase() === 'aliyun' && obj.type === 'default') {
  121. return true
  122. }
  123. return false
  124. },
  125. getParam () {
  126. const ret = {
  127. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  128. details: true,
  129. }
  130. return ret
  131. },
  132. handleOpenSidepage (row) {
  133. this.sidePageTriggerHandle(this, 'LoadbalancerbackendgroupSidePage', {
  134. id: row.id,
  135. resource: 'loadbalancerbackendgroups',
  136. getParams: this.getParam,
  137. lbData: this.data,
  138. }, {
  139. list: this.list,
  140. })
  141. },
  142. async loadListeners ({ row }) {
  143. const manager = new this.$Manager('loadbalancerlisteners')
  144. try {
  145. const params = {
  146. backend_group: row.id,
  147. scope: this.$store.getters.scope,
  148. limit: 0,
  149. }
  150. const ret = await manager.list({
  151. params,
  152. })
  153. row.listeners = ret.data.data || []
  154. } catch (err) {
  155. throw err
  156. }
  157. },
  158. },
  159. }
  160. </script>