List.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :single-actions="singleActions"
  6. :group-actions="groupActions"
  7. @refresh="refreshRule" />
  8. </template>
  9. <script>
  10. import _ from 'lodash'
  11. import WindowsMixin from '@/mixins/windows'
  12. import ListMixin from '@/mixins/list'
  13. import { getNameFilter } from '@/utils/common/tableFilter'
  14. import { getNameDescriptionTableColumn } from '@/utils/common/tableColumn'
  15. import { RULE_ACTIONS } from '../constants'
  16. export default {
  17. name: 'WafRules',
  18. mixins: [WindowsMixin, ListMixin],
  19. props: {
  20. id: String,
  21. data: {
  22. type: Object,
  23. },
  24. },
  25. data () {
  26. const filterActions = this.data.provider === 'Cloudflare' ? RULE_ACTIONS : [
  27. { label: this.$t('network.waf.rule_action_Allow'), key: 'Allow' },
  28. { label: this.$t('network.waf.rule_action_Block'), key: 'Block' },
  29. { label: this.$t('network.waf.rule_action_Log'), key: 'Log' },
  30. { label: this.$t('network.waf.rule_action_Count'), key: 'Count' },
  31. { label: this.$t('network.waf.rule_action_Alert'), key: 'Alert' },
  32. { label: this.$t('network.waf.rule_action_Detection'), key: 'Detection' },
  33. { label: this.$t('network.waf.rule_action_Prevention'), key: 'Prevention' },
  34. // { label: this.$t('network.waf.null'), key: '' },
  35. ]
  36. return {
  37. list: this.$list.createList(this, {
  38. id: this.id,
  39. apiVersion: 'v2',
  40. resource: 'waf_rules',
  41. getParams: { details: true, waf_instance_id: this.data.id },
  42. filterOptions: {
  43. name: getNameFilter(),
  44. action: {
  45. label: this.$t('network.waf.action'),
  46. dropdown: true,
  47. multiple: true,
  48. items: filterActions,
  49. filter: true,
  50. mapper: (data) => {
  51. return data.map(item => {
  52. return {
  53. key: item.key,
  54. label: item.key,
  55. }
  56. })
  57. },
  58. formatter: val => {
  59. return `action.contains(${val})`
  60. },
  61. },
  62. },
  63. }),
  64. groupActions: [
  65. {
  66. label: this.$t('compute.perform_create'),
  67. action: () => {
  68. this.createDialog('WafRuleCreateDialog', {
  69. waf: this.data,
  70. columns: this.columns,
  71. success: () => {
  72. this.list.fetchData()
  73. },
  74. })
  75. },
  76. meta: () => {
  77. return {
  78. validate: this.data.provider === 'Cloudflare',
  79. tooltip: this.data.provider !== 'Cloudflare' ? this.$t('cloudenv.brand_action_deny') : '',
  80. }
  81. },
  82. },
  83. ],
  84. singleActions: [
  85. {
  86. label: this.$t('network.waf.rule_view_action'),
  87. permission: 'scheduledtasks_perform_set_label',
  88. action: (row) => {
  89. if (this.data.provider !== 'Cloudflare') {
  90. this.createDialog('WafRuleInfoDialog', {
  91. title: this.$t('network.waf.rule_view'),
  92. data: [row],
  93. isEdit: false,
  94. resData: this.data,
  95. columns: this.columns,
  96. })
  97. } else {
  98. this.createDialog('WafRuleCreateDialog', {
  99. title: this.$t('network.waf.rule_view'),
  100. data: [row],
  101. type: 'info',
  102. waf: this.data,
  103. })
  104. }
  105. },
  106. },
  107. {
  108. label: this.$t('table.action.delete'),
  109. permission: 'waf_rules_delete',
  110. action: obj => {
  111. this.createDialog('DeleteResDialog', {
  112. vm: this,
  113. data: [obj],
  114. columns: this.columns,
  115. title: this.$t('table.action.delete'),
  116. name: this.$t('network.waf.rule'),
  117. onManager: this.onManager,
  118. })
  119. },
  120. meta: obj => this.$getDeleteResult(obj),
  121. },
  122. ],
  123. }
  124. },
  125. computed: {
  126. columns () {
  127. if (this.data.provider === 'Cloudflare') {
  128. return [
  129. getNameDescriptionTableColumn({
  130. onManager: this.onManager,
  131. hideField: true,
  132. edit: false,
  133. showDesc: false,
  134. slotCallback: row => {
  135. return (
  136. <side-page-trigger onTrigger={() => this.handleOpenSidepage(row, '')}>{row.name}</side-page-trigger>
  137. )
  138. },
  139. }),
  140. {
  141. field: 'type',
  142. title: this.$t('network.waf.rule_type'),
  143. resizable: true,
  144. formatter: ({ row }) => {
  145. return row.type ? this.$t(`network.waf.rule_type.${row.type}`) : '-'
  146. },
  147. },
  148. {
  149. field: 'action',
  150. title: this.$t('network.waf.action'),
  151. resizable: true,
  152. formatter: ({ row }) => {
  153. const action = _.get(row, ['action', 'action'])
  154. if (action) return this.$te(`network.waf.rule_action.${action}`) ? this.$t(`network.waf.rule_action.${action}`) : '-'
  155. return '-'
  156. },
  157. },
  158. ]
  159. }
  160. return [
  161. {
  162. field: 'name',
  163. title: this.$t('network.text_21'),
  164. resizable: true,
  165. },
  166. {
  167. field: 'priority',
  168. sortable: true,
  169. title: this.$t('network.text_81'),
  170. resizable: true,
  171. },
  172. {
  173. field: 'action',
  174. title: this.$t('network.waf.action'),
  175. resizable: true,
  176. formatter: ({ row }) => {
  177. const action = _.get(row, ['action', 'action'])
  178. if (action) return this.$t(`network.waf.rule_action_${action}`)
  179. return '-'
  180. },
  181. },
  182. ]
  183. },
  184. },
  185. created () {
  186. this.list.fetchData()
  187. },
  188. methods: {
  189. handleOpenSidepage (row, tab) {
  190. this.sidePageTriggerHandle(this, 'WafRuleSidePage', {
  191. id: row.id,
  192. title: row.name,
  193. resource: 'waf_rules',
  194. apiVersion: 'v2',
  195. getParams: this.getParams,
  196. refresh: this.refresh,
  197. }, {
  198. list: this.list,
  199. tab,
  200. })
  201. this.initSidePageTab(tab)
  202. },
  203. },
  204. }
  205. </script>