管理界面可以切换风格

This commit is contained in:
GoEdgeLab
2021-07-12 10:21:17 +08:00
parent a0dfda626f
commit 2f0627aa23
12 changed files with 159 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ func loadAdminModuleMapping() (map[int64]*AdminModuleList, error) {
list := &AdminModuleList{ list := &AdminModuleList{
IsSuper: m.IsSuper, IsSuper: m.IsSuper,
Fullname: m.Fullname, Fullname: m.Fullname,
Theme: m.Theme,
} }
for _, pbModule := range m.Modules { for _, pbModule := range m.Modules {
@@ -132,6 +133,29 @@ func FindAdminFullname(adminId int64) string {
return "" 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 所有权限列表 // AllModuleMaps 所有权限列表
func AllModuleMaps() []maps.Map { func AllModuleMaps() []maps.Map {
m := []maps.Map{ m := []maps.Map{

View File

@@ -6,6 +6,7 @@ type AdminModuleList struct {
IsSuper bool IsSuper bool
Modules []*systemconfigs.AdminModule Modules []*systemconfigs.AdminModule
Fullname string Fullname string
Theme string
} }
func (this *AdminModuleList) Allow(module string) bool { func (this *AdminModuleList) Allow(module string) bool {

View File

@@ -70,7 +70,7 @@ func (this *IndexAction) RunGet(params struct {
this.Show() this.Show()
} }
// 提交 // RunPost 提交
func (this *IndexAction) RunPost(params struct { func (this *IndexAction) RunPost(params struct {
Token string Token string
Username string Username string

View File

@@ -29,6 +29,7 @@ func init() {
Post("/eventLevelOptions", new(EventLevelOptionsAction)). Post("/eventLevelOptions", new(EventLevelOptionsAction)).
Post("/showTip", new(ShowTipAction)). Post("/showTip", new(ShowTipAction)).
Post("/hideTip", new(HideTipAction)). Post("/hideTip", new(HideTipAction)).
Post("/theme", new(ThemeAction)).
EndAll() EndAll()
}) })

View 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()
}

View File

@@ -91,6 +91,7 @@ func (this *userMustAuth) BeforeAction(actionPtr actions.ActionWrapper, paramNam
action.Data["teaFaviconFileId"] = config.FaviconFileId action.Data["teaFaviconFileId"] = config.FaviconFileId
action.Data["teaLogoFileId"] = config.LogoFileId action.Data["teaLogoFileId"] = config.LogoFileId
action.Data["teaUsername"] = configloaders.FindAdminFullname(adminId) action.Data["teaUsername"] = configloaders.FindAdminFullname(adminId)
action.Data["teaTheme"] = configloaders.FindAdminTheme(adminId)
action.Data["teaUserAvatar"] = "" action.Data["teaUserAvatar"] = ""

View File

@@ -275,7 +275,7 @@ window.teaweb = {
Swal.fire(config); Swal.fire(config);
}, },
successToast: function (message, timeout) { successToast: function (message, timeout, callback) {
if (timeout == null) { if (timeout == null) {
timeout = 2000 timeout = 2000
} }
@@ -288,7 +288,12 @@ window.teaweb = {
icon: "success", icon: "success",
width: width, width: width,
timer: timeout, timer: timeout,
showConfirmButton: false showConfirmButton: false,
onAfterClose: function () {
if (typeof callback == "function") {
callback()
}
}
}); });
}, },
successRefresh: function (message) { successRefresh: function (message) {

View File

@@ -273,7 +273,6 @@ body.expanded .main {
z-index: 1000; z-index: 1000;
overflow-x: auto; overflow-x: auto;
border: 0 !important; border: 0 !important;
background: #14539A !important;
} }
.top-nav img.avatar { .top-nav img.avatar {
width: 1.6em !important; width: 1.6em !important;
@@ -297,6 +296,15 @@ body.expanded .main {
.top-nav .item.red { .top-nav .item.red {
color: red !important; color: red !important;
} }
.top-nav.theme1 {
background: #14539A !important;
}
.top-nav.theme2 {
background: #276AC6 !important;
}
.top-nav.theme3 {
background: #007D9C !important;
}
.top-nav::-webkit-scrollbar { .top-nav::-webkit-scrollbar {
height: 2px; height: 2px;
} }
@@ -410,14 +418,30 @@ body.expanded .main {
top: 2em; top: 2em;
bottom: 0; bottom: 0;
overflow-y: auto; overflow-y: auto;
background: #14539A !important;
z-index: 10; z-index: 10;
} }
.main-menu .menu { .main-menu .menu {
background: #14539A !important;
border: 0 !important; border: 0 !important;
box-shadow: none !important; box-shadow: none !important;
} }
.main-menu.theme1 {
background: #14539A !important;
}
.main-menu.theme1 .menu {
background: #14539A !important;
}
.main-menu.theme2 {
background: #276AC6 !important;
}
.main-menu.theme2 .menu {
background: #276AC6 !important;
}
.main-menu.theme3 {
background: #007D9C !important;
}
.main-menu.theme3 .menu {
background: #007D9C !important;
}
.main-menu::-webkit-scrollbar { .main-menu::-webkit-scrollbar {
width: 2px; width: 2px;
} }

File diff suppressed because one or more lines are too long

View File

@@ -25,7 +25,7 @@
<div> <div>
<!-- 顶部导航 --> <!-- 顶部导航 -->
<div class="ui menu top-nav blue inverted small borderless" v-cloak=""> <div class="ui menu top-nav blue inverted small borderless" :class="(teaTheme == null || teaTheme.length == 0) ? 'theme1': teaTheme" v-cloak="">
<a href="/" class="item"> <a href="/" class="item">
<i class="ui icon leaf" v-if="teaLogoFileId == 0"></i><img v-if="teaLogoFileId > 0" :src="'/ui/image/' + teaLogoFileId" style="width: auto;height: 1.6em"/> &nbsp; {{teaTitle}}&nbsp;<sup v-if="teaShowVersion">v{{teaVersion}}</sup> &nbsp; <i class="ui icon leaf" v-if="teaLogoFileId == 0"></i><img v-if="teaLogoFileId > 0" :src="'/ui/image/' + teaLogoFileId" style="width: auto;height: 1.6em"/> &nbsp; {{teaTitle}}&nbsp;<sup v-if="teaShowVersion">v{{teaVersion}}</sup> &nbsp;
</a> </a>
@@ -58,6 +58,9 @@
<span class="hover-span"><span class="disabled">{{teaUsername}}</span></span> <span class="hover-span"><span class="disabled">{{teaUsername}}</span></span>
</a> </a>
<!-- 背景颜色 -->
<a href="" class="item" title="点击切换背景颜色" @click.prevent="changeTheme()"><i class="icon adjust"></i></a>
<!-- 退出登录 --> <!-- 退出登录 -->
<a :href="Tea.url('logout')" class="item" title="安全退出登录"><i class="icon sign out"></i> <a :href="Tea.url('logout')" class="item" title="安全退出登录"><i class="icon sign out"></i>
<span class="hover-span"><span class="disabled">退出登录</span></span> <span class="hover-span"><span class="disabled">退出登录</span></span>
@@ -66,7 +69,7 @@
</div> </div>
<!-- 左侧主菜单 --> <!-- 左侧主菜单 -->
<div class="main-menu" v-cloak=""> <div class="main-menu" :class="(teaTheme == null || teaTheme.length == 0) ? 'theme1': teaTheme" v-cloak="">
<div class="ui labeled menu vertical blue inverted tiny borderless"> <div class="ui labeled menu vertical blue inverted tiny borderless">
<div class="item"></div> <div class="item"></div>
<!--<a :href="Tea.url('dashboard')" class="item" :class="{active:teaMenu == 'dashboard'}"> <!--<a :href="Tea.url('dashboard')" class="item" :class="{active:teaMenu == 'dashboard'}">

View File

@@ -21,6 +21,17 @@ Tea.context(function () {
this.loadDNSTasks() this.loadDNSTasks()
}) })
/**
* 切换模板
*/
this.changeTheme = function () {
this.$post("/ui/theme")
.success(function (resp) {
teaweb.successToast("界面风格已切换")
this.teaTheme = resp.data.theme
})
}
/** /**
* 左侧子菜单 * 左侧子菜单
*/ */

View File

@@ -241,7 +241,6 @@ body.expanded .main {
z-index: 1000; z-index: 1000;
overflow-x: auto; overflow-x: auto;
border: 0 !important; border: 0 !important;
background: #14539A !important;
img.avatar { img.avatar {
width: 1.6em !important; width: 1.6em !important;
@@ -279,6 +278,18 @@ body.expanded .main {
} }
} }
.top-nav.theme1 {
background: #14539A !important;
}
.top-nav.theme2 {
background: #276AC6 !important;
}
.top-nav.theme3 {
background: #007D9C !important;
}
.top-nav::-webkit-scrollbar { .top-nav::-webkit-scrollbar {
height: 2px; height: 2px;
} }
@@ -419,16 +430,35 @@ body.expanded .main {
top: 2em; top: 2em;
bottom: 0; bottom: 0;
overflow-y: auto; overflow-y: auto;
background: #14539A !important;
z-index: 10; z-index: 10;
.menu { .menu {
background: #14539A !important;
border: 0 !important; border: 0 !important;
box-shadow: none !important; box-shadow: none !important;
} }
} }
.main-menu.theme1 {
background: #14539A !important;
.menu {
background: #14539A !important;
}
}
.main-menu.theme2 {
background: #276AC6 !important;
.menu {
background: #276AC6 !important;
}
}
.main-menu.theme3 {
background: #007D9C !important;
.menu {
background: #007D9C !important;
}
}
.main-menu::-webkit-scrollbar { .main-menu::-webkit-scrollbar {
width: 2px; width: 2px;
} }