EdgeDNS支持内置线路

This commit is contained in:
刘祥超
2021-08-09 13:56:11 +08:00
parent a256a7328e
commit 69c1d35406
10 changed files with 138 additions and 81 deletions

View File

@@ -1,6 +1,6 @@
// 选择单一线路
Vue.component("ns-route-selector", {
props: ["v-route-id"],
props: ["v-route-code"],
mounted: function () {
let that = this
Tea.action("/ns/routes/options")
@@ -10,20 +10,20 @@ Vue.component("ns-route-selector", {
})
},
data: function () {
let routeId = this.vRouteId
if (routeId == null) {
routeId = 0
let routeCode = this.vRouteCode
if (routeCode == null) {
routeCode = ""
}
return {
routeId: routeId,
routeCode: routeCode,
routes: []
}
},
template: `<div>
<div v-if="routes.length > 0">
<select class="ui dropdown" name="routeId" v-model="routeId">
<option value="0">[线路]</option>
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
<select class="ui dropdown" name="routeCode" v-model="routeCode">
<option value="">[线路]</option>
<option v-for="route in routes" :value="route.code">{{route.name}}</option>
</select>
</div>
</div>`

View File

@@ -1,66 +1,70 @@
// 选择多个线路
Vue.component("ns-routes-selector", {
props: ["v-route-ids"],
props: ["v-routes"],
mounted: function () {
let that = this
let routeIds = this.vRouteIds
if (routeIds == null) {
routeIds = []
}
Tea.action("/ns/routes/options")
.post()
.success(function (resp) {
that.allRoutes = resp.data.routes
that.allRoutes.forEach(function (v) {
v.isChecked = (routeIds.$contains(v.id))
})
that.routes = resp.data.routes
})
},
data: function () {
return {
routeId: 0,
allRoutes: [],
routes: [],
isAdding: false
let selectedRoutes = this.vRoutes
if (selectedRoutes == null) {
selectedRoutes = []
}
}
,
return {
routeCode: "default",
routes: [],
isAdding: false,
routeType: "default",
selectedRoutes: selectedRoutes
}
},
watch: {
routeType: function (v) {
this.routeCode = ""
let that = this
this.routes.forEach(function (route) {
if (route.type == v && that.routeCode.length == 0) {
that.routeCode = route.code
}
})
}
},
methods: {
add: function () {
this.isAdding = true
this.routes = this.allRoutes.$findAll(function (k, v) {
return !v.isChecked
})
this.routeId = 0
this.routeType = "default"
this.routeCode = "default"
},
cancel: function () {
this.isAdding = false
},
confirm: function () {
if (this.routeId == 0) {
if (this.routeCode.length == 0) {
return
}
let that = this
this.routes.forEach(function (v) {
if (v.id == that.routeId) {
v.isChecked = true
if (v.code == that.routeCode) {
that.selectedRoutes.push(v)
}
})
this.cancel()
},
remove: function (index) {
this.allRoutes[index].isChecked = false
Vue.set(this.allRoutes, index, this.allRoutes[index])
this.selectedRoutes.$remove(index)
}
}
,
template: `<div>
<div>
<div class="ui label basic text small" v-for="(route, index) in allRoutes" v-if="route.isChecked">
<input type="hidden" name="routeIds" :value="route.id"/>
<div class="ui label basic text small" v-for="(route, index) in selectedRoutes" style="margin-bottom: 0.3em">
<input type="hidden" name="routeCodes" :value="route.code"/>
{{route.name}} &nbsp; <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
</div>
<div class="ui divider"></div>
@@ -68,11 +72,21 @@ Vue.component("ns-routes-selector", {
<div v-if="isAdding" style="margin-bottom: 1em">
<div class="ui fields inline">
<div class="ui field">
<select class="ui dropdown" name="routeId" v-model="routeId">
<option value="0">[线路]</option>
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
<select class="ui dropdown" v-model="routeType">
<option value="default">[默认线路]</option>
<option value="user">自定义线路</option>
<option value="isp">运营商</option>
<option value="china">中国省市</option>
<option value="world">全球国家地区</option>
</select>
</div>
<div class="ui field">
<select class="ui dropdown" v-model="routeCode" style="width: 10em">
<option v-for="route in routes" :value="route.code" v-if="route.type == routeType">{{route.name}}</option>
</select>
</div>
<div class="ui field">
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
&nbsp; <a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>

View File

@@ -15,7 +15,7 @@
</select>
</div>
<div class="ui field">
<ns-route-selector :v-route-id="routeId"></ns-route-selector>
<ns-route-selector :v-route-code="routeCode"></ns-route-selector>
</div>
<div class="ui field">
<input type="text" placeholder="记录名、备注..." name="keyword" v-model="keyword"/>

View File

@@ -1,7 +1,7 @@
Tea.context(function () {
this.createRecord = function () {
teaweb.popup("/ns/domains/records/createPopup?domainId=" + this.domain.id, {
height: "32em",
height: "33em",
callback: function () {
teaweb.success("保存成功", function () {
teaweb.reload()
@@ -12,7 +12,7 @@ Tea.context(function () {
this.updateRecord = function (recordId) {
teaweb.popup("/ns/domains/records/updatePopup?recordId=" + recordId, {
height: "32em",
height: "33em",
callback: function () {
teaweb.success("保存成功", function () {
teaweb.reload()

View File

@@ -40,7 +40,7 @@
<tr>
<td>线路</td>
<td>
<ns-routes-selector :v-route-ids="record.routeIds"></ns-routes-selector>
<ns-routes-selector :v-routes="record.routes"></ns-routes-selector>
</td>
</tr>
<tr>

View File

@@ -11,6 +11,7 @@
<tr>
<th style="width: 3em"></th>
<th>线路名称</th>
<th>代号</th>
<th class="two wide">状态</th>
<th class="two op">操作</th>
</tr>
@@ -19,6 +20,7 @@
<tr>
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
<td>{{route.name}}</td>
<td>id:{{route.id}}</td>
<td>
<label-on :v-is-on="route.isOn"></label-on>
</td>