diff --git a/internal/web/actions/default/admins/recipients/tasks/index.go b/internal/web/actions/default/admins/recipients/tasks/index.go new file mode 100644 index 00000000..6038a3c0 --- /dev/null +++ b/internal/web/actions/default/admins/recipients/tasks/index.go @@ -0,0 +1,103 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package tasks + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" + timeutil "github.com/iwind/TeaGo/utils/time" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { + this.Nav("", "", "task") +} + +func (this *IndexAction) RunGet(params struct { + Status int32 +}) { + this.Data["status"] = params.Status + if params.Status > 3 { + params.Status = 0 + } + + countWaitingResp, err := this.RPC().MessageTaskRPC().CountMessageTasksWithStatus(this.AdminContext(), &pb.CountMessageTasksWithStatusRequest{Status: pb.CountMessageTasksWithStatusRequest_MessageTaskStatusNone}) + if err != nil { + this.ErrorPage(err) + return + } + var countWaiting = countWaitingResp.Count + this.Data["countWaiting"] = countWaiting + + countFailedResp, err := this.RPC().MessageTaskRPC().CountMessageTasksWithStatus(this.AdminContext(), &pb.CountMessageTasksWithStatusRequest{Status: pb.CountMessageTasksWithStatusRequest_MessageTaskStatusFailed}) + if err != nil { + this.ErrorPage(err) + return + } + var countFailed = countFailedResp.Count + this.Data["countFailed"] = countFailed + + // 列表 + var total = int64(0) + switch params.Status { + case 0: + total = countWaiting + case 3: + total = countFailed + } + page := this.NewPage(total) + this.Data["page"] = page.AsHTML() + + var taskMaps = []maps.Map{} + tasksResp, err := this.RPC().MessageTaskRPC().ListMessageTasksWithStatus(this.AdminContext(), &pb.ListMessageTasksWithStatusRequest{ + Status: pb.ListMessageTasksWithStatusRequest_Status(params.Status), + Offset: page.Offset, + Size: page.Size, + }) + if err != nil { + this.ErrorPage(err) + return + } + for _, task := range tasksResp.MessageTasks { + var resultMap = maps.Map{} + var result = task.Result + if result != nil { + resultMap = maps.Map{ + "isOk": result.IsOk, + "error": result.Error, + "response": result.Response, + } + } + + //var recipients = []string{} + var user = "" + var instanceMap maps.Map + if task.MessageRecipient != nil { + user = task.MessageRecipient.User + if task.MessageRecipient.MessageMediaInstance != nil { + instanceMap = maps.Map{ + "id": task.MessageRecipient.MessageMediaInstance.Id, + "name": task.MessageRecipient.MessageMediaInstance.Name, + } + } + } + + taskMaps = append(taskMaps, maps.Map{ + "id": task.Id, + "subject": task.Subject, + "body": task.Body, + "createdTime": timeutil.FormatTime("Y-m-d H:i:s", task.CreatedAt), + "result": resultMap, + "status": task.Status, + "user": user, + "instance": instanceMap, + }) + } + this.Data["tasks"] = taskMaps + + this.Show() +} diff --git a/internal/web/actions/default/admins/recipients/tasks/init.go b/internal/web/actions/default/admins/recipients/tasks/init.go index c9b8b989..90fde3e2 100644 --- a/internal/web/actions/default/admins/recipients/tasks/init.go +++ b/internal/web/actions/default/admins/recipients/tasks/init.go @@ -13,6 +13,7 @@ func init() { Data("teaMenu", "admins"). Data("teaSubMenu", "recipients"). Prefix("/admins/recipients/tasks"). + Get("", new(IndexAction)). Post("/taskInfo", new(TaskInfoAction)). EndAll() }) diff --git a/web/public/js/components/common/menu-item.js b/web/public/js/components/common/menu-item.js index 29eb7c4e..31fd8266 100644 --- a/web/public/js/components/common/menu-item.js +++ b/web/public/js/components/common/menu-item.js @@ -4,7 +4,7 @@ Vue.component("menu-item", { props: ["href", "active", "code"], data: function () { - var active = this.active + let active = this.active if (typeof (active) == "undefined") { var itemCode = "" if (typeof (window.TEA.ACTION.data.firstMenuItem) != "undefined") { @@ -18,8 +18,19 @@ Vue.component("menu-item", { } } } + + let href = (this.href == null) ? "" : this.href + if (typeof (href) == "string" && href.length > 0 && href.startsWith(".")) { + let qIndex = href.indexOf("?") + if (qIndex >= 0) { + href = Tea.url(href.substring(0, qIndex)) + href.substring(qIndex) + } else { + href = Tea.url(href) + } + } + return { - vHref: (this.href == null) ? "" : this.href, + vHref: href, vActive: active } }, diff --git a/web/views/@default/admins/recipients/@menu.html b/web/views/@default/admins/recipients/@menu.html index e05c7aef..14368634 100644 --- a/web/views/@default/admins/recipients/@menu.html +++ b/web/views/@default/admins/recipients/@menu.html @@ -3,4 +3,5 @@ 接收人分组 媒介 发送记录 + 任务队列 diff --git a/web/views/@default/admins/recipients/tasks/index.html b/web/views/@default/admins/recipients/tasks/index.html new file mode 100644 index 00000000..c7bd1f39 --- /dev/null +++ b/web/views/@default/admins/recipients/tasks/index.html @@ -0,0 +1,37 @@ +{$layout} +{$template "../menu"} + + + 等待发送({{countWaiting}}) + 发送错误({{countFailed}}) + + + +

暂时还没有发送任务。

+ +
+
+ + + + + + + + + + + + + + + + + +
简介 + {{task.user}}   |   媒介:{{task.instance.name}} +   |   时间:{{task.createdTime}} +
标题{{task.subject}}
内容{{task.body}}
错误信息{{task.result.error}}
+
+ +
\ No newline at end of file