Vue.component("dns-route-selector", { props: ["v-all-routes", "v-routes"], data: function () { let routes = this.vRoutes if (routes == null) { routes = [] } return { routes: routes, routeCodes: routes.$map(function (k, v) { return v.code }), isAdding: false, routeCode: "" } }, methods: { add: function () { this.isAdding = true }, cancel: function () { this.isAdding = false }, confirm: function () { if (this.routeCode.length == 0) { return } if (this.routeCodes.$contains(this.routeCode)) { teaweb.warn("已经添加过此线路,不能重复添加") return } let that = this let route = this.vAllRoutes.$find(function (k, v) { return v.code == that.routeCode }) if (route == null) { return } this.routeCodes.push(this.routeCode) this.routes.push(route) this.routeCode = "" this.isAdding = false }, remove: function (route) { this.routeCodes.$removeValue(route.code) this.routes.$removeIf(function (k, v) { return v.code == route.code }) } }, template: `
` })