|
| 1 | +<template> |
| 2 | + <div class="TraceIps"> |
| 3 | + <el-form |
| 4 | + ref="TraceIps" |
| 5 | + :rules="rules" |
| 6 | + :model="infos" |
| 7 | + :inline="true" |
| 8 | + > |
| 9 | + <div class="selectBox"> |
| 10 | + <el-form-item label="compareMode" prop="compareMode" label-width="120px"> |
| 11 | + <el-select |
| 12 | + v-model="infos.compareMode" |
| 13 | + placeholder="请选择" |
| 14 | + > |
| 15 | + <el-option |
| 16 | + v-for="item in options" |
| 17 | + :key="item.value" |
| 18 | + :label="item.label" |
| 19 | + :value="item.value" |
| 20 | + /> |
| 21 | + </el-select> |
| 22 | + </el-form-item> |
| 23 | + <el-form-item label="ips" prop="ips" label-width="120px"> |
| 24 | + <el-input v-model="infos.ips" /> |
| 25 | + </el-form-item> |
| 26 | + |
| 27 | + </div> |
| 28 | + <div class="infosBox"> |
| 29 | + <el-form-item label="infos" prop="infos" label-width="120px" style="width:100%"> |
| 30 | + <el-input v-model="infos.infos" type="textarea" readonly /> |
| 31 | + </el-form-item> |
| 32 | + |
| 33 | + </div> |
| 34 | + </el-form> |
| 35 | + </div> |
| 36 | +</template> |
| 37 | + |
| 38 | +<script> |
| 39 | +
|
| 40 | +export default { |
| 41 | + name: 'HttpHeader', |
| 42 | + props: { |
| 43 | + info: { |
| 44 | + type: String, |
| 45 | + default: '' |
| 46 | + } |
| 47 | + }, |
| 48 | + data() { |
| 49 | + const iprules = (rule, value, callback) => { |
| 50 | + if (!value) { |
| 51 | + callback(new Error('ips is required')) |
| 52 | + } else { |
| 53 | + if (!this.isValidIP(value)) { |
| 54 | + callback(new Error('Please enter the correct ip')) |
| 55 | + } else { |
| 56 | + callback() |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + return { |
| 61 | + infos: { |
| 62 | + compareMode: '', |
| 63 | + ips: '', |
| 64 | + infos: '{"compareMode":"","ips":""}' |
| 65 | + }, |
| 66 | + options: [{ |
| 67 | + value: 'CONTAINS_ANY', |
| 68 | + label: 'CONTAINS_ANY' |
| 69 | + }, { |
| 70 | + value: 'NOT_CONTAINS_ANY', |
| 71 | + label: 'NOT_CONTAINS_ANY' |
| 72 | + }], |
| 73 | + rules: { |
| 74 | + compareMode: [{ required: true, message: 'compareMode is required', trigger: 'change' }], |
| 75 | + ip: [{ required: true, validator: iprules, trigger: 'blur' }] |
| 76 | +
|
| 77 | + } |
| 78 | + } |
| 79 | + }, |
| 80 | + computed: { |
| 81 | + ips() { |
| 82 | + return this.infos.ips |
| 83 | + }, |
| 84 | + compareMode() { |
| 85 | + return this.infos.compareMode |
| 86 | + } |
| 87 | +
|
| 88 | + }, |
| 89 | + watch: { |
| 90 | + ips(a) { |
| 91 | + if (a) { |
| 92 | + this.setInfos() |
| 93 | + } |
| 94 | + }, |
| 95 | + compareMode(a) { |
| 96 | + if (a) { |
| 97 | + this.setInfos() |
| 98 | + } |
| 99 | + }, |
| 100 | + info(a) { |
| 101 | + if (a) { |
| 102 | + if (this.info) { |
| 103 | + this.infos = { ...JSON.parse(this.info) } |
| 104 | + this.infos.infos = this.info |
| 105 | + console.log(this.infos) |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +
|
| 110 | + }, |
| 111 | + created() { |
| 112 | + if (this.info) { |
| 113 | + this.infos = { ...JSON.parse(this.info) } |
| 114 | + this.infos.infos = this.info |
| 115 | + console.log(this.infos) |
| 116 | + } |
| 117 | + }, |
| 118 | + methods: { |
| 119 | + setInfos() { |
| 120 | + this.infos.infos = '{"compareMode":"' + this.infos.compareMode + ',"ips":"' + this.infos.ips + '"}' |
| 121 | + this.$emit('sendInfos', this.infos.infos) |
| 122 | + }, |
| 123 | + clear() { |
| 124 | + this.$refs.TraceIps.clearValidate() |
| 125 | + }, |
| 126 | + check() { |
| 127 | + let flag = false |
| 128 | + this.$refs.TraceIps.validate((valid) => { |
| 129 | + flag = valid |
| 130 | + }) |
| 131 | + return flag |
| 132 | + }, |
| 133 | + isValidIP(ips) { |
| 134 | + const ipList = ips.split(',') |
| 135 | + for (const ip of ipList) { |
| 136 | + const reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/ |
| 137 | + if (!reg.test(ip)) { |
| 138 | + return false |
| 139 | + } |
| 140 | + } |
| 141 | + return true |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | +</script> |
| 146 | +<style > |
| 147 | +.TraceIps .selectBox .el-form-item{ |
| 148 | + margin-right: 0; |
| 149 | +
|
| 150 | +} |
| 151 | +
|
| 152 | +.TraceIps .infosBox{ |
| 153 | + width: 100%; |
| 154 | +} |
| 155 | +.TraceIps .infosBox .el-form-item__content{ |
| 156 | + width:80%; |
| 157 | +} |
| 158 | +</style> |
0 commit comments