|
@@ -201,3 +201,62 @@ func GetMenuList(token string, roleId int) (items []*system.SysMenu, err error)
|
|
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+type TopMenuItemResp struct {
|
|
|
|
+ OrderNum int
|
|
|
|
+ MenuId int
|
|
|
|
+ MenuName string
|
|
|
|
+ IsFrame int ` description:"1左边,0右边"`
|
|
|
|
+ Path string `description:"跳转地址"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// GetTopMenuList
|
|
|
|
+// @Description: 获取顶部的菜单
|
|
|
|
+// @author: Roc
|
|
|
|
+// @datetime 2025-06-19 17:11:31
|
|
|
|
+// @param userId int
|
|
|
|
+// @return items []TopMenuItemResp
|
|
|
|
+// @return err error
|
|
|
|
+func GetTopMenuList(token string) (items []TopMenuItemResp, err error) {
|
|
|
|
+ items = make([]TopMenuItemResp, 0)
|
|
|
|
+ if utils.GnSciUserApiUrl == `` || token == `` {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 先从缓存里面获取,如果取不到,那么再去调用接口
|
|
|
|
+ key := fmt.Sprintf("%s%d", utils.CACHE_SCI_TOP_MENU, utils.MD5(token))
|
|
|
|
+ menuJsonStr, tmpErr := utils.Rc.RedisString(key)
|
|
|
|
+ if tmpErr == nil && menuJsonStr != `` {
|
|
|
|
+ err = json.Unmarshal([]byte(menuJsonStr), &items)
|
|
|
|
+ if err == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resp, err := third.GetTopMenuInfo(token)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if resp.Info != nil && len(resp.Info) > 0 {
|
|
|
|
+ for _, v := range resp.Info {
|
|
|
|
+
|
|
|
|
+ items = append(items, TopMenuItemResp{
|
|
|
|
+ MenuId: v.MenuId,
|
|
|
|
+ MenuName: v.MenuName,
|
|
|
|
+ IsFrame: v.IsFrame,
|
|
|
|
+ Path: v.Path,
|
|
|
|
+ OrderNum: v.OrderNum,
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 30分钟缓存,避免多次调用接口获取数据
|
|
|
|
+ menuJsonByte, tmpErr := json.Marshal(items)
|
|
|
|
+ if tmpErr == nil {
|
|
|
|
+ _ = utils.Rc.Put(key, menuJsonByte, 30*time.Minute)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+}
|