Vue.component("ns-route-ranges-box", { props: ["v-ranges"], data: function () { let ranges = this.vRanges if (ranges == null) { ranges = [] } return { ranges: ranges, isAdding: false, // IP范围 ipRangeFrom: "", ipRangeTo: "" } }, methods: { add: function () { this.isAdding = true let that = this setTimeout(function () { that.$refs.ipRangeFrom.focus() }, 100) }, remove: function (index) { this.ranges.$remove(index) }, cancelIPRange: function () { this.isAdding = false this.ipRangeFrom = "" this.ipRangeTo = "" }, confirmIPRange: function () { // 校验IP let that = this this.ipRangeFrom = this.ipRangeFrom.trim() if (!this.validateIP(this.ipRangeFrom)) { teaweb.warn("开始IP填写错误", function () { that.$refs.ipRangeFrom.focus() }) return } this.ipRangeTo = this.ipRangeTo.trim() if (!this.validateIP(this.ipRangeTo)) { teaweb.warn("结束IP填写错误", function () { that.$refs.ipRangeTo.focus() }) return } this.ranges.push({ type: "ipRange", params: { ipFrom: this.ipRangeFrom, ipTo: this.ipRangeTo } }) this.cancelIPRange() }, validateIP: function (ip) { if (!ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) { return false } let pieces = ip.split(".") let isOk = true pieces.forEach(function (v) { let v1 = parseInt(v) if (v1 > 255) { isOk = false } }) return isOk } }, template: `
IP范围: {{range.params.ipFrom}} - {{range.params.ipTo}}  
-
 
` })