List.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :export-data-options="exportDataOptions"
  8. :placeholder="$t('common.default_search_key', [$t('compute.text_228')])" />
  9. </template>
  10. <script>
  11. import * as R from 'ramda'
  12. import { mapGetters } from 'vuex'
  13. import ColumnsMixin from '../mixins/columns'
  14. import SingleActionsMixin from '../mixins/singleActions'
  15. import ListMixin from '@/mixins/list'
  16. import WindowsMixin from '@/mixins/windows'
  17. import { getNameFilter, getDescriptionFilter, getEnabledFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  18. import globalSearchMixins from '@/mixins/globalSearch'
  19. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  20. export default {
  21. name: 'TapServiceList',
  22. mixins: [WindowsMixin, ListMixin, globalSearchMixins, ColumnsMixin, SingleActionsMixin],
  23. props: {
  24. id: String,
  25. getParams: {
  26. type: [Function, Object],
  27. default: () => ({
  28. details: true,
  29. }),
  30. },
  31. },
  32. data () {
  33. return {
  34. list: this.$list.createList(this, {
  35. id: this.id,
  36. resource: 'tap_services',
  37. apiVersion: 'v1',
  38. getParams: this.getParam,
  39. filterOptions: {
  40. name: getNameFilter(),
  41. description: getDescriptionFilter(),
  42. enabled: getEnabledFilter(),
  43. // type: {
  44. // label: this.$t('compute.text_175'),
  45. // dropdown: true,
  46. // items: [
  47. // { label: this.$t('compute.host_port'), key: 'host' },
  48. // { label: this.$t('compute.guest_port'), key: 'guest' },
  49. // ],
  50. // },
  51. // target: getNameFilter({ field: 'target', label: this.$t('compute.target_name') }),
  52. // target_ips: {
  53. // label: this.$t('compute.target_ip'),
  54. // },
  55. mac_addr: getNameFilter({ field: 'mac_addr', label: this.$t('compute.target_mac') }),
  56. created_at: getCreatedAtFilter(),
  57. },
  58. responseData: this.responseData,
  59. hiddenColumns: ['created_at'],
  60. }),
  61. exportDataOptions: {
  62. items: [
  63. { label: 'ID', key: 'id' },
  64. { label: this.$t('cloudenv.text_95'), key: 'name' },
  65. { label: this.$t('table.title.enable_status'), key: 'enabled' },
  66. { label: this.$t('compute.text_175'), key: 'type' },
  67. { label: this.$t('compute.target_name'), key: 'target' },
  68. { label: this.$t('compute.target_ip'), key: 'target_ips' },
  69. { label: this.$t('compute.target_mac'), key: 'mac_addr' },
  70. { label: this.$t('compute.flow_count'), key: 'flow_count' },
  71. { label: this.$t('common.createdAt'), key: 'created_at' },
  72. ],
  73. },
  74. groupActions: [
  75. {
  76. label: this.$t('compute.perform_create'),
  77. permission: 'tapservices_create',
  78. action: () => {
  79. this.$router.push({
  80. name: 'TapServiceCreate',
  81. })
  82. },
  83. meta: () => ({
  84. buttonType: 'primary',
  85. }),
  86. },
  87. {
  88. label: this.$t('common.batchAction'),
  89. actions: () => {
  90. return [
  91. ...getEnabledSwitchActions(this, undefined, ['tapservices_perform_enable', 'tapservices_perform_disable'], {
  92. metas: [
  93. () => {
  94. const isEnable = !!this.list.selectedItems.find(item => item.enabled)
  95. return {
  96. validate: this.list.selectedItems.length && !isEnable,
  97. }
  98. },
  99. () => {
  100. const isDisable = !!this.list.selectedItems.find(item => !item.enabled)
  101. return {
  102. validate: this.list.selectedItems.length && !isDisable,
  103. }
  104. },
  105. ],
  106. resourceName: this.$t('dictionary.tap_service'),
  107. }),
  108. {
  109. label: this.$t('cloudenv.text_108'),
  110. permission: 'tapservices_delete',
  111. action: () => {
  112. this.createDialog('DeleteResDialog', {
  113. vm: this,
  114. data: this.list.selectedItems,
  115. columns: this.columns,
  116. title: this.$t('compute.perform_delete'),
  117. name: this.$t('dictionary.tap_service'),
  118. onManager: this.onManager,
  119. })
  120. },
  121. meta: () => {
  122. const ret = {
  123. validate: true,
  124. }
  125. if (this.list.selectedItems.some(item => item.flow_count)) {
  126. ret.validate = false
  127. ret.tooltip = this.$t('compute.tap_service_delete_tip')
  128. }
  129. return ret
  130. },
  131. },
  132. ]
  133. },
  134. meta: () => {
  135. return {
  136. validate: this.list.selectedItems && this.list.selectedItems.length > 0,
  137. }
  138. },
  139. },
  140. ],
  141. }
  142. },
  143. computed: {
  144. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo', 'isProjectMode']),
  145. },
  146. created () {
  147. this.initSidePageTab('tap-service-detail')
  148. this.list.fetchData()
  149. this.$bus.$on('tap-service-refresh', () => {
  150. this.list.refresh()
  151. })
  152. },
  153. methods: {
  154. getParam () {
  155. const ret = {
  156. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  157. }
  158. return ret
  159. },
  160. handleOpenSidepage (row) {
  161. this.sidePageTriggerHandle(this, 'TapServiceSidePage', {
  162. id: row.id,
  163. resource: 'tap_services',
  164. getParams: this.getParam,
  165. tab: 'tap-service-detail',
  166. }, {
  167. list: this.list,
  168. })
  169. },
  170. },
  171. }
  172. </script>