Skip to content

Commit

Permalink
菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
zgwit committed Jul 14, 2024
1 parent 803b84a commit ceda446
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 27 deletions.
16 changes: 16 additions & 0 deletions device/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package device

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("device", &menu.Menu{
Name: "设备管理",
Icon: "block",
Domain: []string{"admin", "project"},
Privileges: nil,
Items: []*menu.Item{
{Name: "所有设备", Url: "device", Type: "route"},
{Name: "创建设备", Url: "device/create", Type: "route"},
},
})
}
15 changes: 15 additions & 0 deletions gateway/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gateway

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("broker", &menu.Menu{
Name: "MQTT服务器",
Icon: "cluster",
Domain: []string{"admin"},
Privileges: nil,
Items: []*menu.Item{
{Name: "网关", Url: "gateway", Type: "route"},
},
})
}
24 changes: 24 additions & 0 deletions menu/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package menu

import (
"github.com/gin-gonic/gin"
"github.com/god-jason/bucket/api"
"slices"
)

func init() {
api.Register("GET", "/menu/:domain", menuGet)
}

func menuGet(ctx *gin.Context) {
domain := ctx.Param("domain")
//TODO 获取用户权限,过滤菜单
var ms []*Menu
menus.Range(func(name string, m *Menu) bool {
if slices.Contains(m.Domain, domain) {
ms = append(ms, m)
}
return true
})
api.OK(ctx, ms)
}
29 changes: 29 additions & 0 deletions menu/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package menu

import "github.com/god-jason/bucket/lib"

type Menu struct {
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
Domain []string `json:"domain"` //域 admin project 或 dealer等
Privileges []string `json:"privileges,omitempty"`
Items []*Item `json:"items"`
}

type Item struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"` //route 路由, web 嵌入web, window 独立弹出
Url string `json:"url,omitempty"`
Query map[string]any `json:"query,omitempty"`
Privileges []string `json:"privileges,omitempty"`
}

var menus lib.Map[Menu]

func Register(name string, menu *Menu) {
menus.Store(name, menu)
}

func Unregister(name string) {
menus.Delete(name)
}
46 changes: 19 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,28 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^17.3.5",
"@angular/common": "^17.3.5",
"@angular/compiler": "^17.3.5",
"@angular/core": "^17.3.5",
"@angular/forms": "^17.3.5",
"@angular/platform-browser": "^17.3.5",
"@angular/platform-browser-dynamic": "^17.3.5",
"@angular/router": "^17.3.5",
"dayjs": "^1.11.10",
"echarts": "^5.5.0",
"iot-master-smart": "^0.1.6",
"ng-zorro-antd": "^17.4.0",
"ngx-echarts": "^17.1.0",
"@angular/animations": "^18.1.0",
"@angular/common": "^18.1.0",
"@angular/compiler": "^18.1.0",
"@angular/core": "^18.1.0",
"@angular/forms": "^18.1.0",
"@angular/platform-browser": "^18.1.0",
"@angular/platform-browser-dynamic": "^18.1.0",
"@angular/router": "^18.1.0",
"@god-jason/smart": "^1.0.6",
"dayjs": "^1.11.11",
"ng-zorro-antd": "^18.0.1",
"ngx-echarts": "^18.0.0",
"rxjs": "~7.8.1",
"ts-md5": "^1.3.1",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
"tslib": "^2.6.3",
"zone.js": "~0.14.7"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.3.5",
"@angular/cli": "^17.3.5",
"@angular/compiler-cli": "^17.3.5",
"@types/jasmine": "~5.1.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"ng-packagr": "^17.2.0",
"typescript": "~5.4.2"
"@angular-devkit/build-angular": "^18.1.0",
"@angular/cli": "^18.1.0",
"@angular/compiler-cli": "^18.1.0",
"ng-packagr": "^18.1.0",
"typescript": "~5.5.0"
}
}
16 changes: 16 additions & 0 deletions product/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package product

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("product", &menu.Menu{
Name: "产品管理",
Icon: "profile",
Domain: []string{"admin"},
Privileges: nil,
Items: []*menu.Item{
{Name: "所有产品", Url: "product", Type: "route"},
{Name: "创建产品", Url: "product/create", Type: "route"},
},
})
}
26 changes: 26 additions & 0 deletions project/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package project

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("project", &menu.Menu{
Name: "项目管理",
Icon: "apartment",
Domain: []string{"admin"},
Privileges: nil,
Items: []*menu.Item{
{Name: "所有项目", Url: "project", Type: "route"},
{Name: "创建项目", Url: "project/create", Type: "route"},
},
})
menu.Register("project-user", &menu.Menu{
Name: "用户管理",
Icon: "user",
Domain: []string{"project"},
Privileges: nil,
Items: []*menu.Item{
{Name: "用户", Url: "user", Type: "route"},
{Name: "角色", Url: "role", Type: "route"},
},
})
}
16 changes: 16 additions & 0 deletions space/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package space

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("space", &menu.Menu{
Name: "空间管理",
Icon: "appstore",
Domain: []string{"project"},
Privileges: nil,
Items: []*menu.Item{
{Name: "所有空间", Url: "space", Type: "route"},
{Name: "创建空间", Url: "space/create", Type: "route"},
},
})
}
16 changes: 16 additions & 0 deletions user/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package user

import "github.com/zgwit/iot-master/v5/menu"

func init() {
menu.Register("user", &menu.Menu{
Name: "用户管理",
Icon: "user",
Domain: []string{"admin"},
Privileges: nil,
Items: []*menu.Item{
{Name: "所有用户", Url: "user", Type: "route"},
{Name: "所有角色", Url: "role", Type: "route"},
},
})
}

0 comments on commit ceda446

Please sign in to comment.