// 指标对象 Vue.component("metric-keys-config-box", { props: ["v-keys"], data: function () { let keys = this.vKeys if (keys == null) { keys = [] } return { keys: keys, isAdding: false, key: "", subKey: "", keyDescription: "", keyDefs: window.METRIC_HTTP_KEYS } }, watch: { keys: function () { this.$emit("change", this.keys) } }, methods: { cancel: function () { this.key = "" this.subKey = "" this.keyDescription = "" this.isAdding = false }, confirm: function () { if (this.key.length == 0) { return } if (this.key.indexOf(".NAME") > 0) { if (this.subKey.length == 0) { teaweb.warn("请输入参数值") return } this.key = this.key.replace(".NAME", "." + this.subKey) } this.keys.push(this.key) this.cancel() }, add: function () { this.isAdding = true let that = this setTimeout(function () { if (that.$refs.key != null) { that.$refs.key.focus() } }, 100) }, remove: function (index) { this.keys.$remove(index) }, changeKey: function () { if (this.key.length == 0) { return } let that = this let def = this.keyDefs.$find(function (k, v) { return v.code == that.key }) if (def != null) { this.keyDescription = def.description } }, keyName: function (key) { let that = this let subKey = "" let def = this.keyDefs.$find(function (k, v) { if (v.code == key) { return true } if (key.startsWith("${arg.") && v.code.startsWith("${arg.")) { subKey = that.getSubKey("arg.", key) return true } if (key.startsWith("${header.") && v.code.startsWith("${header.")) { subKey = that.getSubKey("header.", key) return true } if (key.startsWith("${cookie.") && v.code.startsWith("${cookie.")) { subKey = that.getSubKey("cookie.", key) return true } return false }) if (def != null) { if (subKey.length > 0) { return def.name + ": " + subKey } return def.name } return key }, getSubKey: function (prefix, key) { prefix = "${" + prefix let index = key.indexOf(prefix) if (index >= 0) { key = key.substring(index + prefix.length) key = key.substring(0, key.length - 1) return key } return "" } }, template: `
{{keyName(key)}}  

{{keyDescription}}

` })