feat:完善项目信息
This commit is contained in:
60
app/api/admin/controller/auth/base.go
Normal file
60
app/api/admin/controller/auth/base.go
Normal file
@ -0,0 +1,60 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type (
|
||||
// Tree 权限信息
|
||||
Tree struct {
|
||||
*model2.SysAuth
|
||||
KindTitle string `json:"kind_title"`
|
||||
Children []*Tree `json:"children"`
|
||||
}
|
||||
// TreeRole 角色权限信息
|
||||
TreeRole struct {
|
||||
*model2.SysAuth
|
||||
KindTitle string `json:"kind_title"`
|
||||
Checked bool `json:"checked"`
|
||||
Children []*TreeRole `json:"children"`
|
||||
}
|
||||
// TreeChecked 角色选中状态
|
||||
TreeChecked struct {
|
||||
*model2.SysAuth
|
||||
Checked bool `json:"checked"`
|
||||
Children []*TreeChecked `json:"children"`
|
||||
}
|
||||
)
|
||||
|
||||
// tree 树状筛选
|
||||
func tree(src []*model2.SysAuth, parentID uint64) []*Tree {
|
||||
out := make([]*Tree, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &Tree{
|
||||
SysAuth: v,
|
||||
KindTitle: v.KindTitle(),
|
||||
Children: tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TreeCheckedFunc 树状筛选
|
||||
func TreeCheckedFunc(src []*model.SysAuthScene, parentID uint64) []*TreeChecked {
|
||||
out := make([]*TreeChecked, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
out = append(out, &TreeChecked{
|
||||
SysAuth: v.SysAuth,
|
||||
Checked: v.SceneID > 0,
|
||||
Children: TreeCheckedFunc(src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
34
app/api/admin/controller/auth/instance.go
Normal file
34
app/api/admin/controller/auth/instance.go
Normal file
@ -0,0 +1,34 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List() ([]*Tree, error) {
|
||||
mSysAuth := model.NewSysAuth()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
&model2.ModelWhereOrder{Order: model2.NewOrder("parent_id", model2.OrderModeToAsc)},
|
||||
&model2.ModelWhereOrder{Order: model2.NewOrder("sort", model2.OrderModeToDesc)},
|
||||
}
|
||||
out := make([]*model2.SysAuth, 0)
|
||||
|
||||
if err := model2.Scan(mSysAuth, &out, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tree(out, 0), nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{Platform: &controller.Platform{Session: session}}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user