TapFlow.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 {
  14. getNameDescriptionTableColumn,
  15. getTimeTableColumn,
  16. getEnabledTableColumn,
  17. getCopyWithContentTableColumn,
  18. } from '@/utils/common/tableColumn'
  19. import ListMixin from '@/mixins/list'
  20. import WindowsMixin from '@/mixins/windows'
  21. import { getNameFilter, getDescriptionFilter, getEnabledFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  22. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  23. import validateForm from '@/utils/validate'
  24. export default {
  25. name: 'TapFlowList',
  26. mixins: [WindowsMixin, ListMixin],
  27. props: {
  28. id: String,
  29. getParams: {
  30. type: [Function, Object],
  31. default: () => ({
  32. details: true,
  33. }),
  34. },
  35. data: Object,
  36. },
  37. data () {
  38. return {
  39. list: this.$list.createList(this, {
  40. id: this.id,
  41. resource: 'tap_flows',
  42. apiVersion: 'v1',
  43. getParams: this.getParam,
  44. filterOptions: {
  45. name: getNameFilter(),
  46. description: getDescriptionFilter(),
  47. enabled: getEnabledFilter(),
  48. // type: {
  49. // label: this.$t('compute.text_175'),
  50. // dropdown: true,
  51. // items: [
  52. // { label: this.$t('compute.vswitch'), key: 'vswitch' },
  53. // { label: this.$t('compute.vswitch'), key: 'vnic' },
  54. // ],
  55. // },
  56. // source: getNameFilter({ field: 'source', label: this.$t('compute.source') }),
  57. // mac_addr: getNameFilter({ field: 'mac_addr', label: this.$t('compute.source_mac') }),
  58. // direction: {
  59. // label: this.$t('compute.tap_direction'),
  60. // dropdown: true,
  61. // items: [
  62. // { label: this.$t('compute.direction_in'), key: 'IN' },
  63. // { label: this.$t('compute.direction_out'), key: 'OUT' },
  64. // { label: this.$t('compute.direction_both'), key: 'BOTH' },
  65. // ],
  66. // },
  67. created_at: getCreatedAtFilter(),
  68. },
  69. responseData: this.responseData,
  70. hiddenColumns: ['created_at'],
  71. }),
  72. exportDataOptions: {
  73. items: [
  74. { label: 'ID', key: 'id' },
  75. { label: this.$t('cloudenv.text_95'), key: 'name' },
  76. { label: this.$t('table.title.enable_status'), key: 'enabled' },
  77. { label: this.$t('compute.text_175'), key: 'type' },
  78. { label: this.$t('compute.source'), key: 'source' },
  79. { label: this.$t('compute.source_ip'), key: 'source_ips' },
  80. { label: this.$t('compute.source_mac'), key: 'mac_addr' },
  81. { label: this.$t('compute.vlan_id'), key: 'vlan_id' },
  82. { label: this.$t('compute.tap_direction'), key: 'direction' },
  83. { label: this.$t('common.createdAt'), key: 'created_at' },
  84. ],
  85. },
  86. singleActions: [
  87. ...getEnabledSwitchActions(this),
  88. {
  89. label: this.$t('compute.perform_delete'),
  90. permission: 'tapflows_delete',
  91. action: (obj) => {
  92. this.createDialog('DeleteResDialog', {
  93. vm: this,
  94. data: [obj],
  95. columns: this.columns,
  96. title: this.$t('compute.perform_delete'),
  97. name: this.$t('dictionary.tap_flow'),
  98. onManager: this.onManager,
  99. success: () => {
  100. this.$bus.$emit('tap-service-refresh')
  101. },
  102. })
  103. },
  104. meta: () => {
  105. const ret = {
  106. validate: true,
  107. }
  108. return ret
  109. },
  110. },
  111. ],
  112. groupActions: [
  113. {
  114. label: this.$t('compute.add_tap_flow'),
  115. permission: 'tapservices_create',
  116. action: () => {
  117. this.createDialog('TapFlowCreateDialog', {
  118. tapService: this.data,
  119. onManager: this.onManager,
  120. success: () => {
  121. this.list.refresh()
  122. },
  123. })
  124. },
  125. meta: () => ({
  126. buttonType: 'primary',
  127. }),
  128. },
  129. {
  130. label: this.$t('common.batchAction'),
  131. actions: () => {
  132. return [
  133. ...getEnabledSwitchActions(this, undefined, ['tapflows_perform_enable', 'tapflows_perform_disable'], {
  134. metas: [
  135. () => {
  136. const isEnable = !!this.list.selectedItems.find(item => item.enabled)
  137. return {
  138. validate: this.list.selectedItems.length && !isEnable,
  139. }
  140. },
  141. () => {
  142. const isDisable = !!this.list.selectedItems.find(item => !item.enabled)
  143. return {
  144. validate: this.list.selectedItems.length && !isDisable,
  145. }
  146. },
  147. ],
  148. resourceName: this.$t('dictionary.tap_flow'),
  149. }),
  150. {
  151. label: this.$t('cloudenv.text_108'),
  152. permission: 'tapflows_delete',
  153. action: () => {
  154. this.createDialog('DeleteResDialog', {
  155. vm: this,
  156. data: this.list.selectedItems,
  157. columns: this.columns,
  158. title: this.$t('compute.perform_delete'),
  159. name: this.$t('dictionary.tap_flow'),
  160. onManager: this.onManager,
  161. success: () => {
  162. this.$bus.$emit('tap-service-refresh')
  163. },
  164. })
  165. },
  166. meta: () => {
  167. return {
  168. validate: true,
  169. }
  170. },
  171. },
  172. ]
  173. },
  174. meta: () => {
  175. return {
  176. validate: this.list.selectedItems && this.list.selectedItems.length > 0,
  177. }
  178. },
  179. },
  180. ],
  181. columns: [
  182. getNameDescriptionTableColumn({
  183. onManager: this.onManager,
  184. hideField: true,
  185. formRules: [
  186. { required: true, message: this.$t('compute.text_210') },
  187. { validator: validateForm('serverCreateName') },
  188. ],
  189. slotCallback: row => {
  190. return row.name
  191. },
  192. }),
  193. getEnabledTableColumn(),
  194. // {
  195. // title: this.$t('compute.tap'),
  196. // field: 'tap',
  197. // },
  198. {
  199. title: this.$t('compute.text_175'),
  200. field: 'type',
  201. formatter: ({ row }) => {
  202. if (row.type === 'vswitch') {
  203. return this.$t('compute.vswitch')
  204. }
  205. if (row.type === 'vnic') {
  206. return this.$t('compute.vnic')
  207. }
  208. return '-'
  209. },
  210. },
  211. {
  212. title: this.$t('compute.source'),
  213. field: 'source',
  214. },
  215. {
  216. title: this.$t('compute.source_ip'),
  217. field: 'source_ips',
  218. slots: {
  219. default: ({ row }) => {
  220. const { source_ips = '' } = row
  221. const ips = source_ips.split(',')
  222. return ips.map(ip => {
  223. return <list-body-cell-wrap copy field='ip' row={{ ip }} title={ip} />
  224. })
  225. },
  226. },
  227. },
  228. getCopyWithContentTableColumn({
  229. field: 'mac_addr',
  230. title: this.$t('compute.source_mac'),
  231. hideField: true,
  232. message: (row) => {
  233. return row.mac_addr
  234. },
  235. slotCallback: (row) => {
  236. return row.mac_addr
  237. },
  238. }),
  239. {
  240. title: this.$t('compute.vlan_id'),
  241. field: 'vlan_id',
  242. formatter: ({ row }) => {
  243. return row.vlan_id || '-'
  244. },
  245. },
  246. {
  247. title: this.$t('compute.tap_direction'),
  248. field: 'direction',
  249. formatter: ({ row }) => {
  250. return this.$te(`compute.direction_${row.direction.toLowerCase()}`) ? this.$t(`compute.direction_${row.direction.toLowerCase()}`) : row.direction
  251. },
  252. },
  253. getTimeTableColumn(),
  254. ],
  255. }
  256. },
  257. computed: {
  258. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo', 'isProjectMode']),
  259. },
  260. created () {
  261. this.list.fetchData()
  262. },
  263. methods: {
  264. getParam () {
  265. const ret = {
  266. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  267. }
  268. return ret
  269. },
  270. },
  271. }
  272. </script>