diff --git a/web/public/js/components/ns/ns-route-ranges-box.js b/web/public/js/components/ns/ns-route-ranges-box.js index 605486e7..f5fdd64c 100644 --- a/web/public/js/components/ns/ns-route-ranges-box.js +++ b/web/public/js/components/ns/ns-route-ranges-box.js @@ -8,10 +8,13 @@ Vue.component("ns-route-ranges-box", { return { ranges: ranges, isAdding: false, + isAddingBatch: false, // IP范围 ipRangeFrom: "", - ipRangeTo: "" + ipRangeTo: "", + + batchIPRange: "" } }, methods: { @@ -58,6 +61,65 @@ Vue.component("ns-route-ranges-box", { }) this.cancelIPRange() }, + addBatch: function () { + this.isAddingBatch = true + let that = this + setTimeout(function () { + that.$refs.batchIPRange.focus() + }, 100) + }, + cancelBatchIPRange: function () { + this.isAddingBatch = false + this.batchIPRange = "" + }, + confirmBatchIPRange: function () { + let that = this + let rangesText = this.batchIPRange + if (rangesText.length == 0) { + teaweb.warn("请填写要加入的IP范围", function () { + that.$refs.batchIPRange.focus() + }) + return + } + + let validRanges = [] + let invalidLine = "" + rangesText.split("\n").forEach(function (line) { + line = line.trim() + if (line.length == 0) { + return + } + line = line.replace(",", ",") + let pieces = line.split(",") + if (pieces.length != 2) { + invalidLine = line + return + } + let ipFrom = pieces[0].trim() + let ipTo = pieces[1].trim() + if (!that.validateIP(ipFrom) || !that.validateIP(ipTo)) { + invalidLine = line + return + } + validRanges.push({ + type: "ipRange", + params: { + ipFrom: ipFrom, + ipTo: ipTo + } + }) + }) + if (invalidLine.length > 0) { + teaweb.warn("'" + invalidLine + "'格式错误", function () { + that.$refs.batchIPRange.focus() + }) + return + } + validRanges.forEach(function (v) { + that.ranges.push(v) + }) + this.cancelBatchIPRange() + }, validateIP: function (ip) { if (!ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) { return false @@ -76,14 +138,14 @@ Vue.component("ns-route-ranges-box", { template: `