MatchFieldValues.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div>
  3. <a-form-item :label="label || $t('network_waf_statement.label.match_field_values')" v-bind="formLayout">
  4. <template v-for="(matchFieldValue, index) in matchFieldValues">
  5. <a-select v-if="addType === 'select' && isEdit" v-model="matchFieldValues[index]" :key="index">
  6. <a-select-option v-for="item in options" :value="item.value" :key="item.value">
  7. {{item.label}}
  8. </a-select-option>
  9. </a-select>
  10. <a-input v-else-if="addType === 'input' && isEdit" :value="matchFieldValues[index]" :key="index" />
  11. <box-show v-else :value="getShowValue(index)" :key="index" />
  12. </template>
  13. </a-form-item>
  14. </div>
  15. </template>
  16. <script>
  17. import WafMixin from '../../mixins/waf'
  18. import BoxShow from './BoxShow'
  19. import WindowsMixin from '@/mixins/windows'
  20. export default {
  21. name: 'MatchFieldValuesStatement',
  22. components: {
  23. BoxShow,
  24. },
  25. mixins: [WindowsMixin, WafMixin],
  26. props: {
  27. isEdit: Boolean,
  28. type: String,
  29. label: {
  30. type: String,
  31. },
  32. addType: {
  33. type: String,
  34. default: () => 'input', // input select
  35. },
  36. selectOptions: {
  37. type: Array,
  38. default: () => [],
  39. },
  40. valueList: {
  41. type: Array,
  42. default: () => [],
  43. },
  44. },
  45. data () {
  46. return {
  47. matchFieldValues: this.valueList || [''],
  48. formLayout: {
  49. wrapperCol: {
  50. span: 20,
  51. },
  52. labelCol: {
  53. span: 4,
  54. },
  55. },
  56. }
  57. },
  58. computed: {
  59. options () {
  60. // 根据不同type返回
  61. return this.selectOptions
  62. },
  63. },
  64. watch: {
  65. valueList: {
  66. handler: function (val) {
  67. this.matchFieldValues = val
  68. },
  69. deep: true,
  70. },
  71. },
  72. created () {
  73. },
  74. methods: {
  75. getShowValue (index) {
  76. if (this.addType === 'select') {
  77. const matchFieldValues = this.selectOptions.filter(item => item.value === this.valueList[index])
  78. if (matchFieldValues && matchFieldValues.length) {
  79. return matchFieldValues[0].label
  80. } else {
  81. return ''
  82. }
  83. }
  84. return this.matchFieldValues[index] || ''
  85. },
  86. },
  87. }
  88. </script>