From ceda446c1af7260ed040e9dabd14ae77f6fe0b98 Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 14 Jul 2024 23:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device/menu.go | 16 ++++++++++++++++ gateway/menu.go | 15 +++++++++++++++ menu/api.go | 24 ++++++++++++++++++++++++ menu/menu.go | 29 +++++++++++++++++++++++++++++ package.json | 46 +++++++++++++++++++--------------------------- product/menu.go | 16 ++++++++++++++++ project/menu.go | 26 ++++++++++++++++++++++++++ space/menu.go | 16 ++++++++++++++++ user/menu.go | 16 ++++++++++++++++ 9 files changed, 177 insertions(+), 27 deletions(-) create mode 100644 device/menu.go create mode 100644 gateway/menu.go create mode 100644 menu/api.go create mode 100644 menu/menu.go create mode 100644 product/menu.go create mode 100644 project/menu.go create mode 100644 space/menu.go create mode 100644 user/menu.go diff --git a/device/menu.go b/device/menu.go new file mode 100644 index 00000000..0d42dbfe --- /dev/null +++ b/device/menu.go @@ -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"}, + }, + }) +} diff --git a/gateway/menu.go b/gateway/menu.go new file mode 100644 index 00000000..c1c471e5 --- /dev/null +++ b/gateway/menu.go @@ -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"}, + }, + }) +} diff --git a/menu/api.go b/menu/api.go new file mode 100644 index 00000000..db7368da --- /dev/null +++ b/menu/api.go @@ -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) +} diff --git a/menu/menu.go b/menu/menu.go new file mode 100644 index 00000000..db4aebe0 --- /dev/null +++ b/menu/menu.go @@ -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) +} diff --git a/package.json b/package.json index cfc4ec08..4187436d 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/product/menu.go b/product/menu.go new file mode 100644 index 00000000..2bb74c5a --- /dev/null +++ b/product/menu.go @@ -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"}, + }, + }) +} diff --git a/project/menu.go b/project/menu.go new file mode 100644 index 00000000..2482ff86 --- /dev/null +++ b/project/menu.go @@ -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"}, + }, + }) +} diff --git a/space/menu.go b/space/menu.go new file mode 100644 index 00000000..f057a977 --- /dev/null +++ b/space/menu.go @@ -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"}, + }, + }) +} diff --git a/user/menu.go b/user/menu.go new file mode 100644 index 00000000..8faefda8 --- /dev/null +++ b/user/menu.go @@ -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"}, + }, + }) +}