-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
177 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | ||
}, | ||
}) | ||
} |