WafRuleInfo.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <base-dialog :width="1000" @cancel="cancelDialog">
  3. <div slot="header">{{title}}</div>
  4. <div slot="body">
  5. <a-form-model
  6. v-bind="formLayout"
  7. ref="ruleInfoForm"
  8. :model="ruleInfoForm"
  9. :rules="rules"
  10. :hideRequiredMark="true">
  11. <!-- 名称 -->
  12. <a-form-model-item :label="$t('network.waf.rule_name')" prop="name">
  13. <a-input v-if="params.isEdit" v-model="ruleInfoForm.name" :placeholder="$t('network.waf.rule_name_placeholder')" />
  14. <box-show v-else :value="ruleInfoForm.name" />
  15. </a-form-model-item>
  16. <!-- 优先级 -->
  17. <a-form-model-item :label="$t('network.text_81')" prop="priority">
  18. <a-input v-if="params.isEdit" v-model="ruleInfoForm.priority" :placeholder="$t('network.waf.rule_priority_placeholder')" />
  19. <box-show v-else :value="ruleInfoForm.priority" />
  20. </a-form-model-item>
  21. <!-- 匹配规则 -->
  22. <a-form-model-item :label="$t('network.waf.rule_match')" prop="statement_conditon">
  23. <a-select v-if="params.isEdit" v-model="ruleInfoForm.statement_conditon" :placeholder="$t('network.waf.rule_match_validator')">
  24. <a-select-option v-for="item in statementConditionOptions" :value="item.value" :key="item.value">
  25. {{item.label}}
  26. </a-select-option>
  27. </a-select>
  28. <box-show v-else :value="ruleStatementCondition" />
  29. </a-form-model-item>
  30. <!-- 条件 -->
  31. <template v-if="ruleInfoForm.statements.length">
  32. <a-form-model-item v-for="(statement,index) in ruleInfoForm.statements" :key="index"
  33. v-bind="index === 0 ? formLayout : formLayoutWithOutLabel"
  34. :label="index === 0 ? $t('network.waf.rule_condition') : ''">
  35. <div class="d-flex align-items-center">
  36. <waf-rule-statement :data="statement" :type="statement.type" :wafBrand="ruleInfoData.brand" :isEdit="params.isEdit" />
  37. <!-- <a-button style="flex: 0 0 24px;margin-left: 20px" shape="circle" icon="minus" size="small" @click="deleteRule(item,index)" /> -->
  38. </div>
  39. </a-form-model-item>
  40. </template>
  41. <!-- <div class="d-flex align-items-center">
  42. <a-button type="primary" shape="circle" icon="plus" size="small" @click="addRule" />
  43. <a-button type="link" @click="addRule">{{$t('network.waf.rule_add')}}</a-button>
  44. </div> -->
  45. <!-- 处理动作 -->
  46. <a-form-model-item :label="$t('network.waf.action')" prop="action">
  47. <a-select v-if="params.isEdit" v-model="ruleInfoForm.action">
  48. <a-select-option v-for="item in wafRuleActionOptions" :value="item.value" :key="item.value">
  49. {{item.label}}
  50. </a-select-option>
  51. </a-select>
  52. <box-show v-else :value="ruleAction" />
  53. </a-form-model-item>
  54. </a-form-model>
  55. </div>
  56. <div slot="footer">
  57. <!-- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button> -->
  58. <a-button @click="cancelDialog">{{ $t('network.text_33') }}</a-button>
  59. </div>
  60. </base-dialog>
  61. </template>
  62. <script>
  63. import { mapGetters } from 'vuex'
  64. import DialogMixin from '@/mixins/dialog'
  65. import WindowsMixin from '@/mixins/windows'
  66. import WafMixin from '../mixins/waf'
  67. import BoxShow from '../components/statementComponents/BoxShow'
  68. import WafRuleStatement from '../components/WafRuleStatement'
  69. export default {
  70. name: 'WafRuleInfoDialog',
  71. components: {
  72. WafRuleStatement,
  73. BoxShow,
  74. },
  75. mixins: [DialogMixin, WindowsMixin, WafMixin],
  76. props: {
  77. parmas: Object,
  78. },
  79. data () {
  80. const initTitle = this.params.title || this.$t('network.waf.rule_view')
  81. return {
  82. loading: false,
  83. title: initTitle,
  84. form: {
  85. fc: this.$form.createForm(this, {
  86. onValuesChange: (props, values) => {
  87. Object.keys(values).forEach((key) => {
  88. this.form.fd[key] = values[key]
  89. })
  90. },
  91. }),
  92. fd: {
  93. applicationScope: 1,
  94. },
  95. },
  96. ruleInfoForm: {
  97. name: '',
  98. priority: 0,
  99. statement_conditon: '',
  100. action: '',
  101. statements: [],
  102. },
  103. ruleInfoData: {},
  104. rules: {
  105. name: { required: true, message: this.$t('cloudenv.text_190') },
  106. priority: { required: true, validator: this.$validate('nonNegativeInt') },
  107. statement_conditon: { message: this.$t('network.waf.rule_match_validator') },
  108. action: { required: true, message: this.$t('network.waf.rule_action_validator') },
  109. },
  110. formLayout: {
  111. wrapperCol: {
  112. span: 20,
  113. },
  114. labelCol: {
  115. span: 4,
  116. },
  117. },
  118. formLayoutWithOutLabel: {
  119. wrapperCol: {
  120. span: 20,
  121. offset: 4,
  122. },
  123. },
  124. }
  125. },
  126. computed: {
  127. ...mapGetters(['isAdminMode', 'isDomainMode', 'userInfo', 'l3PermissionEnable']),
  128. ruleStatementCondition () {
  129. const statementCondition = this.statementConditionOptions.filter(item => item.value === this.ruleInfoForm.statement_conditon)
  130. if (statementCondition && statementCondition.length) {
  131. return statementCondition[0].label
  132. } else {
  133. return this.ruleInfoForm.statement_conditon
  134. }
  135. },
  136. ruleAction () {
  137. const action = this.wafRuleActionOptions.filter(item => item.value === this.ruleInfoForm.action)
  138. if (action && action.length) {
  139. return action[0].label
  140. } else {
  141. return this.ruleInfoForm.action || this.$t('network.waf.match_null')
  142. }
  143. },
  144. },
  145. created () {
  146. this.$r = new this.$Manager('waf_rules', 'v2')
  147. this.fetchRuleInfo()
  148. },
  149. methods: {
  150. async fetchRuleInfo () {
  151. const { data = [] } = this.params
  152. const id = data[0]?.id
  153. if (id) {
  154. try {
  155. const { data: ruleInfo = {} } = await this.$r.get({ id })
  156. this.ruleInfoForm.name = ruleInfo.name || ''
  157. this.ruleInfoForm.priority = ruleInfo.priority || 0
  158. this.ruleInfoForm.statement_conditon = ruleInfo.statement_conditon || ''
  159. this.ruleInfoForm.action = ruleInfo.action?.action ?? ''
  160. this.ruleInfoForm.statements = ruleInfo.statements || []
  161. // 是否每条数据都有brand来区分是哪个平台的waf规则
  162. this.ruleInfoData = Object.assign({}, { brand: 'Azure' }, ruleInfo)
  163. } catch (err) { throw err }
  164. }
  165. },
  166. },
  167. }
  168. </script>