管理界面可以切换风格
This commit is contained in:
@@ -44,6 +44,7 @@ func loadAdminModuleMapping() (map[int64]*AdminModuleList, error) {
|
||||
list := &AdminModuleList{
|
||||
IsSuper: m.IsSuper,
|
||||
Fullname: m.Fullname,
|
||||
Theme: m.Theme,
|
||||
}
|
||||
|
||||
for _, pbModule := range m.Modules {
|
||||
@@ -132,6 +133,29 @@ func FindAdminFullname(adminId int64) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// FindAdminTheme 查找某个管理员选择的风格
|
||||
func FindAdminTheme(adminId int64) string {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
|
||||
list, ok := sharedAdminModuleMapping[adminId]
|
||||
if ok {
|
||||
return list.Theme
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// UpdateAdminTheme 设置某个管理员的风格
|
||||
func UpdateAdminTheme(adminId int64, theme string) {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
|
||||
list, ok := sharedAdminModuleMapping[adminId]
|
||||
if ok {
|
||||
list.Theme = theme
|
||||
}
|
||||
}
|
||||
|
||||
// AllModuleMaps 所有权限列表
|
||||
func AllModuleMaps() []maps.Map {
|
||||
m := []maps.Map{
|
||||
|
||||
@@ -6,6 +6,7 @@ type AdminModuleList struct {
|
||||
IsSuper bool
|
||||
Modules []*systemconfigs.AdminModule
|
||||
Fullname string
|
||||
Theme string
|
||||
}
|
||||
|
||||
func (this *AdminModuleList) Allow(module string) bool {
|
||||
|
||||
@@ -70,7 +70,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
// 提交
|
||||
// RunPost 提交
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
Token string
|
||||
Username string
|
||||
|
||||
@@ -29,6 +29,7 @@ func init() {
|
||||
Post("/eventLevelOptions", new(EventLevelOptionsAction)).
|
||||
Post("/showTip", new(ShowTipAction)).
|
||||
Post("/hideTip", new(HideTipAction)).
|
||||
Post("/theme", new(ThemeAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
|
||||
47
internal/web/actions/default/ui/theme.go
Normal file
47
internal/web/actions/default/ui/theme.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type ThemeAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ThemeAction) RunPost(params struct{}) {
|
||||
theme := configloaders.FindAdminTheme(this.AdminId())
|
||||
|
||||
var themes = []string{"theme1", "theme2", "theme3"}
|
||||
var nextTheme = "theme1"
|
||||
if len(theme) == 0 {
|
||||
nextTheme = "theme2"
|
||||
} else {
|
||||
for index, t := range themes {
|
||||
if t == theme {
|
||||
if index < len(themes)-1 {
|
||||
nextTheme = themes[index+1]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err := this.RPC().AdminRPC().UpdateAdminTheme(this.AdminContext(), &pb.UpdateAdminThemeRequest{
|
||||
AdminId: this.AdminId(),
|
||||
Theme: nextTheme,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
configloaders.UpdateAdminTheme(this.AdminId(), nextTheme)
|
||||
|
||||
this.Data["theme"] = nextTheme
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -91,6 +91,7 @@ func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
|
||||
action.Data["teaFaviconFileId"] = config.FaviconFileId
|
||||
action.Data["teaLogoFileId"] = config.LogoFileId
|
||||
action.Data["teaUsername"] = configloaders.FindAdminFullname(adminId)
|
||||
action.Data["teaTheme"] = configloaders.FindAdminTheme(adminId)
|
||||
|
||||
action.Data["teaUserAvatar"] = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user