|
| 1 | +<!-- |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance with |
| 8 | +# the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +--> |
| 19 | + |
| 20 | +<template> |
| 21 | + <el-form> |
| 22 | + <el-form-item |
| 23 | + v-for="(item, index) in vars" |
| 24 | + :key="index" |
| 25 | + :label="'Var' + (index + 1)" |
| 26 | + class="var-item" |
| 27 | + > |
| 28 | + <el-form-item :prop="'var.' + index + '.ip'"> |
| 29 | + <el-select |
| 30 | + v-model="item.name" |
| 31 | + :placeholder="$t('schema.route.inputMultipleValues')" |
| 32 | + filterable |
| 33 | + allow-create |
| 34 | + default-first-option |
| 35 | + @change="onChange" |
| 36 | + > |
| 37 | + <el-option |
| 38 | + v-for="name in varNames" |
| 39 | + :key="name" |
| 40 | + :label="name" |
| 41 | + :value="name" |
| 42 | + /> |
| 43 | + </el-select> |
| 44 | + <el-select |
| 45 | + v-model="item.operator" |
| 46 | + placeholder="Operator" |
| 47 | + @change="onChange" |
| 48 | + > |
| 49 | + <el-option |
| 50 | + v-for="operator in varOperator" |
| 51 | + :key="operator" |
| 52 | + :label="operator" |
| 53 | + :value="operator" |
| 54 | + /> |
| 55 | + </el-select> |
| 56 | + </el-form-item> |
| 57 | + <el-form-item> |
| 58 | + <el-input |
| 59 | + v-model="item.value" |
| 60 | + placeholder="" |
| 61 | + @input="onChange" |
| 62 | + /> |
| 63 | + </el-form-item> |
| 64 | + <el-form-item> |
| 65 | + <el-button |
| 66 | + type="danger" |
| 67 | + @click.prevent="removeVar(index)" |
| 68 | + > |
| 69 | + {{ $t("button.delete") }} |
| 70 | + </el-button> |
| 71 | + </el-form-item> |
| 72 | + </el-form-item> |
| 73 | + <el-form-item> |
| 74 | + <el-button @click="addVar"> |
| 75 | + {{ $t("button.add_var") }} |
| 76 | + </el-button> |
| 77 | + </el-form-item> |
| 78 | + </el-form> |
| 79 | +</template> |
| 80 | + |
| 81 | +<script lang="ts"> |
| 82 | +import { Component, Vue, Watch, Prop } from 'vue-property-decorator' |
| 83 | +
|
| 84 | +@Component({ |
| 85 | + name: 'VarArgs' |
| 86 | +}) |
| 87 | +export default class extends Vue { |
| 88 | + @Prop({ default: () => [] }) private pVars!: any |
| 89 | + private isFullscreen = false; |
| 90 | + private get vars() { |
| 91 | + const _vars = this.pVars.map((arr:Array<any>) => { |
| 92 | + const [name, operator, value] = arr |
| 93 | + return { name, operator, value } |
| 94 | + }) |
| 95 | + return _vars |
| 96 | + } |
| 97 | + private varNames = ['remote_addr', 'host', 'uri', 'http_user_agent', 'http_referer', 'http_cookie', 'http_accept_language', 'request_uri', 'query_string', 'remote_port', 'hostname', 'arg_id']; |
| 98 | +
|
| 99 | + private varOperator = ['==', '~=', '>', '<', '~~']; |
| 100 | +
|
| 101 | + private onChange() { |
| 102 | + const val = this.vars.map((e:any) => Object.values(e)) |
| 103 | + this.$emit('update:pVars', val) |
| 104 | + } |
| 105 | +
|
| 106 | + private addVar() { |
| 107 | + (this.vars as any).push({ |
| 108 | + name: null, |
| 109 | + operator: null, |
| 110 | + value: null |
| 111 | + }) |
| 112 | + this.onChange() |
| 113 | + } |
| 114 | +
|
| 115 | + private removeVar(index:number) { |
| 116 | + this.$confirm('Do you want to remove the var?', 'Warning', { |
| 117 | + confirmButtonText: 'Confirm', |
| 118 | + cancelButtonText: 'Cancel', |
| 119 | + type: 'warning' |
| 120 | + }) |
| 121 | + .then(async() => { |
| 122 | + this.vars.splice(index, 1) |
| 123 | + this.onChange() |
| 124 | + }) |
| 125 | + .catch(() => {}) |
| 126 | + } |
| 127 | +} |
| 128 | +</script> |
0 commit comments