diff --git a/app/common/init.go b/app/common/init.go index edbcaa4..16437c3 100644 --- a/app/common/init.go +++ b/app/common/init.go @@ -3,7 +3,6 @@ package common import ( "ArmedPolice/app/common/model" "ArmedPolice/config" - "ArmedPolice/lib" "ArmedPolice/serve/orm" "ArmedPolice/utils" ) @@ -96,7 +95,7 @@ func initModel() { out := make([]*model.SysConfig, 0) - lib.LoadConfig("./json/sys_config.json", &values, func(i interface{}) { + utils.LoadConfig("./json/sys_config.json", &values, func(i interface{}) { for _, v := range values { out = append(out, &model.SysConfig{ Model: model.Model{ID: v.ID}, @@ -115,7 +114,7 @@ func initModel() { out := make([]*model.SysMenu, 0) - lib.LoadConfig("./json/sys_menu.json", &values, func(i interface{}) { + utils.LoadConfig("./json/sys_menu.json", &values, func(i interface{}) { for _, v := range values { out = append(out, &model.SysMenu{ Model: model.Model{ID: v.ID}, @@ -145,7 +144,7 @@ func initModel() { out := make([]*model.SysRole, 0) values := make([]*structForSysRole, 0) - lib.LoadConfig("./json/sys_role.json", &values, func(i interface{}) { + utils.LoadConfig("./json/sys_role.json", &values, func(i interface{}) { for _, v := range values { out = append(out, &model.SysRole{ Model: model.Model{ID: v.ID}, @@ -177,7 +176,7 @@ func initModel() { values := make([]*structForWorkSchedule, 0) - lib.LoadConfig("./json/work_schedule.json", &values, func(i interface{}) { + utils.LoadConfig("./json/work_schedule.json", &values, func(i interface{}) { for _, v := range values { out = append(out, &model.WorkSchedule{ Model: model.Model{ID: v.ID}, diff --git a/app/controller/user/menu.go b/app/controller/user/menu.go index 644263a..a3cb1c9 100644 --- a/app/controller/user/menu.go +++ b/app/controller/user/menu.go @@ -1,19 +1,29 @@ package user import ( - "ArmedPolice/app/controller/menu" + model2 "ArmedPolice/app/common/model" + "ArmedPolice/app/controller/basic" "ArmedPolice/app/model" "ArmedPolice/app/service" - "ArmedPolice/utils" - "fmt" ) type Menu struct{ *service.Session } type MenuHandle func(session *service.Session) *Menu +type MenuInfo struct { + basic.CommonIDString + *model2.SysMenuBasic + ParentID string `json:"parent_id"` + // 与前端约定 + Meta struct { + Title string `json:"title"` + } `json:"meta"` + Path string `json:"path"` +} + // Menu 用户菜单信息 -func (c *Menu) Menu() ([]*menu.InstanceIdentityInfo, error) { +func (c *Menu) Menu() ([]*MenuInfo, error) { mSysMenu := model.NewSysMenu() out := make([]*model.SysMenuScene, 0) @@ -28,9 +38,25 @@ func (c *Menu) Menu() ([]*menu.InstanceIdentityInfo, error) { if out, err = mSysMenu.UserMenu(c.UID); err != nil { return nil, err } - fmt.Println(utils.AnyToJSON(out)) RETURN: - return menu.TreeIdentity(mSysMenu.SysMenu, out, 0), nil + list := make([]*MenuInfo, 0) + + for _, v := range out { + mSysMenu.SetID(v.ID) + data := &MenuInfo{ + CommonIDString: basic.CommonIDString{ID: mSysMenu.GetEncodeID()}, + SysMenuBasic: v.SysMenuBasic, + ParentID: (&model2.Model{ID: v.ParentID}).GetEncodeID(), + Meta: struct { + Title string `json:"title"` + }{Title: v.Name}, + } + data.Name = v.Link + data.Path = v.Link + list = append(list, data) + } + return list, nil + //return menu.TreeIdentity(mSysMenu.SysMenu, out, 0), nil } func NewMenu() MenuHandle { diff --git a/app/init.go b/app/init.go index 28d26c9..1b48c9f 100644 --- a/app/init.go +++ b/app/init.go @@ -4,7 +4,6 @@ import ( "ArmedPolice/app/event" "ArmedPolice/app/service" "ArmedPolice/config" - "ArmedPolice/lib" "ArmedPolice/utils" ) @@ -14,7 +13,7 @@ func Init() { service.NewHub().Run() }) // 载入数据配置 - lib.LoadConfig("./json/area.json", &config.SettingAreaInfo) + utils.LoadConfig("./json/area.json", &config.SettingAreaInfo) // RedisHash存储/移除监听 service.Subscribe(config.EventForRedisHashProduce, event.NewRedisHashProduce()) service.Subscribe(config.EventForRedisHashDestroy, event.NewRedisHashDestroy()) diff --git a/app/service/session.go b/app/service/session.go index 5066329..f74a891 100644 --- a/app/service/session.go +++ b/app/service/session.go @@ -20,7 +20,7 @@ func (this *Session) MarshalBinary() ([]byte, error) { } func (this *Session) UnmarshalBinary(data []byte) error { - return utils.FromJSONBytes(data, this) + return json.Unmarshal(data, this) } func (this *Session) UIDToString() string { diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index a146527..9ce2f48 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -4,13 +4,13 @@ import ( "ArmedPolice/app" "ArmedPolice/app/common" "ArmedPolice/config" - "ArmedPolice/lib" "ArmedPolice/router" "ArmedPolice/serve/cache" "ArmedPolice/serve/logger" "ArmedPolice/serve/orm" "ArmedPolice/serve/web" "ArmedPolice/task" + "ArmedPolice/utils" "github.com/gin-gonic/gin" "strings" ) @@ -25,7 +25,7 @@ type Option struct { func (this *Serve) Run() { // 载入配置 - lib.LoadConfig(this.Option.Config, config.SettingInfo, func(i interface{}) { + utils.LoadConfig(this.Option.Config, config.SettingInfo, func(i interface{}) { obj := i.(*config.Setting) obj.Upload.Exts = strings.Split(obj.Upload.Ext, ",") logger.NewLogger().Init(&logger.Option{File: obj.Log.File, LeastDay: obj.Log.LeastDay, Level: obj.Log.Level, IsStdout: false}).Load() diff --git a/json/sys_menu.json b/json/sys_menu.json index 6048013..1a58f12 100644 --- a/json/sys_menu.json +++ b/json/sys_menu.json @@ -1,296 +1,410 @@ -[ - { - "id": 10, - "parent_id": 0, - "name": "装备维修", - "kind": 1, - "link": null, - "component": null, - "icon": null, - "auth": 0, - "sort": 10, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 11, - "parent_id": 0, - "name": "装备型谱目录", - "kind": 1, - "link": null, - "component": null, - "icon": null, - "auth": 0, - "sort": 9, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 12, - "parent_id": 0, - "name": "器材库", - "kind": 1, - "link": null, - "component": null, - "icon": null, - "auth": 0, - "sort": 8, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 13, - "parent_id": 0, - "name": "供应商", - "kind": 1, - "link": null, - "component": null, - "icon": null, - "auth": 0, - "sort": 7, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 14, - "parent_id": 0, - "name": "系统设置", - "kind": 1, - "link": null, - "component": "RouteView", - "icon": null, - "auth": 0, - "sort": 0, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 15, - "parent_id": 10, - "name": "新增内修申请", - "kind": 2, - "link": null, - "component": "repair/innerApply", - "icon": null, - "auth": 0, - "sort": 10, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 16, - "parent_id": 10, - "name": "新增外修申请", - "kind": 2, - "link": null, - "component": "repair/outerApply", - "icon": null, - "auth": 0, - "sort": 9, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 17, - "parent_id": 10, - "name": "我的内修审批", - "kind": 2, - "link": null, - "component": "repair/innerApprove", - "icon": null, - "auth": 0, - "sort": 8, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 18, - "parent_id": 10, - "name": "我的外修审批", - "kind": 2, - "link": null, - "component": "repair/outerApprove", - "icon": null, - "auth": 0, - "sort": 7, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 19, - "parent_id": 10, - "name": "内修工单查询", - "kind": 2, - "link": null, - "component": "repair/innerWorkOrder", - "icon": null, - "auth": 0, - "sort": 6, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 20, - "parent_id": 10, - "name": "外修工单查询", - "kind": 2, - "link": null, - "component": "repair/outerWorkOrder", - "icon": null, - "auth": 0, - "sort": 5, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 21, - "parent_id": 11, - "name": "装备型谱新增", - "kind": 2, - "link": "", - "component": "catalogue/add", - "icon": "", - "auth": 0, - "sort": 10, - "remark": "", - "status": 1, - "is_deleted": 0 - }, - { - "id": 22, - "parent_id": 11, - "name": "装备型谱列表", - "kind": 2, - "link": "", - "component": "catalogue/list", - "icon": "", - "auth": 0, - "sort": 9, - "remark": "", - "status": 1, - "is_deleted": 0 - }, - { - "id": 23, - "parent_id": 12, - "name": "器材新增", - "kind": 2, - "link": null, - "component": "equipment/add", - "icon": null, - "auth": 0, - "sort": 10, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 24, - "parent_id": 12, - "name": "器材列表", - "kind": 2, - "link": null, - "component": "equipment/list", - "icon": null, - "auth": 0, - "sort": 9, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 25, - "parent_id": 13, - "name": "供应商新增", - "kind": 2, - "link": null, - "component": "supplier/add", - "icon": null, - "auth": 0, - "sort": 10, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 26, - "parent_id": 13, - "name": "供应商列表", - "kind": 2, - "link": null, - "component": "supplier/list", - "icon": null, - "auth": 0, - "sort": 9, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 27, - "parent_id": 14, - "name": "用户管理", - "kind": 2, - "link": null, - "component": "system/user", - "icon": null, - "auth": 0, - "sort": 10, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 28, - "parent_id": 14, - "name": "角色管理", - "kind": 2, - "link": null, - "component": "system/role", - "icon": null, - "auth": 0, - "sort": 9, - "remark": null, - "status": 1, - "is_deleted": 0 - }, - { - "id": 29, - "parent_id": 14, - "name": "部门管理", - "kind": 2, - "link": null, - "component": "system/dept", - "icon": null, - "auth": 0, - "sort": 8, - "remark": null, - "status": 1, - "is_deleted": 1 - }, - { - "id": 30, - "parent_id": 14, - "name": "菜单管理", - "kind": 2, - "link": "", - "component": "system/menu", - "icon": "", - "auth": 0, - "sort": 8, - "remark": "", - "status": 1, - "is_deleted": 0 - } -] +{ + "RECORDS": [ + { + "id": 10, + "parent_id": 0, + "name": "装备维修", + "kind": 1, + "link": null, + "component": "Layout", + "icon": null, + "auth": 0, + "sort": 10, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 11, + "parent_id": 0, + "name": "装备型谱目录", + "kind": 1, + "link": null, + "component": "Layout", + "icon": null, + "auth": 0, + "sort": 9, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 12, + "parent_id": 0, + "name": "器材库", + "kind": 1, + "link": null, + "component": "Layout", + "icon": null, + "auth": 0, + "sort": 8, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 13, + "parent_id": 0, + "name": "供应商", + "kind": 1, + "link": null, + "component": "Layout", + "icon": null, + "auth": 0, + "sort": 7, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 14, + "parent_id": 0, + "name": "系统设置", + "kind": 1, + "link": null, + "component": "Layout", + "icon": null, + "auth": 0, + "sort": 0, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 15, + "parent_id": 10, + "name": "内修工单创建", + "kind": 2, + "link": "innerApply", + "component": "repair/innerApply", + "icon": "", + "auth": 0, + "sort": 10, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 16, + "parent_id": 10, + "name": "外修工单创建", + "kind": 2, + "link": "outerApply", + "component": "repair/outerApply", + "icon": "", + "auth": 0, + "sort": 9, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 17, + "parent_id": 10, + "name": "我的内修审批", + "kind": 2, + "link": "innerApprove", + "component": "repair/innerApprove", + "icon": "", + "auth": 0, + "sort": 8, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 18, + "parent_id": 10, + "name": "我的外修审批", + "kind": 2, + "link": "outerApprove", + "component": "repair/outerApprove", + "icon": "", + "auth": 0, + "sort": 7, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 19, + "parent_id": 10, + "name": "内修工单查询", + "kind": 2, + "link": "innerWorkOrder", + "component": "repair/innerWorkOrder", + "icon": "", + "auth": 0, + "sort": 6, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 20, + "parent_id": 10, + "name": "外修工单查询", + "kind": 2, + "link": "outerWorkOrder", + "component": "repair/outerWorkOrder", + "icon": "", + "auth": 0, + "sort": 5, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 21, + "parent_id": 11, + "name": "装备型谱新增", + "kind": 2, + "link": "spectrumAdd", + "component": "catalogue/spectrumAdd", + "icon": "", + "auth": 0, + "sort": 10, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 22, + "parent_id": 11, + "name": "装备型谱列表", + "kind": 2, + "link": "spectrumList", + "component": "catalogue/spectrumList", + "icon": "", + "auth": 0, + "sort": 9, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 23, + "parent_id": 12, + "name": "器材新增", + "kind": 2, + "link": "add", + "component": "equipment/add", + "icon": "", + "auth": 0, + "sort": 10, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 24, + "parent_id": 12, + "name": "器材列表", + "kind": 2, + "link": "list", + "component": "equipment/list", + "icon": "", + "auth": 0, + "sort": 9, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 25, + "parent_id": 13, + "name": "供应商新增", + "kind": 2, + "link": "add", + "component": "supplier/add", + "icon": "", + "auth": 0, + "sort": 10, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 26, + "parent_id": 13, + "name": "供应商列表", + "kind": 2, + "link": "list", + "component": "supplier/list", + "icon": "", + "auth": 0, + "sort": 9, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 27, + "parent_id": 14, + "name": "用户管理", + "kind": 2, + "link": "user", + "component": "system/user", + "icon": "", + "auth": 0, + "sort": 9, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 28, + "parent_id": 14, + "name": "角色管理", + "kind": 2, + "link": "role", + "component": "system/role", + "icon": "", + "auth": 0, + "sort": 8, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 29, + "parent_id": 14, + "name": "部门管理", + "kind": 2, + "link": null, + "component": "system/dept", + "icon": null, + "auth": 0, + "sort": 8, + "remark": null, + "status": 1, + "is_deleted": 1 + }, + { + "id": 30, + "parent_id": 14, + "name": "菜单管理", + "kind": 2, + "link": "menu", + "component": "system/menu", + "icon": "", + "auth": 0, + "sort": 7, + "remark": "", + "status": 1, + "is_deleted": 0 + }, + { + "id": 33, + "parent_id": 10, + "name": "维修工单列表", + "kind": 2, + "link": "repairWorkOrder", + "component": "repair/repairWorkOrder", + "icon": null, + "auth": 0, + "sort": 4, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 34, + "parent_id": 11, + "name": "承修单位新增", + "kind": 2, + "link": "repairAdd", + "component": "catalogue/repairAdd", + "icon": null, + "auth": 0, + "sort": 8, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 35, + "parent_id": 11, + "name": "承修单位", + "kind": 2, + "link": "repairList", + "component": "catalogue/repairList", + "icon": null, + "auth": 0, + "sort": 7, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 36, + "parent_id": 11, + "name": "承制单位新增", + "kind": 2, + "link": "systemAdd", + "component": "catalogue/systemAdd", + "icon": null, + "auth": 0, + "sort": 6, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 37, + "parent_id": 11, + "name": "承制单位", + "kind": 2, + "link": "systemList", + "component": "catalogue/systemList", + "icon": null, + "auth": 0, + "sort": 5, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 38, + "parent_id": 14, + "name": "单位管理", + "kind": 2, + "link": "dept", + "component": "system/dept", + "icon": null, + "auth": 0, + "sort": 10, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 39, + "parent_id": 14, + "name": "通知列表", + "kind": 2, + "link": "notice", + "component": "system/notice", + "icon": null, + "auth": 0, + "sort": 6, + "remark": null, + "status": 1, + "is_deleted": 0 + }, + { + "id": 40, + "parent_id": 14, + "name": "故障库", + "kind": 2, + "link": "fault", + "component": "system/fault", + "icon": null, + "auth": 0, + "sort": 5, + "remark": null, + "status": 1, + "is_deleted": 0 + } + ] +} \ No newline at end of file diff --git a/lib/config_test.go b/lib/config_test.go deleted file mode 100644 index d52ab19..0000000 --- a/lib/config_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package lib - -import ( - "ArmedPolice/utils" - "testing" -) - -type ( - structForSysConfig struct { - ID uint64 `json:"id"` - Kind int `json:"kind"` - Name string `json:"name"` - Key string `json:"key"` - Value string `json:"value"` - IsDeleted int `json:"is_deleted"` - } - structForSysMenu struct { - ID int `json:"id"` - ParentId int `json:"parent_id"` - Name string `json:"name"` - Kind int `json:"kind"` - Link string `json:"link"` - Component string `json:"component"` - Icon string `json:"icon"` - Auth int `json:"auth"` - Sort int `json:"sort"` - Remark string `json:"remark"` - Status int `json:"status"` - IsDeleted int `json:"is_deleted"` - } -) - -func TestLoadConfig(t *testing.T) { - values := make([]*structForSysMenu, 0) - LoadConfig("../json/sys_menu.json", &values) - t.Log(utils.AnyToJSON(values)) -} diff --git a/router/router.go b/router/router.go index 910df8c..9d32639 100644 --- a/router/router.go +++ b/router/router.go @@ -43,7 +43,6 @@ func (this *Router) registerWeb() { func (this *Router) registerAPI() { apiPrefix := "/api" g := this.handler.Group(apiPrefix) - g.Use() // 登录验证 g.Use(NeedLogin(AddSkipperURL([]string{ apiPrefix + "/v1/account/login", diff --git a/lib/config.go b/utils/load.go similarity index 98% rename from lib/config.go rename to utils/load.go index 5e2ecf7..5c98c69 100644 --- a/lib/config.go +++ b/utils/load.go @@ -1,4 +1,4 @@ -package lib +package utils import ( "encoding/json"