Files
2022-01-12 17:29:05 +08:00

52 lines
1.1 KiB
Go

package controller
import (
"SciencesServer/app/api/website/model"
model2 "SciencesServer/app/common/model"
)
type Navigation struct{}
type NavigationHandle func() *Navigation
type NavigationInfo struct {
Title string `json:"title"`
Link string `json:"link"`
IsTarget bool `json:"is_target"`
Children []*NavigationInfo `json:"children"`
}
// tree 树状
func (c *Navigation) tree(src []*model2.SysNavigation, parentID uint64) []*NavigationInfo {
out := make([]*NavigationInfo, 0)
for _, v := range src {
if v.ParentID == parentID {
out = append(out, &NavigationInfo{
Title: v.Title,
Link: v.Link,
IsTarget: v.IsTarget > 0,
Children: c.tree(src, v.ID),
})
}
}
return out
}
// Instance 导航栏信息
func (c *Navigation) Instance() ([]*NavigationInfo, error) {
mSysNavigation := model.NewSysNavigation()
out, err := mSysNavigation.Navigation()
if err != nil {
return nil, err
}
return c.tree(out, 0), nil
}
func NewNavigation() NavigationHandle {
return func() *Navigation {
return &Navigation{}
}
}