List.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import * as R from 'ramda'
  11. import { mapGetters } from 'vuex'
  12. import ColumnsMixin from '../mixins/columns'
  13. import SingleActionsMixin from '../mixins/singleActions'
  14. import ListMixin from '@/mixins/list'
  15. import WindowsMixin from '@/mixins/windows'
  16. export default {
  17. name: 'SshProxyMatchList',
  18. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  19. props: {
  20. id: String,
  21. proxyEndpointId: String,
  22. getParams: {
  23. type: [Function, Object],
  24. },
  25. },
  26. data () {
  27. return {
  28. list: this.$list.createList(this, {
  29. id: this.id,
  30. resource: 'proxy_matches',
  31. getParams: this.getParam,
  32. filterOptions: {
  33. name: {
  34. label: this.$t('network.text_21'),
  35. filter: true,
  36. formatter: val => {
  37. return `name.contains(${val})`
  38. },
  39. },
  40. },
  41. extraDataFecther: {
  42. vpc: async (listData, params) => {
  43. const vpcIds = listData.data.filter((row) => { return row.match_scope === 'vpc' }).map((row) => { return row.match_value })
  44. const vpcIdMap = {}
  45. if (vpcIds.length > 0) {
  46. try {
  47. const { data: { data = [] } } = await new this.$Manager('vpcs').list({
  48. params: {
  49. 'filter.0': `id.in(${vpcIds.join(',')})`,
  50. scope: this.$store.getters.scope,
  51. },
  52. })
  53. data.map((row) => { vpcIdMap[row.id] = row.name })
  54. } catch (e) {
  55. throw e
  56. }
  57. }
  58. return { data: vpcIdMap }
  59. },
  60. network: async (listData, params) => {
  61. const networkIds = listData.data.filter((row) => { return row.match_scope === 'network' }).map((row) => { return row.match_value })
  62. const networkIdMap = {}
  63. if (networkIds.length > 0) {
  64. try {
  65. const { data: { data = [] } } = await new this.$Manager('networks').list({
  66. params: {
  67. 'filter.0': `id.in(${networkIds.join(',')})`,
  68. scope: this.$store.getters.scope,
  69. },
  70. })
  71. data.map((row) => { networkIdMap[row.id] = row.name })
  72. } catch (e) {
  73. throw e
  74. }
  75. }
  76. return { data: networkIdMap }
  77. },
  78. },
  79. }),
  80. exportDataOptions: {
  81. items: [
  82. { label: 'ID', key: 'id' },
  83. { label: this.$t('network.text_21'), key: 'name' },
  84. ],
  85. },
  86. groupActions: [
  87. {
  88. label: this.$t('network.ssh-proxy-match.link'),
  89. permission: 'sshproxy_match_link',
  90. action: () => {
  91. this.createDialog('SshProxyMatchLinkDialog', {
  92. proxy_endpoint_id: this.proxyEndpointId,
  93. list: this.list,
  94. })
  95. },
  96. meta: () => {
  97. const ret = {
  98. validate: true,
  99. tooltip: null,
  100. buttonType: 'primary',
  101. }
  102. return ret
  103. },
  104. },
  105. {
  106. label: this.$t('network.ssh-proxy-match.unlink'),
  107. permission: 'sshproxy_match_unlink',
  108. action: () => {
  109. this.createDialog('DeleteResDialog', {
  110. vm: this,
  111. data: this.list.selectedItems,
  112. columns: this.columns,
  113. title: this.$t('network.ssh-proxy-match.unlink'),
  114. name: this.$t('network.ssh-proxy.match'),
  115. onManager: this.onManager,
  116. })
  117. },
  118. meta: () => {
  119. return {
  120. validate: this.list.allowDelete(),
  121. }
  122. },
  123. },
  124. ],
  125. }
  126. },
  127. computed: {
  128. ...mapGetters(['isAdminMode', 'isDomainMode', 'isProjectMode', 'userInfo']),
  129. },
  130. created () {
  131. this.initSidePageTab('SshProxyMatch-detail')
  132. this.list.fetchData()
  133. },
  134. methods: {
  135. getParam () {
  136. return { ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams) }
  137. },
  138. handleOpenSidepage (row) {
  139. this.sidePageTriggerHandle(this, 'SshProxyMatchSidePage', {
  140. id: row.id,
  141. resource: 'proxy_matches',
  142. getParams: this.getParam,
  143. }, {
  144. list: this.list,
  145. })
  146. },
  147. },
  148. }
  149. </script>