Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package category
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
CategoryId int64
}) {
defer this.CreateLogInfo(codes.TicketCategory_LogDeleteTicketCategory, params.CategoryId)
_, err := this.RPC().UserTicketCategoryRPC().DeleteUserTicketCategory(this.AdminContext(), &pb.DeleteUserTicketCategoryRequest{UserTicketCategoryId: params.CategoryId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,71 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package category
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdatePopupAction struct {
actionutils.ParentAction
}
func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct {
CategoryId int64
}) {
categoryResp, err := this.RPC().UserTicketCategoryRPC().FindUserTicketCategory(this.AdminContext(), &pb.FindUserTicketCategoryRequest{UserTicketCategoryId: params.CategoryId})
if err != nil {
this.ErrorPage(err)
return
}
var category = categoryResp.UserTicketCategory
if category == nil {
this.NotFound("userTicketCategory", params.CategoryId)
return
}
this.Data["category"] = maps.Map{
"id": category.Id,
"name": category.Name,
"isOn": category.IsOn,
}
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
CategoryId int64
Name string
IsOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.TicketCategory_LogUpdateTicketCategory, params.CategoryId)
params.Must.
Field("name", params.Name).
Require("请输入分类名称")
_, err := this.RPC().UserTicketCategoryRPC().UpdateUserTicketCategory(this.AdminContext(), &pb.UpdateUserTicketCategoryRequest{
UserTicketCategoryId: params.CategoryId,
Name: params.Name,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,49 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package categories
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var categoryId int64
defer func() {
this.CreateLogInfo(codes.TicketCategory_LogCreateTicketCategory, categoryId)
}()
params.Must.
Field("name", params.Name).
Require("请输入分类名称")
createResp, err := this.RPC().UserTicketCategoryRPC().CreateUserTicketCategory(this.AdminContext(), &pb.CreateUserTicketCategoryRequest{Name: params.Name})
if err != nil {
this.ErrorPage(err)
return
}
categoryId = createResp.UserTicketCategoryId
this.Success()
}

View File

@@ -0,0 +1,38 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package categories
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
categoriesResp, err := this.RPC().UserTicketCategoryRPC().FindAllUserTicketCategories(this.AdminContext(), &pb.FindAllUserTicketCategoriesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var categoryMaps = []maps.Map{}
for _, category := range categoriesResp.UserTicketCategories {
categoryMaps = append(categoryMaps, maps.Map{
"id": category.Id,
"name": category.Name,
"isOn": category.IsOn,
})
}
this.Data["categories"] = categoryMaps
this.Show()
}

View File

@@ -0,0 +1,138 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package tickets
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"net/url"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
var status = this.Request.URL.Query().Get("status")
if len(status) == 0 {
status = "none"
}
this.Nav("", "", status)
}
func (this *IndexAction) RunGet(params struct {
UserId int64
CategoryId int64
Status string
}) {
if len(params.Status) == 0 {
params.Status = "none"
}
this.Data["status"] = params.Status
this.Data["userId"] = params.UserId
this.Data["categoryId"] = params.CategoryId
this.Data["currentURL"] = url.QueryEscape(this.Request.URL.String())
// 处于新状态的数字
countNewTicketsResp, err := this.RPC().UserTicketRPC().CountUserTickets(this.AdminContext(), &pb.CountUserTicketsRequest{
UserId: params.UserId,
Status: userconfigs.UserTicketStatusNone,
UserTicketCategoryId: params.CategoryId,
})
if err != nil {
this.ErrorPage(err)
return
}
var countNewTickets = countNewTicketsResp.Count
this.Data["countNewTickets"] = countNewTickets
// 列表
var page *actionutils.Page
if params.Status == userconfigs.UserTicketStatusNone {
page = this.NewPage(countNewTickets)
} else {
countTicketsRPC, err := this.RPC().UserTicketRPC().CountUserTickets(this.AdminContext(), &pb.CountUserTicketsRequest{
UserId: params.UserId,
UserTicketCategoryId: params.CategoryId,
Status: params.Status,
})
if err != nil {
this.ErrorPage(err)
return
}
var count = countTicketsRPC.Count
page = this.NewPage(count)
}
this.Data["page"] = page.AsHTML()
// 工单列表
ticketsResp, err := this.RPC().UserTicketRPC().ListUserTickets(this.AdminContext(), &pb.ListUserTicketsRequest{
UserId: params.UserId,
UserTicketCategoryId: params.CategoryId,
Status: params.Status,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var ticketMaps = []maps.Map{}
for _, ticket := range ticketsResp.UserTickets {
// category
var categoryMap maps.Map
if ticket.UserTicketCategory != nil {
categoryMap = maps.Map{
"id": ticket.UserTicketCategory.Id,
"name": ticket.UserTicketCategory.Name,
}
}
// user
var userMap maps.Map
if ticket.User != nil {
userMap = maps.Map{
"id": ticket.User.Id,
"username": ticket.User.Username,
"fullname": ticket.User.Fullname,
}
}
// latest log
var latestLogMap maps.Map
if ticket.LatestUserTicketLog != nil {
var logAdminMap maps.Map
if ticket.LatestUserTicketLog.Admin != nil {
logAdminMap = maps.Map{
"id": ticket.LatestUserTicketLog.Admin.Id,
"fullname": ticket.LatestUserTicketLog.Admin.Fullname,
"username": ticket.LatestUserTicketLog.Admin.Username,
}
}
latestLogMap = maps.Map{
"admin": logAdminMap,
}
}
ticketMaps = append(ticketMaps, maps.Map{
"id": ticket.Id,
"subject": ticket.Subject,
"category": categoryMap,
"user": userMap,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
"status": ticket.Status,
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
"latestLog": latestLogMap,
})
}
this.Data["tickets"] = ticketMaps
this.Show()
}

View File

@@ -0,0 +1,52 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package tickets
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/tickets/categories"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/tickets/categories/category"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/tickets/ticket"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/tickets/users"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(plus.NewHelper(plus.ComponentCodeTicket)).
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeTicket)).
Data("teaMenu", "tickets").
// 工单列表
Prefix("/tickets").
Get("", new(IndexAction)).
// 工单详情
Prefix("/tickets/ticket").
Get("", new(ticket.IndexAction)).
GetPost("/createLogPopup", new(ticket.CreateLogPopupAction)).
Post("/deleteLog", new(ticket.DeleteLogAction)).
// 分类列表
Data("teaSubMenu", "categories").
Prefix("/tickets/categories").
Get("", new(categories.IndexAction)).
GetPost("/createPopup", new(categories.CreatePopupAction)).
// 分类
Prefix("/tickets/categories/category").
Post("/delete", new(category.DeleteAction)).
GetPost("/updatePopup", new(category.UpdatePopupAction)).
// 用户
Prefix("/tickets/users").
Post("/options", new(users.OptionsAction)).
//
EndAll()
})
}

