feat:完善项目

This commit is contained in:
henry
2022-01-18 09:20:18 +08:00
parent 8a97ec40d3
commit 478182dcb0
12 changed files with 161 additions and 30 deletions

View File

@ -14,9 +14,10 @@ type AboutHandle func(tenantID uint64) *About
type (
// AboutInfo 基本信息
AboutInfo struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Children []*AboutInfo `json:"children"`
}
// AboutNavigationInfo 导航栏信息
AboutNavigationInfo struct {
@ -25,17 +26,32 @@ type (
}
)
func (c *About) tree(src []*model2.SysAbout, parentID uint64) []*AboutInfo {
out := make([]*AboutInfo, 0)
for _, v := range src {
if v.ParentID == parentID {
out = append(out, &AboutInfo{
ID: v.GetEncodeID(),
Title: v.Title,
Content: v.Content,
Children: nil,
})
}
}
return out
}
// Instance 关于信息
func (c *About) Instance(parentID uint64) (*AboutInfo, error) {
func (c *About) Instance() ([]*AboutInfo, error) {
mSysAbout := model.NewSysAbout()
if isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "title", "content"},
model2.NewWhere("parent_id", parentID)); err != nil {
out := make([]*model2.SysAbout, 0)
if err := model2.ScanFields(mSysAbout.SysAbout, &out, []string{"id", "title", "content"}); err != nil {
return nil, err
} else if !isExist {
return nil, nil
}
return &AboutInfo{ID: mSysAbout.GetEncodeID(), Title: mSysAbout.Title, Content: mSysAbout.Content}, nil
return c.tree(out, 0), nil
}
// Navigation 导航栏