92 lines
3.5 KiB
Go
92 lines
3.5 KiB
Go
package menuResponse
|
||
|
||
import (
|
||
"hospital-admin-api/api/model"
|
||
"strconv"
|
||
)
|
||
|
||
// GetMenuList 获取菜单列表
|
||
type GetMenuList struct {
|
||
MenuId string `json:"menu_id"`
|
||
MenuName string `json:"menu_name"` // 菜单名称
|
||
MenuTitle string `json:"menu_title"` // 菜单名称
|
||
ParentId string `json:"parent_id"` // 父菜单ID(0表示一级)
|
||
MenuStatus int `json:"menu_status"` // 菜单状态(0:隐藏 1:正常)此优先级最高
|
||
MenuType int `json:"menu_type"` // 菜单类型(1:模块 2:菜单 3:按钮)
|
||
Permission string `json:"permission"` // 标识
|
||
OrderNum int `json:"order_num"` // 显示顺序
|
||
Icon string `json:"icon"` // 图标地址
|
||
Path string `json:"path"` // 页面地址(#表示当前页)
|
||
Component string `json:"component"` // 组件名称
|
||
Children []*GetMenuList `json:"children"` // 下级页面
|
||
}
|
||
|
||
// GetMenu 菜单详情
|
||
type getMenu struct {
|
||
MenuId string `json:"menu_id"`
|
||
MenuName string `json:"menu_name"` // 菜单名称
|
||
MenuTitle string `json:"menu_title"` // 菜单名称
|
||
ParentId string `json:"parent_id"` // 父菜单ID(0表示一级)
|
||
MenuStatus int `json:"menu_status"` // 菜单状态(0:隐藏 1:正常)此优先级最高
|
||
MenuType int `json:"menu_type"` // 菜单类型(1:模块 2:菜单 3:按钮)
|
||
Permission string `json:"permission"` // 标识
|
||
OrderNum int `json:"order_num"` // 显示顺序
|
||
Icon string `json:"icon"` // 图标地址
|
||
Path string `json:"path"` // 页面地址(#表示当前页)
|
||
Component string `json:"component"` // 组件名称
|
||
Api []*getAdminMenuApi `json:"api"` // 接口数据
|
||
Apis []string `json:"apis"` // 接口数据
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||
}
|
||
|
||
// 接口id
|
||
type getAdminMenuApi struct {
|
||
ApiId string `json:"api_id"` // 接口id
|
||
ApiName string `json:"api_name"` // 接口名称
|
||
}
|
||
|
||
// GetMenuResponse 菜单详情
|
||
func GetMenuResponse(adminMenu *model.AdminMenu, adminMenuApi []*model.AdminMenuApi) (*getMenu, error) {
|
||
var getMenuResponse *getMenu
|
||
|
||
getAdminMenuApis := make([]*getAdminMenuApi, len(adminMenuApi))
|
||
apis := make([]string, 0, len(adminMenuApi))
|
||
|
||
if adminMenu != nil {
|
||
getMenuResponse = &getMenu{
|
||
MenuId: strconv.Itoa(int(adminMenu.MenuId)),
|
||
MenuName: adminMenu.MenuName,
|
||
MenuTitle: adminMenu.MenuTitle,
|
||
ParentId: strconv.Itoa(int(adminMenu.ParentId)),
|
||
MenuStatus: adminMenu.MenuStatus,
|
||
MenuType: adminMenu.MenuType,
|
||
Permission: adminMenu.Permission,
|
||
OrderNum: adminMenu.OrderNum,
|
||
Icon: adminMenu.Icon,
|
||
Path: adminMenu.Path,
|
||
Component: adminMenu.Component,
|
||
CreatedAt: adminMenu.CreatedAt,
|
||
UpdatedAt: adminMenu.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
if getMenuResponse != nil && len(adminMenuApi) != 0 {
|
||
for i, v := range adminMenuApi {
|
||
result := &getAdminMenuApi{
|
||
ApiId: strconv.FormatInt(v.ApiId, 10),
|
||
ApiName: v.API.APIName,
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
getAdminMenuApis[i] = result
|
||
apis = append(apis, strconv.FormatInt(v.ApiId, 10))
|
||
}
|
||
|
||
getMenuResponse.Api = getAdminMenuApis
|
||
getMenuResponse.Apis = apis
|
||
}
|
||
|
||
return getMenuResponse, nil
|
||
}
|