List.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :defaultSearchKey="defaultSearchKey"
  7. :group-actions="groupActions" />
  8. </template>
  9. <script>
  10. import ListMixin from '@/mixins/list'
  11. import WindowsMixin from '@/mixins/windows'
  12. import { getStatusTableColumn, getNameDescriptionTableColumn } from '@/utils/common/tableColumn'
  13. import i18n from '@/locales'
  14. import regexp from '@/utils/regexp'
  15. import expectStatus from '@/constants/expectStatus'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. const PROTOCOL = {
  18. any: i18n.t('compute.any_protocol.text'),
  19. tcp: 'TCP',
  20. udp: 'UDP',
  21. icmp: 'ICMP',
  22. }
  23. const ACTIONS = {
  24. allow: i18n.t('compute.text_976'),
  25. deny: i18n.t('compute.text_977'),
  26. }
  27. export default {
  28. name: 'DirectionList',
  29. mixins: [WindowsMixin, ListMixin, SingleActionsMixin],
  30. props: {
  31. type: {
  32. type: String,
  33. required: true,
  34. },
  35. id: {
  36. type: String,
  37. required: true,
  38. },
  39. isRead: {
  40. type: Boolean,
  41. default: false,
  42. },
  43. listId: {
  44. type: String,
  45. },
  46. data: Object,
  47. },
  48. data () {
  49. const title = this.type === 'out' ? this.$t('compute.text_978') : this.$t('compute.text_979')
  50. const getParams = {
  51. direction: this.type,
  52. order: 'desc',
  53. order_by: 'priority',
  54. secgroup: this.id,
  55. }
  56. return {
  57. getParams,
  58. list: this.$list.createList(this, {
  59. id: this.listId,
  60. resource: 'secgrouprules',
  61. steadyStatus: Object.values(expectStatus.common).flat(),
  62. getParams,
  63. filterOptions: {
  64. cidr: {
  65. label: title,
  66. filter: true,
  67. formatter: val => {
  68. return `cidr.contains("${val}")`
  69. },
  70. },
  71. ports: {
  72. label: this.$t('compute.text_349'),
  73. filter: true,
  74. formatter: val => {
  75. // if ((val && val.toLowerCase(val)) === 'all') {
  76. // return 'ports.isnullorempty()'
  77. // }
  78. return `ports.contains("${val}")`
  79. },
  80. },
  81. },
  82. }),
  83. columns: [
  84. getNameDescriptionTableColumn({
  85. field: 'cidr',
  86. title: 'CIDR',
  87. edit: false,
  88. showDesc: false,
  89. hideField: true,
  90. slotCallback: row => {
  91. if (row.cidr) {
  92. return row.cidr
  93. } else {
  94. return this.$t('compute.any_cidr.text')
  95. }
  96. },
  97. }),
  98. {
  99. field: 'protocol',
  100. title: this.$t('compute.text_980'),
  101. formatter: ({ cellValue, row }) => {
  102. return PROTOCOL[cellValue] || row.protocol
  103. },
  104. },
  105. {
  106. field: 'ports',
  107. title: this.$t('compute.text_349'),
  108. formatter: ({ cellValue, row }) => {
  109. return cellValue === 'any' ? this.$t('compute.any_port.text') : !row.ports ? this.$t('compute.any_port.text') : row.ports
  110. },
  111. },
  112. getStatusTableColumn({ statusModule: 'common' }),
  113. {
  114. field: 'action',
  115. title: this.$t('compute.text_694'),
  116. formatter: ({ cellValue, row }) => {
  117. return ACTIONS[cellValue] || row.action
  118. },
  119. },
  120. {
  121. field: 'priority',
  122. title: this.$t('compute.text_981'),
  123. formatter: ({ row }) => {
  124. if (this.data.brand === 'Aws') {
  125. return '-'
  126. }
  127. return row.priority
  128. },
  129. },
  130. {
  131. field: 'description',
  132. title: this.$t('compute.text_312'),
  133. slots: {
  134. default: ({ row }, h) => {
  135. const ret = []
  136. ret.push(h('list-body-cell-wrap', {
  137. props: {
  138. edit: true,
  139. copy: true,
  140. field: 'description',
  141. row,
  142. onManager: this.onManager,
  143. formRules: [],
  144. },
  145. }))
  146. return ret
  147. },
  148. },
  149. },
  150. ],
  151. groupActions: [
  152. {
  153. label: this.$t('compute.perform_create'),
  154. permission: 'secgrouprules_create',
  155. action: () => {
  156. this.createDialog('EditRulesDialog', {
  157. title: 'create',
  158. data: [{}],
  159. onManager: this.onManager,
  160. refresh: this.refresh,
  161. type: this.type,
  162. secgroup: this.id,
  163. brand: this.data.brand,
  164. cloud_env: this.data.cloud_env,
  165. })
  166. },
  167. meta: () => {
  168. return {
  169. buttonType: 'primary',
  170. validate: !this.isRead,
  171. tooltip: this.isRead ? i18n.t('compute.secgroup.shared') : '',
  172. }
  173. },
  174. },
  175. {
  176. label: this.$t('compute.perform_delete'),
  177. permission: 'secgrouprules_delete',
  178. action: () => {
  179. this.createDialog('DeleteResDialog', {
  180. vm: this,
  181. data: this.list.selectedItems,
  182. columns: this.columns,
  183. title: this.$t('compute.perform_delete'),
  184. name: this.$t('compute.text_984'),
  185. onManager: this.onManager,
  186. })
  187. },
  188. meta: (obj) => {
  189. if (this.isRead) {
  190. return {
  191. validate: !this.isRead,
  192. tooltip: this.isRead ? i18n.t('compute.secgroup.shared') : '',
  193. }
  194. }
  195. return this.$getDeleteResult(this.list.selectedItems)
  196. },
  197. },
  198. ],
  199. }
  200. },
  201. created () {
  202. this.list.fetchData()
  203. },
  204. methods: {
  205. defaultSearchKey (search) {
  206. if (regexp.isPrefixStr(search)) {
  207. return 'cidr'
  208. }
  209. if (regexp.isNumber(search)) {
  210. return 'ports'
  211. }
  212. },
  213. handleOpenSidepage (row) {
  214. this.sidePageTriggerHandle(this, 'SecgroupRuleSidePage', {
  215. id: row.id,
  216. resource: 'secgrouprules',
  217. getParams: this.getParams,
  218. }, {
  219. list: this.list,
  220. })
  221. },
  222. },
  223. }
  224. </script>