View File

@@ -0,0 +1,53 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package ticket
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/actions"
)
type CreateLogPopupAction struct {
actionutils.ParentAction
}
func (this *CreateLogPopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreateLogPopupAction) RunGet(params struct {
TicketId int64
}) {
this.Data["ticketId"] = params.TicketId
this.Data["statusList"] = userconfigs.FindAllUserTicketStatusList()
this.Show()
}
func (this *CreateLogPopupAction) RunPost(params struct {
TicketId int64
Comment string
Status string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.UserTicketLog_LogReplyTicket, params.TicketId)
_, err := this.RPC().UserTicketLogRPC().CreateUserTicketLog(this.AdminContext(), &pb.CreateUserTicketLogRequest{
UserTicketId: params.TicketId,
Status: params.Status,
Comment: params.Comment,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,13 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package ticket
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type DeleteLogAction struct {
actionutils.ParentAction
}
func (this *DeleteLogAction) RunPost(params struct{}) {
this.Success()
}

View File

@@ -0,0 +1,136 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package ticket
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"html"
"strings"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct {
TicketId int64
FromURL string
}) {
this.Data["fromURL"] = params.FromURL
// 工单信息
ticketResp, err := this.RPC().UserTicketRPC().FindUserTicket(this.AdminContext(), &pb.FindUserTicketRequest{UserTicketId: params.TicketId})
if err != nil {
this.ErrorPage(err)
return
}
var ticket = ticketResp.UserTicket
if ticket == nil {
return
}
// category
var categoryMap maps.Map
if ticket.UserTicketCategory != nil {
categoryMap = maps.Map{
"id": ticket.UserTicketCategory.Id,
"name": ticket.UserTicketCategory.Name,
}
}
// user
var userMap maps.Map
if ticket.User != nil {
userMap = maps.Map{
"id": ticket.User.Id,
"username": ticket.User.Username,
"fullname": ticket.User.Fullname,
}
}
this.Data["ticket"] = maps.Map{
"id": ticket.Id,
"subject": ticket.Subject,
"body": this.formatText(ticket.Body),
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.CreatedAt),
"lastLogTime": timeutil.FormatTime("Y-m-d H:i:s", ticket.LastLogAt),
"status": ticket.Status,
"statusName": userconfigs.UserTicketStatusName(ticket.Status),
"category": categoryMap,
"user": userMap,
}
// 工单处理日志
countLogsResp, err := this.RPC().UserTicketLogRPC().CountUserTicketLogs(this.AdminContext(), &pb.CountUserTicketLogsRequest{UserTicketId: params.TicketId})
if err != nil {
this.ErrorPage(err)
return
}
var countLogs = countLogsResp.Count
var page = this.NewPage(countLogs)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().UserTicketLogRPC().ListUserTicketLogs(this.AdminContext(), &pb.ListUserTicketLogsRequest{
UserTicketId: params.TicketId,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var logMaps = []maps.Map{}
for _, log := range logsResp.UserTicketLogs {
// admin
var adminMap maps.Map
if log.Admin != nil {
adminMap = maps.Map{
"id": log.Admin.Id,
"fullname": log.Admin.Fullname,
"username": log.Admin.Username,
}
}
// user
var userMap maps.Map
if log.User != nil {
userMap = maps.Map{
"id": log.User.Id,
"fullname": log.User.Fullname,
"username": log.User.Username,
}
}
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"comment": this.formatText(log.Comment),
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"status": log.Status,
"statusName": userconfigs.UserTicketStatusName(log.Status),
"admin": adminMap,
"user": userMap,
})
}
this.Data["logs"] = logMaps
this.Show()
}
func (this *IndexAction) formatText(s string) string {
s = html.EscapeString(s)
s = strings.ReplaceAll(s, " ", " ")
s = strings.ReplaceAll(s, "\t", "    ")
s = strings.ReplaceAll(s, "\n", "<br/>\n")
return s
}

View File

@@ -0,0 +1,38 @@
package users
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type OptionsAction struct {
actionutils.ParentAction
}
func (this *OptionsAction) RunPost(params struct {
Keyword string
}) {
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
Keyword: params.Keyword,
Offset: 0,
Size: 100,
})
if err != nil {
this.ErrorPage(err)
return
}
var userMaps = []maps.Map{}
for _, user := range usersResp.Users {
userMaps = append(userMaps, maps.Map{
"id": user.Id,
"fullname": user.Fullname,
"username": user.Username,
"name": user.Fullname + "(" + user.Username + ")",
})
}
this.Data["users"] = userMaps
this.Success()
}