Vue.component("ddos-protection-ip-list-config-box", { props: ["v-ip-list"], data: function () { let list = this.vIpList if (list == null) { list = [] } return { list: list, isAdding: false, addingIP: { ip: "", description: "" } } }, methods: { add: function () { this.isAdding = true let that = this setTimeout(function () { that.$refs.addingIPInput.focus() }) }, confirm: function () { let ip = this.addingIP.ip if (ip.length == 0) { this.warn("请输入IP") return } let exists = false this.list.forEach(function (v) { if (v.ip == ip) { exists = true } }) if (exists) { this.warn("IP '" + ip + "'已经存在") return } let that = this Tea.Vue.$post("/ui/validateIPs") .params({ ips: [ip] }) .success(function () { that.list.push({ ip: ip, description: that.addingIP.description }) that.notifyChange() that.cancel() }) .fail(function () { that.warn("请输入正确的IP") }) }, cancel: function () { this.isAdding = false this.addingIP = { ip: "", description: "" } }, remove: function (index) { this.list.$remove(index) this.notifyChange() }, warn: function (message) { let that = this teaweb.warn(message, function () { that.$refs.addingIPInput.focus() }) }, notifyChange: function () { this.$emit("change", this.list) } }, template: `
` })