mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-18 23:10:25 +08:00
EdgeDNS支持内置线路
This commit is contained in:
@@ -54,7 +54,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
Value string
|
Value string
|
||||||
Ttl int32
|
Ttl int32
|
||||||
Description string
|
Description string
|
||||||
RouteIds []int64
|
RouteCodes []string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
@@ -76,13 +76,13 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createResp, err := this.RPC().NSRecordRPC().CreateNSRecord(this.AdminContext(), &pb.CreateNSRecordRequest{
|
createResp, err := this.RPC().NSRecordRPC().CreateNSRecord(this.AdminContext(), &pb.CreateNSRecordRequest{
|
||||||
NsDomainId: params.DomainId,
|
NsDomainId: params.DomainId,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
Value: params.Value,
|
Value: params.Value,
|
||||||
Ttl: params.Ttl,
|
Ttl: params.Ttl,
|
||||||
NsRouteIds: params.RouteIds,
|
NsRouteCodes: params.RouteCodes,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
DomainId int64
|
DomainId int64
|
||||||
Type string
|
Type string
|
||||||
Keyword string
|
Keyword string
|
||||||
RouteId int64
|
RouteCode string
|
||||||
}) {
|
}) {
|
||||||
// 初始化域名信息
|
// 初始化域名信息
|
||||||
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
err := domainutils.InitDomain(this.Parent(), params.DomainId)
|
||||||
@@ -33,14 +33,14 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
|
|
||||||
this.Data["type"] = params.Type
|
this.Data["type"] = params.Type
|
||||||
this.Data["keyword"] = params.Keyword
|
this.Data["keyword"] = params.Keyword
|
||||||
this.Data["routeId"] = params.RouteId
|
this.Data["routeCode"] = params.RouteCode
|
||||||
|
|
||||||
// 记录
|
// 记录
|
||||||
countResp, err := this.RPC().NSRecordRPC().CountAllEnabledNSRecords(this.AdminContext(), &pb.CountAllEnabledNSRecordsRequest{
|
countResp, err := this.RPC().NSRecordRPC().CountAllEnabledNSRecords(this.AdminContext(), &pb.CountAllEnabledNSRecordsRequest{
|
||||||
NsDomainId: params.DomainId,
|
NsDomainId: params.DomainId,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
NsRouteId: params.RouteId,
|
NsRouteCode: params.RouteCode,
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -51,12 +51,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
recordsResp, err := this.RPC().NSRecordRPC().ListEnabledNSRecords(this.AdminContext(), &pb.ListEnabledNSRecordsRequest{
|
recordsResp, err := this.RPC().NSRecordRPC().ListEnabledNSRecords(this.AdminContext(), &pb.ListEnabledNSRecordsRequest{
|
||||||
NsDomainId: params.DomainId,
|
NsDomainId: params.DomainId,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
NsRouteId: params.RouteId,
|
NsRouteCode: params.RouteCode,
|
||||||
Keyword: params.Keyword,
|
Keyword: params.Keyword,
|
||||||
Offset: page.Offset,
|
Offset: page.Offset,
|
||||||
Size: page.Size,
|
Size: page.Size,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
routeIds := []int64{}
|
|
||||||
for _, route := range record.NsRoutes {
|
|
||||||
routeIds = append(routeIds, route.Id)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.Data["record"] = maps.Map{
|
this.Data["record"] = maps.Map{
|
||||||
"id": record.Id,
|
"id": record.Id,
|
||||||
"name": record.Name,
|
"name": record.Name,
|
||||||
@@ -47,7 +42,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
|||||||
"weight": record.Weight,
|
"weight": record.Weight,
|
||||||
"description": record.Description,
|
"description": record.Description,
|
||||||
"isOn": record.IsOn,
|
"isOn": record.IsOn,
|
||||||
"routeIds": routeIds,
|
"routes": record.NsRoutes,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 域名信息
|
// 域名信息
|
||||||
@@ -83,7 +78,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Ttl int32
|
Ttl int32
|
||||||
Description string
|
Description string
|
||||||
IsOn bool
|
IsOn bool
|
||||||
RouteIds []int64
|
RouteCodes []string
|
||||||
|
|
||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
@@ -102,14 +97,14 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := this.RPC().NSRecordRPC().UpdateNSRecord(this.AdminContext(), &pb.UpdateNSRecordRequest{
|
_, err := this.RPC().NSRecordRPC().UpdateNSRecord(this.AdminContext(), &pb.UpdateNSRecordRequest{
|
||||||
NsRecordId: params.RecordId,
|
NsRecordId: params.RecordId,
|
||||||
Description: params.Description,
|
Description: params.Description,
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
Type: params.Type,
|
Type: params.Type,
|
||||||
Value: params.Value,
|
Value: params.Value,
|
||||||
Ttl: params.Ttl,
|
Ttl: params.Ttl,
|
||||||
IsOn: params.IsOn,
|
IsOn: params.IsOn,
|
||||||
NsRouteIds: params.RouteIds,
|
NsRouteCodes: params.RouteCodes,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ package clusters
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OptionsAction struct {
|
type OptionsAction struct {
|
||||||
@@ -17,6 +19,18 @@ func (this *OptionsAction) RunPost(params struct {
|
|||||||
DomainId int64
|
DomainId int64
|
||||||
UserId int64
|
UserId int64
|
||||||
}) {
|
}) {
|
||||||
|
var routeMaps = []maps.Map{}
|
||||||
|
|
||||||
|
// 默认线路
|
||||||
|
for _, route := range dnsconfigs.AllDefaultRoutes {
|
||||||
|
routeMaps = append(routeMaps, maps.Map{
|
||||||
|
"name": route.Name,
|
||||||
|
"code": route.Code,
|
||||||
|
"type": "default",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义
|
||||||
routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{
|
routesResp, err := this.RPC().NSRouteRPC().FindAllEnabledNSRoutes(this.AdminContext(), &pb.FindAllEnabledNSRoutesRequest{
|
||||||
NsClusterId: params.ClusterId,
|
NsClusterId: params.ClusterId,
|
||||||
NsDomainId: params.DomainId,
|
NsDomainId: params.DomainId,
|
||||||
@@ -27,13 +41,45 @@ func (this *OptionsAction) RunPost(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
routeMaps := []maps.Map{}
|
|
||||||
for _, route := range routesResp.NsRoutes {
|
for _, route := range routesResp.NsRoutes {
|
||||||
|
if len(route.Code) == 0 {
|
||||||
|
route.Code = "id:" + types.String(route.Id)
|
||||||
|
}
|
||||||
|
|
||||||
routeMaps = append(routeMaps, maps.Map{
|
routeMaps = append(routeMaps, maps.Map{
|
||||||
"id": route.Id,
|
|
||||||
"name": route.Name,
|
"name": route.Name,
|
||||||
|
"code": route.Code,
|
||||||
|
"type": "user",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 运营商
|
||||||
|
for _, route := range dnsconfigs.AllDefaultISPRoutes {
|
||||||
|
routeMaps = append(routeMaps, maps.Map{
|
||||||
|
"name": route.Name,
|
||||||
|
"code": route.Code,
|
||||||
|
"type": "isp",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 中国
|
||||||
|
for _, route := range dnsconfigs.AllDefaultChinaProvinceRoutes {
|
||||||
|
routeMaps = append(routeMaps, maps.Map{
|
||||||
|
"name": route.Name,
|
||||||
|
"code": route.Code,
|
||||||
|
"type": "china",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 全球
|
||||||
|
for _, route := range dnsconfigs.AllDefaultWorldRegionRoutes {
|
||||||
|
routeMaps = append(routeMaps, maps.Map{
|
||||||
|
"name": route.Name,
|
||||||
|
"code": route.Code,
|
||||||
|
"type": "world",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["routes"] = routeMaps
|
this.Data["routes"] = routeMaps
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// 选择单一线路
|
// 选择单一线路
|
||||||
Vue.component("ns-route-selector", {
|
Vue.component("ns-route-selector", {
|
||||||
props: ["v-route-id"],
|
props: ["v-route-code"],
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
let that = this
|
let that = this
|
||||||
Tea.action("/ns/routes/options")
|
Tea.action("/ns/routes/options")
|
||||||
@@ -10,20 +10,20 @@ Vue.component("ns-route-selector", {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
let routeId = this.vRouteId
|
let routeCode = this.vRouteCode
|
||||||
if (routeId == null) {
|
if (routeCode == null) {
|
||||||
routeId = 0
|
routeCode = ""
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
routeId: routeId,
|
routeCode: routeCode,
|
||||||
routes: []
|
routes: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
template: `<div>
|
template: `<div>
|
||||||
<div v-if="routes.length > 0">
|
<div v-if="routes.length > 0">
|
||||||
<select class="ui dropdown" name="routeId" v-model="routeId">
|
<select class="ui dropdown" name="routeCode" v-model="routeCode">
|
||||||
<option value="0">[线路]</option>
|
<option value="">[线路]</option>
|
||||||
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
|
<option v-for="route in routes" :value="route.code">{{route.name}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
|
|||||||
@@ -1,66 +1,70 @@
|
|||||||
// 选择多个线路
|
// 选择多个线路
|
||||||
Vue.component("ns-routes-selector", {
|
Vue.component("ns-routes-selector", {
|
||||||
props: ["v-route-ids"],
|
props: ["v-routes"],
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
let that = this
|
let that = this
|
||||||
|
|
||||||
let routeIds = this.vRouteIds
|
|
||||||
if (routeIds == null) {
|
|
||||||
routeIds = []
|
|
||||||
}
|
|
||||||
|
|
||||||
Tea.action("/ns/routes/options")
|
Tea.action("/ns/routes/options")
|
||||||
.post()
|
.post()
|
||||||
.success(function (resp) {
|
.success(function (resp) {
|
||||||
that.allRoutes = resp.data.routes
|
that.routes = resp.data.routes
|
||||||
that.allRoutes.forEach(function (v) {
|
|
||||||
v.isChecked = (routeIds.$contains(v.id))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
let selectedRoutes = this.vRoutes
|
||||||
routeId: 0,
|
if (selectedRoutes == null) {
|
||||||
allRoutes: [],
|
selectedRoutes = []
|
||||||
routes: [],
|
|
||||||
isAdding: false
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
,
|
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: {
|
methods: {
|
||||||
add: function () {
|
add: function () {
|
||||||
this.isAdding = true
|
this.isAdding = true
|
||||||
this.routes = this.allRoutes.$findAll(function (k, v) {
|
this.routeType = "default"
|
||||||
return !v.isChecked
|
this.routeCode = "default"
|
||||||
})
|
|
||||||
this.routeId = 0
|
|
||||||
},
|
},
|
||||||
cancel: function () {
|
cancel: function () {
|
||||||
this.isAdding = false
|
this.isAdding = false
|
||||||
},
|
},
|
||||||
confirm: function () {
|
confirm: function () {
|
||||||
if (this.routeId == 0) {
|
if (this.routeCode.length == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let that = this
|
let that = this
|
||||||
this.routes.forEach(function (v) {
|
this.routes.forEach(function (v) {
|
||||||
if (v.id == that.routeId) {
|
if (v.code == that.routeCode) {
|
||||||
v.isChecked = true
|
that.selectedRoutes.push(v)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.cancel()
|
this.cancel()
|
||||||
},
|
},
|
||||||
remove: function (index) {
|
remove: function (index) {
|
||||||
this.allRoutes[index].isChecked = false
|
this.selectedRoutes.$remove(index)
|
||||||
Vue.set(this.allRoutes, index, this.allRoutes[index])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
template: `<div>
|
template: `<div>
|
||||||
<div>
|
<div>
|
||||||
<div class="ui label basic text small" v-for="(route, index) in allRoutes" v-if="route.isChecked">
|
<div class="ui label basic text small" v-for="(route, index) in selectedRoutes" style="margin-bottom: 0.3em">
|
||||||
<input type="hidden" name="routeIds" :value="route.id"/>
|
<input type="hidden" name="routeCodes" :value="route.code"/>
|
||||||
{{route.name}} <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
{{route.name}} <a href="" title="删除" @click.prevent="remove(index)"><i class="icon remove small"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
@@ -68,11 +72,21 @@ Vue.component("ns-routes-selector", {
|
|||||||
<div v-if="isAdding" style="margin-bottom: 1em">
|
<div v-if="isAdding" style="margin-bottom: 1em">
|
||||||
<div class="ui fields inline">
|
<div class="ui fields inline">
|
||||||
<div class="ui field">
|
<div class="ui field">
|
||||||
<select class="ui dropdown" name="routeId" v-model="routeId">
|
<select class="ui dropdown" v-model="routeType">
|
||||||
<option value="0">[线路]</option>
|
<option value="default">[默认线路]</option>
|
||||||
<option v-for="route in routes" :value="route.id">{{route.name}}</option>
|
<option value="user">自定义线路</option>
|
||||||
|
<option value="isp">运营商</option>
|
||||||
|
<option value="china">中国省市</option>
|
||||||
|
<option value="world">全球国家地区</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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">
|
<div class="ui field">
|
||||||
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
<button type="button" class="ui button tiny" @click.prevent="confirm">确定</button>
|
||||||
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
<a href="" title="取消" @click.prevent="cancel"><i class="icon remove small"></i></a>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui field">
|
<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>
|
||||||
<div class="ui field">
|
<div class="ui field">
|
||||||
<input type="text" placeholder="记录名、备注..." name="keyword" v-model="keyword"/>
|
<input type="text" placeholder="记录名、备注..." name="keyword" v-model="keyword"/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Tea.context(function () {
|
Tea.context(function () {
|
||||||
this.createRecord = function () {
|
this.createRecord = function () {
|
||||||
teaweb.popup("/ns/domains/records/createPopup?domainId=" + this.domain.id, {
|
teaweb.popup("/ns/domains/records/createPopup?domainId=" + this.domain.id, {
|
||||||
height: "32em",
|
height: "33em",
|
||||||
callback: function () {
|
callback: function () {
|
||||||
teaweb.success("保存成功", function () {
|
teaweb.success("保存成功", function () {
|
||||||
teaweb.reload()
|
teaweb.reload()
|
||||||
@@ -12,7 +12,7 @@ Tea.context(function () {
|
|||||||
|
|
||||||
this.updateRecord = function (recordId) {
|
this.updateRecord = function (recordId) {
|
||||||
teaweb.popup("/ns/domains/records/updatePopup?recordId=" + recordId, {
|
teaweb.popup("/ns/domains/records/updatePopup?recordId=" + recordId, {
|
||||||
height: "32em",
|
height: "33em",
|
||||||
callback: function () {
|
callback: function () {
|
||||||
teaweb.success("保存成功", function () {
|
teaweb.success("保存成功", function () {
|
||||||
teaweb.reload()
|
teaweb.reload()
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>线路</td>
|
<td>线路</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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th style="width: 3em"></th>
|
<th style="width: 3em"></th>
|
||||||
<th>线路名称</th>
|
<th>线路名称</th>
|
||||||
|
<th>代号</th>
|
||||||
<th class="two wide">状态</th>
|
<th class="two wide">状态</th>
|
||||||
<th class="two op">操作</th>
|
<th class="two op">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
|
<td style="text-align: center;"><i class="icon bars handle grey"></i> </td>
|
||||||
<td>{{route.name}}</td>
|
<td>{{route.name}}</td>
|
||||||
|
<td>id:{{route.id}}</td>
|
||||||
<td>
|
<td>
|
||||||
<label-on :v-is-on="route.isOn"></label-on>
|
<label-on :v-is-on="route.isOn"></label-on>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user