From 75a349b8c305905db70084f310786b37d0790688 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 9 Aug 2021 13:56:11 +0800 Subject: [PATCH] =?UTF-8?q?EdgeDNS=E6=94=AF=E6=8C=81=E5=86=85=E7=BD=AE?= =?UTF-8?q?=E7=BA=BF=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/ns/domains/records/createPopup.go | 16 ++-- .../default/ns/domains/records/index.go | 24 +++--- .../default/ns/domains/records/updatePopup.go | 25 +++--- .../web/actions/default/ns/routes/options.go | 50 +++++++++++- .../js/components/ns/ns-route-selector.js | 16 ++-- .../js/components/ns/ns-routes-selector.js | 78 +++++++++++-------- .../@default/ns/domains/records/index.html | 2 +- .../@default/ns/domains/records/index.js | 4 +- .../ns/domains/records/updatePopup.html | 2 +- web/views/@default/ns/routes/index.html | 2 + 10 files changed, 138 insertions(+), 81 deletions(-) diff --git a/internal/web/actions/default/ns/domains/records/createPopup.go b/internal/web/actions/default/ns/domains/records/createPopup.go index d389646c..6cbf599b 100644 --- a/internal/web/actions/default/ns/domains/records/createPopup.go +++ b/internal/web/actions/default/ns/domains/records/createPopup.go @@ -54,7 +54,7 @@ func (this *CreatePopupAction) RunPost(params struct { Value string Ttl int32 Description string - RouteIds []int64 + RouteCodes []string Must *actions.Must CSRF *actionutils.CSRF @@ -76,13 +76,13 @@ func (this *CreatePopupAction) RunPost(params struct { } createResp, err := this.RPC().NSRecordRPC().CreateNSRecord(this.AdminContext(), &pb.CreateNSRecordRequest{ - NsDomainId: params.DomainId, - Description: params.Description, - Name: params.Name, - Type: params.Type, - Value: params.Value, - Ttl: params.Ttl, - NsRouteIds: params.RouteIds, + NsDomainId: params.DomainId, + Description: params.Description, + Name: params.Name, + Type: params.Type, + Value: params.Value, + Ttl: params.Ttl, + NsRouteCodes: params.RouteCodes, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/ns/domains/records/index.go b/internal/web/actions/default/ns/domains/records/index.go index 9692d71a..b1f896e8 100644 --- a/internal/web/actions/default/ns/domains/records/index.go +++ b/internal/web/actions/default/ns/domains/records/index.go @@ -22,7 +22,7 @@ func (this *IndexAction) RunGet(params struct { DomainId int64 Type string Keyword string - RouteId int64 + RouteCode string }) { // 初始化域名信息 err := domainutils.InitDomain(this.Parent(), params.DomainId) @@ -33,14 +33,14 @@ func (this *IndexAction) RunGet(params struct { this.Data["type"] = params.Type 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{ - NsDomainId: params.DomainId, - Type: params.Type, - NsRouteId: params.RouteId, - Keyword: params.Keyword, + NsDomainId: params.DomainId, + Type: params.Type, + NsRouteCode: params.RouteCode, + Keyword: params.Keyword, }) if err != nil { this.ErrorPage(err) @@ -51,12 +51,12 @@ func (this *IndexAction) RunGet(params struct { this.Data["page"] = page.AsHTML() recordsResp, err := this.RPC().NSRecordRPC().ListEnabledNSRecords(this.AdminContext(), &pb.ListEnabledNSRecordsRequest{ - NsDomainId: params.DomainId, - Type: params.Type, - NsRouteId: params.RouteId, - Keyword: params.Keyword, - Offset: page.Offset, - Size: page.Size, + NsDomainId: params.DomainId, + Type: params.Type, + NsRouteCode: params.RouteCode, + Keyword: params.Keyword, + Offset: page.Offset, + Size: page.Size, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/ns/domains/records/updatePopup.go b/internal/web/actions/default/ns/domains/records/updatePopup.go index 3ee3ab9b..aa36c9a0 100644 --- a/internal/web/actions/default/ns/domains/records/updatePopup.go +++ b/internal/web/actions/default/ns/domains/records/updatePopup.go @@ -33,11 +33,6 @@ func (this *UpdatePopupAction) RunGet(params struct { return } - routeIds := []int64{} - for _, route := range record.NsRoutes { - routeIds = append(routeIds, route.Id) - } - this.Data["record"] = maps.Map{ "id": record.Id, "name": record.Name, @@ -47,7 +42,7 @@ func (this *UpdatePopupAction) RunGet(params struct { "weight": record.Weight, "description": record.Description, "isOn": record.IsOn, - "routeIds": routeIds, + "routes": record.NsRoutes, } // 域名信息 @@ -83,7 +78,7 @@ func (this *UpdatePopupAction) RunPost(params struct { Ttl int32 Description string IsOn bool - RouteIds []int64 + RouteCodes []string Must *actions.Must CSRF *actionutils.CSRF @@ -102,14 +97,14 @@ func (this *UpdatePopupAction) RunPost(params struct { } _, err := this.RPC().NSRecordRPC().UpdateNSRecord(this.AdminContext(), &pb.UpdateNSRecordRequest{ - NsRecordId: params.RecordId, - Description: params.Description, - Name: params.Name, - Type: params.Type, - Value: params.Value, - Ttl: params.Ttl, - IsOn: params.IsOn, - NsRouteIds: params.RouteIds, + NsRecordId: params.RecordId, + Description: params.Description, + Name: params.Name, + Type: params.Type, + Value: params.Value, + Ttl: params.Ttl, + IsOn: params.IsOn, + NsRouteCodes: params.RouteCodes, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/ns/routes/options.go b/internal/web/actions/default/ns/routes/options.go index d54aa114..f6142781 100644 --- a/internal/web/actions/default/ns/routes/options.go +++ b/internal/web/actions/default/ns/routes/options.go @@ -4,8 +4,10 @@ package clusters import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" + "github.com/iwind/TeaGo/types" ) type OptionsAction struct { @@ -17,6 +19,18 @@ func (this *OptionsAction) RunPost(params struct { DomainId 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{ NsClusterId: params.ClusterId, NsDomainId: params.DomainId, @@ -27,13 +41,45 @@ func (this *OptionsAction) RunPost(params struct { return } - routeMaps := []maps.Map{} for _, route := range routesResp.NsRoutes { + if len(route.Code) == 0 { + route.Code = "id:" + types.String(route.Id) + } + routeMaps = append(routeMaps, maps.Map{ - "id": route.Id, "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.Success() diff --git a/web/public/js/components/ns/ns-route-selector.js b/web/public/js/components/ns/ns-route-selector.js index 868c7ffd..b7452b1f 100644 --- a/web/public/js/components/ns/ns-route-selector.js +++ b/web/public/js/components/ns/ns-route-selector.js @@ -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: `
- + +
` diff --git a/web/public/js/components/ns/ns-routes-selector.js b/web/public/js/components/ns/ns-routes-selector.js index 02205574..9a208eef 100644 --- a/web/public/js/components/ns/ns-routes-selector.js +++ b/web/public/js/components/ns/ns-routes-selector.js @@ -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: `
-
- +
+ {{route.name}}  
@@ -68,11 +72,21 @@ Vue.component("ns-routes-selector", {
- + + + + +
+ +
+ +
+
  diff --git a/web/views/@default/ns/domains/records/index.html b/web/views/@default/ns/domains/records/index.html index 5d27ce4a..d743c1da 100644 --- a/web/views/@default/ns/domains/records/index.html +++ b/web/views/@default/ns/domains/records/index.html @@ -15,7 +15,7 @@
- +
diff --git a/web/views/@default/ns/domains/records/index.js b/web/views/@default/ns/domains/records/index.js index de615eef..1e12204a 100644 --- a/web/views/@default/ns/domains/records/index.js +++ b/web/views/@default/ns/domains/records/index.js @@ -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() diff --git a/web/views/@default/ns/domains/records/updatePopup.html b/web/views/@default/ns/domains/records/updatePopup.html index 7d40a5e7..979a302a 100644 --- a/web/views/@default/ns/domains/records/updatePopup.html +++ b/web/views/@default/ns/domains/records/updatePopup.html @@ -40,7 +40,7 @@ 线路 - + diff --git a/web/views/@default/ns/routes/index.html b/web/views/@default/ns/routes/index.html index 19a7ccb4..4c97bea5 100644 --- a/web/views/@default/ns/routes/index.html +++ b/web/views/@default/ns/routes/index.html @@ -11,6 +11,7 @@ 线路名称 + 代号 状态 操作 @@ -19,6 +20,7 @@ {{route.name}} + id:{{route.id}}