Vue.component("url-patterns-box", { props: ["value"], data: function () { let patterns = [] if (this.value != null) { patterns = this.value } return { patterns: patterns, isAdding: false, addingPattern: {"type": "wildcard", "pattern": ""}, editingIndex: -1 } }, methods: { add: function () { this.isAdding = true let that = this setTimeout(function () { that.$refs.patternInput.focus() }) }, edit: function (index) { this.isAdding = true this.editingIndex = index this.addingPattern = { type: this.patterns[index].type, pattern: this.patterns[index].pattern } }, confirm: function () { let pattern = this.addingPattern.pattern.trim() if (pattern.length == 0) { let that = this teaweb.warn("请输入URL", function () { that.$refs.patternInput.focus() }) return } if (this.editingIndex < 0) { this.patterns.push({ type: this.addingPattern.type, pattern: this.addingPattern.pattern }) } else { this.patterns[this.editingIndex].type = this.addingPattern.type this.patterns[this.editingIndex].pattern = this.addingPattern.pattern } this.notifyChange() this.cancel() }, remove: function (index) { this.patterns.$remove(index) this.cancel() this.notifyChange() }, cancel: function () { this.isAdding = false this.addingPattern = {"type": "wildcard", "pattern": ""} this.editingIndex = -1 }, patternTypeName: function (patternType) { switch (patternType) { case "wildcard": return "通配符" case "regexp": return "正则" } return "" }, notifyChange: function () { this.$emit("input", this.patterns) } }, template: `
[{{patternTypeName(pattern.type)}}] {{pattern.pattern}}  
` })