[域名服务]实现基本的线路配置

This commit is contained in:
刘祥超
2021-05-30 16:31:12 +08:00
parent dc98081a92
commit d834c2517a
30 changed files with 778 additions and 10 deletions

View File

@@ -0,0 +1,103 @@
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",
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: `<div>
<input type="hidden" name="rangesJSON" :value="JSON.stringify(ranges)"/>
<div v-if="ranges.length > 0">
<div class="ui label tiny basic" v-for="(range, index) in ranges">
<span v-if="range.type == 'ipRange'">IP范围</span>
{{range.ipFrom}} - {{range.ipTo}} &nbsp; <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
</div>
<div class="ui divider"></div>
</div>
<!-- IP 范围 -->
<div style="margin-bottom: 1em" v-show="isAdding">
<div class="ui fields inline">
<div class="ui field">
<input type="text" placeholder="开始IP" maxlength="15" size="15" v-model="ipRangeFrom" ref="ipRangeFrom" @keyup.enter="confirmIPRange" @keypress.enter.prevent="1"/>
</div>
<div class="ui field">-</div>
<div class="ui field">
<input type="text" placeholder="结束IP" maxlength="15" size="15" v-model="ipRangeTo" ref="ipRangeTo" @keyup.enter="confirmIPRange" @keypress.enter.prevent="1"/>
</div>
<div class="ui field">
<button class="ui button tiny" type="button" @click.prevent="confirmIPRange">确定</button> &nbsp;
<a href="" @click.prevent="cancelIPRange" title="取消"><i class="icon remove small"></i></a>
</div>
</div>
</div>
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
</div>`
})

View File

