Vue.component("ddos-protection-ports-config-box", { props: ["v-ports"], data: function () { let ports = this.vPorts if (ports == null) { ports = [] } return { ports: ports, isAdding: false, addingPort: { port: "", description: "" } } }, methods: { add: function () { this.isAdding = true let that = this setTimeout(function () { that.$refs.addingPortInput.focus() }) }, confirm: function () { let portString = this.addingPort.port if (portString.length == 0) { this.warn("请输入端口号") return } if (!/^\d+$/.test(portString)) { this.warn("请输入正确的端口号") return } let port = parseInt(portString, 10) if (port <= 0) { this.warn("请输入正确的端口号") return } if (port > 65535) { this.warn("请输入正确的端口号") return } let exists = false this.ports.forEach(function (v) { if (v.port == port) { exists = true } }) if (exists) { this.warn("端口号已经存在") return } this.ports.push({ port: port, description: this.addingPort.description }) this.notifyChange() this.cancel() }, cancel: function () { this.isAdding = false this.addingPort = { port: "", description: "" } }, remove: function (index) { this.ports.$remove(index) this.notifyChange() }, warn: function (message) { let that = this teaweb.warn(message, function () { that.$refs.addingPortInput.focus() }) }, notifyChange: function () { this.$emit("change", this.ports) } }, template: `
{{portConfig.port}} ({{portConfig.description}})
端口
备注
 取消
` })