diff --git a/web/public/js/components/common/url-patterns-box.js b/web/public/js/components/common/url-patterns-box.js new file mode 100644 index 00000000..0efb8142 --- /dev/null +++ b/web/public/js/components/common/url-patterns-box.js @@ -0,0 +1,104 @@ +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: `
如果填写了例外URL,表示这些URL跳过5秒盾不做处理。
+如果填写了支持URL,表示只对这些URL进行5秒盾处理;如果不填则表示支持所有的URL。
+