@@ -0,0 +1,30 @@
// 选择单一线路
Vue.component("ns-route-selector", {
props: ["v-route-id"],
mounted: function () {
let that = this
Tea.action("/ns/routes/options")
.post()
.success(function (resp) {
that.routes = resp.data.routes
})
},
data: function () {
let routeId = this.vRouteId
if (routeId == null) {
routeId = 0
}
return {
routeId: routeId,
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>
</div>
</div>`
})

View File

@@ -0,0 +1,84 @@
// 选择多个线路
Vue.component("ns-routes-selector", {
props: ["v-route-ids"],
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))
})
})
},
data: function () {
return {
routeId: 0,
allRoutes: [],
routes: [],
isAdding: false
}
}
,
methods: {
add: function () {
this.isAdding = true
this.routes = this.allRoutes.$findAll(function (k, v) {
return !v.isChecked
})
this.routeId = 0
},
cancel: function () {
this.isAdding = false
},
confirm: function () {
if (this.routeId == 0) {
return
}
let that = this
this.routes.forEach(function (v) {
if (v.id == that.routeId) {
v.isChecked = true
}
})
this.cancel()
},
remove: function (index) {
this.allRoutes[index].isChecked = false
Vue.set(this.allRoutes, index, this.allRoutes[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"/>
{{route.name}} &nbsp; <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
</div>
<div class="ui divider"></div>
</div>
<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>
</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>
</div>
</div>
</div>
<button class="ui button tiny" type="button" @click.prevent="add">+</button>
</div>`
})

View File

@@ -37,6 +37,12 @@
</select>
</td>
</tr>
<tr>
<td>线路</td>
<td>
<ns-routes-selector></ns-routes-selector>
</td>
</tr>
<tr>
<td>备注</td>
<td>

View File

@@ -5,6 +5,27 @@
<menu-item @click.prevent="createRecord">[创建记录]</menu-item>
</second-menu>
<form class="ui form" method="get" action="/ns/domains/records">
<input type="hidden" name="domainId" :value="domain.id"/>
<div class="ui fields inline">
<div class="ui field">
<select class="ui dropdown" name="type" v-model="type">
<option value="">[记录类型]</option>
<option v-for="t in types" :value="t.type">{{t.type}}</option>
</select>
</div>
<div class="ui field">
<ns-route-selector :v-route-id="routeId"></ns-route-selector>
</div>
<div class="ui field">
<input type="text" placeholder="记录名、备注..." name="keyword" v-model="keyword"/>
</div>
<div class="ui field">
<button type="submit" class="ui button">搜索</button>
</div>
</div>
</form>
<p class="comment" v-if="records.length == 0">暂时还没有记录。</p>
<table class="ui table selectable celled" v-if="records.length > 0">
<thead>
@@ -24,7 +45,9 @@
<td>{{record.value}}</td>
<td>{{formatTTL(record.ttl)}}</td>
<td>
<span class="ui label basic text tiny" v-for="route in record.routes">{{route.name}}</span>
<div v-for="route in record.routes" style="margin-top: 0.3em; margin-bottom: 0.3em">
<span class="ui label basic text tiny">{{route.name}}</span>
</div>
</td>
<td>{{record.description}}</td>
<td>

View File

@@ -1,6 +1,6 @@
{$layout "layout_popup"}
<h3>创建记录</h3>
<h3>修改记录</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="recordId" :value="record.id"/>
@@ -37,6 +37,12 @@
</select>
</td>
</tr>
<tr>
<td>线路</td>
<td>
<ns-routes-selector :v-route-ids="record.routeIds"></ns-routes-selector>
</td>
</tr>
<tr>
<td>备注</td>
<td>

View File

@@ -0,0 +1,4 @@
<first-menu>
<menu-item href="" @click.prevent="createRoute()">[创建线路]</menu-item>
</first-menu>
<div class="margin"></div>

View File

@@ -0,0 +1,26 @@
{$layout "layout_popup"}
<h3>创建线路</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="clusterId" :value="clusterId"/>
<input type="hidden" name="domainId" :value="domainId"/>
<input type="hidden" name="userId" :value="userId"/>
<table class="ui table definition selectable">
<tr>
<td class="title">线路名称 *</td>
<td>
<input type="text" name="name" maxlength="100" ref="focus"/>
</td>
</tr>
<tr>
<td>IP范围</td>
<td>
<ns-route-ranges-box></ns-route-ranges-box>
</td>
</tr>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -0,0 +1,34 @@
{$layout}
{$template "menu"}
<div v-if="routes.length == 0">
<p class="comment">暂时还没有线路。</p>
</div>
<div v-show="routes.length > 0">
<table class="ui table selectable celled" id="sortable-table">
<thead>
<tr>
<th style="width: 3em"></th>
<th>线路名称</th>
<th class="two wide">状态</th>
<th class="two op">操作</th>
</tr>
</thead>
<tbody v-for="route in routes" :v-id="route.id">
<tr>
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
<td>{{route.name}}</td>
<td>
<label-on :v-is-on="route.isOn"></label-on>
</td>
<td>
<a href="" @click.prevent="updateRoute(route.id)">修改</a> &nbsp;
<a href="" @click.prevent="deleteRoute(route.id)">删除</a>
</td>
</tr>
</tbody>
</table>
<p class="comment" v-if="routes.length > 0">可以拖动左侧的<i class="icon bars"></i>排序。</p>
</div>

View File

@@ -0,0 +1,49 @@
Tea.context(function () {
this.$delay(function () {
let that = this
sortTable(function (ids) {
that.$post(".sort")
.params({
routeIds: ids
})
.success(function () {
teaweb.successToast("排序保存成功")
})
})
})
this.createRoute = function () {
teaweb.popup("/ns/routes/createPopup", {
width: "42em",
callback: function () {
teaweb.success("保存成功", function () {
teaweb.reload()
})
}
})
}
this.updateRoute = function (routeId) {
teaweb.popup("/ns/routes/updatePopup?routeId=" + routeId, {
width: "42em",
callback: function () {
teaweb.success("保存成功", function () {
teaweb.reload()
})
}
})
}
this.deleteRoute = function (routeId) {
let that = this
teaweb.confirm("确定要删除此线路吗?", function () {
that.$post(".delete")
.params({
routeId: routeId
})
.success(function () {
teaweb.reload()
})
})
}
})

View File

@@ -0,0 +1,34 @@
{$layout "layout_popup"}
<h3>修改线路</h3>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token>
<input type="hidden" name="routeId" :value="route.id"/>
<table class="ui table definition selectable">
<tr>
<td class="title">线路名称 *</td>
<td>
<input type="text" name="name" maxlength="100" ref="focus" v-model="route.name"/>
</td>
</tr>
<tr>
<td>IP范围</td>
<td>
<ns-route-ranges-box :v-ranges="route.ranges"></ns-route-ranges-box>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>是否启用</td>
<td>
<checkbox name="isOn" value="1" v-model="route.isOn"></checkbox>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>