阶段性提交

This commit is contained in:
GoEdgeLab
2020-07-29 19:34:54 +08:00
parent b984b68089
commit 16d2dff57a
56 changed files with 5799 additions and 959 deletions

View File

@@ -1,29 +1,29 @@
package actionutils
import (
"fmt"
"github.com/iwind/TeaGo/actions"
"math"
"net/url"
"strconv"
"strings"
)
type Page struct {
Offset int // 开始位置
Size int // 每页显示数量
Current int // 当前页码
Max int // 最大页码
Total int // 总数量
Offset int64 // 开始位置
Size int64 // 每页显示数量
Current int64 // 当前页码
Max int64 // 最大页码
Total int64 // 总数量
Path string
Query url.Values
}
func NewActionPage(actionPtr actions.ActionWrapper, total int, size int) *Page {
func NewActionPage(actionPtr actions.ActionWrapper, total int64, size int64) *Page {
action := actionPtr.Object()
currentPage := action.ParamInt("page")
currentPage := action.ParamInt64("page")
paramSize := action.ParamInt("pageSize")
paramSize := action.ParamInt64("pageSize")
if paramSize > 0 {
size = paramSize
}
@@ -52,7 +52,7 @@ func (this *Page) calculate() {
}
this.Offset = this.Size * (this.Current - 1)
this.Max = int(math.Ceil(float64(this.Total) / float64(this.Size)))
this.Max = int64(math.Ceil(float64(this.Total) / float64(this.Size)))
}
func (this *Page) AsHTML() string {
@@ -86,9 +86,9 @@ func (this *Page) AsHTML() string {
for i := before5; i <= after5; i++ {
if i == this.Current {
result = append(result, `<a href="`+this.composeURL(i)+`" class="active">`+strconv.Itoa(i)+`</a>`)
result = append(result, `<a href="`+this.composeURL(i)+`" class="active">`+fmt.Sprintf("%d", i)+`</a>`)
} else {
result = append(result, `<a href="`+this.composeURL(i)+`">`+strconv.Itoa(i)+`</a>`)
result = append(result, `<a href="`+this.composeURL(i)+`">`+fmt.Sprintf("%d", i)+`</a>`)
}
}
@@ -132,30 +132,30 @@ func (this *Page) IsLastPage() bool {
return this.Current == this.Max
}
func (this *Page) composeURL(page int) string {
this.Query["page"] = []string{strconv.Itoa(page)}
func (this *Page) composeURL(page int64) string {
this.Query["page"] = []string{fmt.Sprintf("%d", page)}
return this.Path + "?" + this.Query.Encode()
}
func (this *Page) min(i, j int) int {
func (this *Page) min(i, j int64) int64 {
if i < j {
return i
}
return j
}
func (this *Page) max(i, j int) int {
func (this *Page) max(i, j int64) int64 {
if i < j {
return j
}
return i
}
func (this *Page) renderSizeOption(size int) string {
o := `<option value="` + strconv.Itoa(size) + `"`
func (this *Page) renderSizeOption(size int64) string {
o := `<option value="` + fmt.Sprintf("%d", size) + `"`
if size == this.Size {
o += ` selected="selected"`
}
o += `>` + strconv.Itoa(size) + `条</option>`
o += `>` + fmt.Sprintf("%d", size) + `条</option>`
return o
}

View File

@@ -1,19 +1,23 @@
package actionutils
import (
"context"
"errors"
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/admin"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs"
"net/http"
"strconv"
)
type ParentAction struct {
actions.ActionObject
rpcClient *rpc.RPCClient
}
func (this *ParentAction) ErrorPage(err error) {
@@ -39,7 +43,7 @@ func (this *ParentAction) NotFound(name string, itemId int) {
this.ErrorPage(errors.New(name + " id: '" + strconv.Itoa(itemId) + "' is not found"))
}
func (this *ParentAction) NewPage(total int, size ...int) *Page {
func (this *ParentAction) NewPage(total int64, size ...int64) *Page {
if len(size) > 0 {
return NewActionPage(this, total, size[0])
}
@@ -56,8 +60,8 @@ func (this *ParentAction) SecondMenu(menuItem string) {
this.Data["secondMenuItem"] = menuItem
}
func (this *ParentAction) AdminId() int {
return this.Context.GetInt("adminId")
func (this *ParentAction) AdminId() int64 {
return int64(this.Context.GetInt("adminId"))
}
func (this *ParentAction) CreateLog(level string, description string, args ...interface{}) {
@@ -66,7 +70,7 @@ func (this *ParentAction) CreateLog(level string, description string, args ...in
utils.PrintError(err)
return
}
_, err = rpcClient.AdminRPC().CreateLog(rpcClient.Context(this.AdminId()), &admin.CreateLogRequest{
_, err = rpcClient.AdminRPC().CreateAdminLog(rpcClient.Context(this.AdminId()), &pb.CreateAdminLogRequest{
Level: level,
Description: fmt.Sprintf(description, args...),
Action: this.Request.URL.Path,
@@ -76,3 +80,25 @@ func (this *ParentAction) CreateLog(level string, description string, args ...in
utils.PrintError(err)
}
}
// 获取RPC
func (this *ParentAction) RPC() *rpc.RPCClient {
if this.rpcClient != nil {
return this.rpcClient
}
// 所有集群
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Fatal(err)
return nil
}
this.rpcClient = rpcClient
return rpcClient
}
// 获取Context
func (this *ParentAction) AdminContext() context.Context {
return this.rpcClient.Context(this.AdminId())
}