From 97e8d8bd26192f1a70ad22ad1f211491bd0aa835 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 11 Jan 2022 14:59:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=A5=E5=BF=97=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=BD=BF=E7=94=A8=E9=9B=86=E7=BE=A4=E3=80=81=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/actions/default/clusters/init.go | 2 +- .../actions/default/clusters/logs/index.go | 54 ++++++++++--------- .../{servers/logs => clusters}/nodeOptions.go | 2 +- .../web/actions/default/servers/logs/index.go | 16 ------ .../web/actions/default/servers/logs/init.go | 1 - .../cluster/node-cluster-combo-box.js | 26 +++++++++ web/public/js/components/common/combo-box.js | 4 +- .../js/components/node/node-combo-box.js | 20 +++++++ .../server/http-access-log-search-box.js | 34 +++--------- web/views/@default/clusters/logs/index.html | 10 +++- web/views/@default/clusters/logs/index.js | 4 ++ web/views/@default/servers/logs/index.html | 2 +- 12 files changed, 102 insertions(+), 73 deletions(-) rename internal/web/actions/default/{servers/logs => clusters}/nodeOptions.go (97%) create mode 100644 web/public/js/components/cluster/node-cluster-combo-box.js create mode 100644 web/public/js/components/node/node-combo-box.js diff --git a/internal/web/actions/default/clusters/init.go b/internal/web/actions/default/clusters/init.go index 048fed4c..041a638b 100644 --- a/internal/web/actions/default/clusters/init.go +++ b/internal/web/actions/default/clusters/init.go @@ -21,8 +21,8 @@ func init() { EndHelpers(). Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeCommon)). Post("/options", new(OptionsAction)). + Post("/nodeOptions", new(NodeOptionsAction)). GetPost("/selectPopup", new(SelectPopupAction)). - EndAll() }) } diff --git a/internal/web/actions/default/clusters/logs/index.go b/internal/web/actions/default/clusters/logs/index.go index 670aeb88..febe6d9f 100644 --- a/internal/web/actions/default/clusters/logs/index.go +++ b/internal/web/actions/default/clusters/logs/index.go @@ -22,12 +22,14 @@ func (this *IndexAction) Init() { } func (this *IndexAction) RunGet(params struct { - DayFrom string - DayTo string - Keyword string - Level string - Type string - Tag string + DayFrom string + DayTo string + Keyword string + Level string + Type string + Tag string + ClusterId int64 + NodeId int64 }) { this.Data["dayFrom"] = params.DayFrom this.Data["dayTo"] = params.DayTo @@ -35,6 +37,8 @@ func (this *IndexAction) RunGet(params struct { this.Data["level"] = params.Level this.Data["type"] = params.Type this.Data["tag"] = params.Tag + this.Data["clusterId"] = params.ClusterId + this.Data["nodeId"] = params.NodeId // 常见标签 this.Data["tags"] = nodelogutils.FindNodeCommonTags() @@ -52,14 +56,15 @@ func (this *IndexAction) RunGet(params struct { // 日志数量 countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{ - NodeId: 0, - Role: nodeconfigs.NodeRoleNode, - DayFrom: params.DayFrom, - DayTo: params.DayTo, - Keyword: params.Keyword, - Level: params.Level, - IsUnread: params.Type == "unread", - Tag: params.Tag, + NodeClusterId: params.ClusterId, + NodeId: params.NodeId, + Role: nodeconfigs.NodeRoleNode, + DayFrom: params.DayFrom, + DayTo: params.DayTo, + Keyword: params.Keyword, + Level: params.Level, + IsUnread: params.Type == "unread", + Tag: params.Tag, }) if err != nil { this.ErrorPage(err) @@ -70,16 +75,17 @@ func (this *IndexAction) RunGet(params struct { this.Data["page"] = page.AsHTML() logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{ - NodeId: 0, - Role: nodeconfigs.NodeRoleNode, - DayFrom: params.DayFrom, - DayTo: params.DayTo, - Keyword: params.Keyword, - Level: params.Level, - IsUnread: params.Type == "unread", - Tag: params.Tag, - Offset: page.Offset, - Size: page.Size, + NodeClusterId: params.ClusterId, + NodeId: params.NodeId, + Role: nodeconfigs.NodeRoleNode, + DayFrom: params.DayFrom, + DayTo: params.DayTo, + Keyword: params.Keyword, + Level: params.Level, + IsUnread: params.Type == "unread", + Tag: params.Tag, + Offset: page.Offset, + Size: page.Size, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/logs/nodeOptions.go b/internal/web/actions/default/clusters/nodeOptions.go similarity index 97% rename from internal/web/actions/default/servers/logs/nodeOptions.go rename to internal/web/actions/default/clusters/nodeOptions.go index 84f33caf..be08bc16 100644 --- a/internal/web/actions/default/servers/logs/nodeOptions.go +++ b/internal/web/actions/default/clusters/nodeOptions.go @@ -1,6 +1,6 @@ // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. -package logs +package clusters import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" diff --git a/internal/web/actions/default/servers/logs/index.go b/internal/web/actions/default/servers/logs/index.go index b08b8ed9..754ff62e 100644 --- a/internal/web/actions/default/servers/logs/index.go +++ b/internal/web/actions/default/servers/logs/index.go @@ -7,7 +7,6 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/lists" - "github.com/iwind/TeaGo/maps" timeutil "github.com/iwind/TeaGo/utils/time" "regexp" "strings" @@ -153,20 +152,5 @@ func (this *IndexAction) RunGet(params struct { } this.Data["regions"] = regionMap - // 集群列表 - var clusterMaps = []maps.Map{} - clusterResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{}) - if err != nil { - this.ErrorPage(err) - return - } - for _, cluster := range clusterResp.NodeClusters { - clusterMaps = append(clusterMaps, maps.Map{ - "id": cluster.Id, - "name": cluster.Name, - }) - } - this.Data["clusters"] = clusterMaps - this.Show() } diff --git a/internal/web/actions/default/servers/logs/init.go b/internal/web/actions/default/servers/logs/init.go index 0760cfaa..e504e224 100644 --- a/internal/web/actions/default/servers/logs/init.go +++ b/internal/web/actions/default/servers/logs/init.go @@ -17,7 +17,6 @@ func init() { Prefix("/servers/logs"). Get("", new(IndexAction)). GetPost("/settings", new(SettingsAction)). - Post("/nodeOptions", new(NodeOptionsAction)). EndAll() }) } diff --git a/web/public/js/components/cluster/node-cluster-combo-box.js b/web/public/js/components/cluster/node-cluster-combo-box.js new file mode 100644 index 00000000..d9d2957f --- /dev/null +++ b/web/public/js/components/cluster/node-cluster-combo-box.js @@ -0,0 +1,26 @@ +Vue.component("node-cluster-combo-box", { + props: ["v-cluster-id"], + data: function () { + let that = this + Tea.action("/clusters/options") + .post() + .success(function (resp) { + that.clusters = resp.data.clusters + }) + return { + clusters: [] + } + }, + methods: { + change: function (item) { + if (item == null) { + this.$emit("change", 0) + } else { + this.$emit("change", item.value) + } + } + }, + template: `
+ +
` +}) \ No newline at end of file diff --git a/web/public/js/components/common/combo-box.js b/web/public/js/components/common/combo-box.js index 902b9f9d..29d7d0f2 100644 --- a/web/public/js/components/common/combo-box.js +++ b/web/public/js/components/common/combo-box.js @@ -112,7 +112,7 @@ Vue.component("combo-box", { this.$emit("change", this.selectedItem) } }, - template: `
+ template: `
@@ -128,7 +128,7 @@ Vue.component("combo-box", {
- diff --git a/web/public/js/components/node/node-combo-box.js b/web/public/js/components/node/node-combo-box.js new file mode 100644 index 00000000..a8866a0c --- /dev/null +++ b/web/public/js/components/node/node-combo-box.js @@ -0,0 +1,20 @@ +Vue.component("node-combo-box", { + props: ["v-cluster-id", "v-node-id"], + data: function () { + let that = this + Tea.action("/clusters/nodeOptions") + .params({ + clusterId: this.vClusterId + }) + .post() + .success(function (resp) { + that.nodes = resp.data.nodes + }) + return { + nodes: [] + } + }, + template: `
+ +
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-access-log-search-box.js b/web/public/js/components/server/http-access-log-search-box.js index 6c59bf08..a0b5f064 100644 --- a/web/public/js/components/server/http-access-log-search-box.js +++ b/web/public/js/components/server/http-access-log-search-box.js @@ -1,13 +1,6 @@ // 访问日志搜索框 Vue.component("http-access-log-search-box", { - props: ["v-ip", "v-domain", "v-keyword", "v-cluster-id", "v-node-id", "v-clusters"], - mounted: function () { - if (this.vClusterId >0) { - this.changeCluster({ - value: this.vClusterId - }) - } - }, + props: ["v-ip", "v-domain", "v-keyword", "v-cluster-id", "v-node-id"], data: function () { let ip = this.vIp if (ip == null) { @@ -28,7 +21,7 @@ Vue.component("http-access-log-search-box", { ip: ip, domain: domain, keyword: keyword, - nodes: [] + clusterId: this.vClusterId } }, methods: { @@ -61,19 +54,8 @@ Vue.component("http-access-log-search-box", { }, 500) } }, - changeCluster: function (item) { - this.nodes = [] - if (item != null) { - let that = this - Tea.action("/servers/logs/nodeOptions") - .params({ - clusterId: item.value - }) - .post() - .success(function (resp) { - that.nodes = resp.data.nodes - }) - } + changeCluster: function (clusterId) { + this.clusterId = clusterId } }, template: `
@@ -103,11 +85,11 @@ Vue.component("http-access-log-search-box", {
-
- +
+
-
- +
+
diff --git a/web/views/@default/clusters/logs/index.html b/web/views/@default/clusters/logs/index.html index f0a19f16..2cadb5a8 100644 --- a/web/views/@default/clusters/logs/index.html +++ b/web/views/@default/clusters/logs/index.html @@ -31,10 +31,18 @@
+
+
+
+ +
+
+ +
- diff --git a/web/views/@default/clusters/logs/index.js b/web/views/@default/clusters/logs/index.js index eaba7256..a8e6be5b 100644 --- a/web/views/@default/clusters/logs/index.js +++ b/web/views/@default/clusters/logs/index.js @@ -38,4 +38,8 @@ Tea.context(function () { }) }) } + + this.changeCluster = function (clusterId) { + this.clusterId = clusterId + } }) \ No newline at end of file diff --git a/web/views/@default/servers/logs/index.html b/web/views/@default/servers/logs/index.html index 670c476b..1808de0e 100644 --- a/web/views/@default/servers/logs/index.html +++ b/web/views/@default/servers/logs/index.html @@ -12,7 +12,7 @@ - +