mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-26 16:46:14 +08:00
优化默认角色数据,增加表格多字段排序例子
This commit is contained in:
41
server/internal/library/hgorm/handler/sorter.go
Normal file
41
server/internal/library/hgorm/handler/sorter.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"hotgo/internal/model/input/form"
|
||||
)
|
||||
|
||||
// ISorter 排序器接口,实现该接口即可使用Handler匹配排序,支持多字段排序
|
||||
type ISorter interface {
|
||||
GetSorters() []form.Sorter
|
||||
}
|
||||
|
||||
// Sorter 排序器
|
||||
func Sorter(in ISorter) func(m *gdb.Model) *gdb.Model {
|
||||
return func(m *gdb.Model) *gdb.Model {
|
||||
hasSort := false
|
||||
sorters := in.GetSorters()
|
||||
for _, sorter := range sorters {
|
||||
if len(sorter.ColumnKey) == 0 || !sorter.Sorter {
|
||||
continue
|
||||
}
|
||||
|
||||
switch sorter.Order {
|
||||
case "descend":
|
||||
hasSort = true
|
||||
m = m.OrderDesc(sorter.ColumnKey)
|
||||
case "ascend":
|
||||
hasSort = true
|
||||
m = m.OrderAsc(sorter.ColumnKey)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 不存在排序条件
|
||||
if !hasSort {
|
||||
// ...
|
||||
}
|
||||
return m
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ type NoticeMaxSortInp struct {
|
||||
}
|
||||
|
||||
type NoticeMaxSortModel struct {
|
||||
Sort int
|
||||
Sort int `json:"sort" dc:"排序"`
|
||||
}
|
||||
|
||||
// NoticeEditInp 修改/新增
|
||||
@@ -27,12 +27,14 @@ type NoticeEditInp struct {
|
||||
Receiver []int64 `json:"receiver" dc:"接收者"`
|
||||
SenderAvatar string `json:"senderAvatar" dc:"发送者头像"`
|
||||
}
|
||||
|
||||
type NoticeEditModel struct{}
|
||||
|
||||
// NoticeDeleteInp 删除字典类型
|
||||
type NoticeDeleteInp struct {
|
||||
Id interface{} `json:"id" v:"required#公告ID不能为空" dc:"公告ID"`
|
||||
}
|
||||
|
||||
type NoticeDeleteModel struct{}
|
||||
|
||||
// NoticeViewInp 获取信息
|
||||
@@ -63,6 +65,7 @@ type NoticeListModel struct {
|
||||
type NoticeStatusInp struct {
|
||||
entity.AdminNotice
|
||||
}
|
||||
|
||||
type NoticeStatusModel struct{}
|
||||
|
||||
// NoticeUpReadInp 更新已读
|
||||
|
21
server/internal/model/input/form/sorter.go
Normal file
21
server/internal/model/input/form/sorter.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Package form
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package form
|
||||
|
||||
// Sorter 排序器,兼容naiveUI
|
||||
type Sorter struct {
|
||||
ColumnKey string `json:"columnKey" dc:"排序字段"`
|
||||
Sorter bool `json:"sorter" dc:"是否需要排序"`
|
||||
Order interface{} `json:"order" dc:"排序方式 descend|ascend|false"`
|
||||
}
|
||||
|
||||
type Sorters struct {
|
||||
Sorters []Sorter `json:"sorters" dc:"排序器"`
|
||||
}
|
||||
|
||||
func (s *Sorters) GetSorters() []Sorter {
|
||||
return s.Sorters
|
||||
}
|
Reference in New Issue
Block a user