Skip to content

Commit ab39782

Browse files
authored
fix bug (#328)
* fix bugs 1. 修复default主题mixin.js文件丢失 2. 修复主题默认值为后台设置值 3. default主题样式优化 * 修复前台切换 theme-custom 不生效
1 parent e24925b commit ab39782

File tree

16 files changed

+104
-15
lines changed

16 files changed

+104
-15
lines changed

pkg/mygin/preferred_theme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func PreferredTheme(c *gin.Context) {
1414
if theme, err := c.Cookie("preferred_theme"); err == nil {
1515
if _, has := model.Themes[theme]; has {
1616
// 检验自定义主题
17-
if theme == "custom" && singleton.Conf.Site.Theme != "custom" && !utils.IsFileExists("resource/template/custom/home.html") {
17+
if theme == "custom" && singleton.Conf.Site.Theme != "custom" && !utils.IsFileExists("resource/template/theme-custom/home.html") {
1818
return
1919
}
2020
c.Set(model.CtxKeyPreferredTheme, theme)

resource/l10n/en-US.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ other = "Virtualization"
398398
other = "Swap"
399399

400400
[NetTransfer]
401-
other = "Network Transfer"
401+
other = "Transfer"
402402

403403
[Load]
404404
other = "Load"
@@ -419,7 +419,7 @@ other = "Last Active"
419419
other = "Version"
420420

421421
[NetSpeed]
422-
other = "Network Speed"
422+
other = "Speed"
423423

424424
[Uptime]
425425
other = "Uptime"
@@ -627,3 +627,6 @@ other = "Feature"
627627

628628
[Template]
629629
other = "Template"
630+
631+
[Stat]
632+
other = "Stat"

resource/l10n/es-ES.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,6 @@ other = "Característica"
627627

628628
[Template]
629629
other = "Plantilla"
630+
631+
[Stat]
632+
other = "Stat"

resource/l10n/zh-CN.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,6 @@ other = "功能"
627627

628628
[Template]
629629
other = "主题"
630+
631+
[Stat]
632+
other = "信息"

resource/l10n/zh-TW.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,6 @@ other = "功能"
627627

628628
[Template]
629629
other = "主題"
630+
631+
[Stat]
632+
other = "信息"

resource/static/theme-default/css/main.css

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,35 @@ td {
8686
margin-right: 0;
8787
}
8888

89+
.ui.grid {
90+
margin-bottom:-0.5em
91+
}
92+
93+
.ui.card>.content>.header:not(.ui), .ui.cards>.card>.content>.header:not(.ui){
94+
line-height: 1em;
95+
}
96+
8997
.status.cards .wide.column {
9098
padding-top: 0 !important;
9199
padding-bottom: 0 !important;
92-
height:3.3rem !important;
100+
height:2.3rem !important;
93101
}
94102

95103
.status.cards .wide.column:nth-child(1) {
96-
margin-top:2rem !important;
104+
margin-top:1.2rem !important;
97105
}
98106

99107
.status.cards .wide.column:nth-child(2) {
100-
margin-top:2rem !important;
108+
margin-top:1.2rem !important;
109+
}
110+
111+
.status.cards .three.wide.column {
112+
text-align: center;
113+
width: 22%!important;
101114
}
102115

103116
.status.cards .thirteen.wide.column{
117+
width: 78%!important;
104118
padding-left:0;
105119
}
106120

@@ -124,7 +138,7 @@ td {
124138
.closePopup{
125139
color:rgb(10, 148, 242) !important;
126140
position: absolute;
127-
top: 10px;
141+
top: 7px;
128142
right: 10px;
129143
cursor: pointer;
130144
z-index: 9999;
@@ -194,6 +208,7 @@ td {
194208
}
195209

196210
.nezha-secondary-font {
211+
height: 1em;
197212
color: rgb(10, 148, 242) !important;
198213
}
199214

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const mixinsVue = {
2+
delimiters: ['@#', '#@'],
3+
data: {
4+
preferredTemplate: null,
5+
isMobile: false
6+
},
7+
created() {
8+
this.isMobile = this.checkIsMobile();
9+
this.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : this.$root.defaultTemplate;
10+
},
11+
methods: {
12+
toggleTemplate(template) {
13+
if( template != this.preferredTemplate){
14+
this.preferredTemplate = template;
15+
this.updateCookie("preferred_theme", template);
16+
window.location.reload();
17+
}
18+
},
19+
updateCookie(name, value) {
20+
document.cookie = name + "=" + value +"; path=/";
21+
},
22+
getCookie(name) {
23+
const cookies = document.cookie.split(';');
24+
let cookieValue = null;
25+
for (let i = 0; i < cookies.length; i++) {
26+
const cookie = cookies[i].trim();
27+
if (cookie.startsWith(name + '=')) {
28+
cookieValue = cookie.substring(name.length + 1, cookie.length);
29+
break;
30+
}
31+
}
32+
return cookieValue;
33+
},
34+
checkIsMobile() { // 检测设备类型,页面宽度小于768px认为是移动设备
35+
return window.innerWidth <= 768;
36+
},
37+
logOut(id) {
38+
$.ajax({
39+
type: 'POST',
40+
url: '/api/logout',
41+
data: JSON.stringify({ id: id }),
42+
contentType: 'application/json',
43+
success: function (resp) {
44+
if (resp.code == 200) {
45+
window.location.reload();
46+
} else {
47+
alert('注销失败(Error ' + resp.code + '): ' + resp.message);
48+
}
49+
},
50+
error: function (err) {
51+
alert('网络错误: ' + err.responseText);
52+
}
53+
});
54+
}
55+
}
56+
}

resource/static/theme-server-status/js/mixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const mixinsVue = {
55
isSystemTheme: false,
66
showGroup: false,
77
showGoTop: false,
8-
preferredTemplate: 'default',
8+
preferredTemplate: null,
99
isMobile: false
1010
},
1111
created() {
1212
this.isMobile = this.checkIsMobile();
1313
this.initTheme();
1414
this.storedShowGroup();
15-
this.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : 'default';
15+
this.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : this.$root.defaultTemplate;
1616
window.addEventListener('scroll', this.handleScroll);
1717
},
1818
destroyed() {

resource/template/theme-default/header.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.min.css">
1313
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.0.0/css/flag-icons.min.css">
1414
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
15-
<link rel="stylesheet" type="text/css" href="/static/theme-default/css/main.css?v20240222">
15+
<link rel="stylesheet" type="text/css" href="/static/theme-default/css/main.css?v20240226">
1616
<link rel="shortcut icon" type="image/png" href="/static/logo.svg" />
1717
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
1818
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.1/dist/semantic.min.js"></script>
1919
<script src="/static/semantic-ui-alerts.min.js"></script>
2020
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
2121
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
22-
<script src="/static/theme-server-status/js/mixin.js?v20240225"></script>
22+
<script src="/static/theme-default/js/mixin.js?v20240226"></script>
2323
</head>
2424
<body>
2525
{{end}}

resource/template/theme-default/home.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class="apple icon"></i><i v-else-if='isWindowsPlatform(server.Host.Platform)'
2020
class="windows icon"></i><i v-else :class="'fl-' + getFontLogoClass(server.Host.Platform)"></i>
2121
@#server.Name + (server.live?'':'[{{tr "Offline"}}]')#@
22-
<i @click="togglePopup($event, server.ID)" aria-expanded="false" class="nezha-secondary-font info circle icon" style="height: 28px"></i>
22+
<i @click="togglePopup($event, server.ID)" aria-expanded="false" class="nezha-secondary-font info circle icon"></i>
2323
<div class="ui content popup" :class="{ 'visible': isActive(server.ID) }" style="margin-bottom: 0;">
2424
<i class="closePopup window close icon" @click="closePopup(server.ID)"></i>
2525
{{tr "Platform"}}: @#server.Host.Platform#@-@#server.Host.PlatformVersion#@
@@ -90,15 +90,15 @@
9090
<i class="arrow alternate circle up outline icon"></i>
9191
@#formatByteSize(server.State.NetOutSpeed)#@/s
9292
</div>
93-
<div class="three wide column">流量</div>
93+
<div class="three wide column">{{tr "NetTransfer"}}</div>
9494
<div class="thirteen wide column">
9595
<i class="arrow circle down icon"></i>
9696
@#formatByteSize(server.State.NetInTransfer)#@
9797
&nbsp;
9898
<i class="arrow circle up icon"></i>
9999
@#formatByteSize(server.State.NetOutTransfer)#@
100100
</div>
101-
<div class="three wide column">信息</div>
101+
<div class="three wide column">{{tr "Stat"}}</div>
102102
<div class="thirteen wide column">
103103
<i class="bi bi-cpu-fill" style="font-size: 1.1rem; color: #4a86e8;"></i> @#getCoreAndGHz(server.Host.CPU)#@
104104
&nbsp;
@@ -138,6 +138,7 @@
138138
delimiters: ['@#', '#@'],
139139
data: {
140140
page: 'index',
141+
defaultTemplate: {{.Conf.Site.Theme}},
141142
templates: {{.Themes}},
142143
data: [],
143144
groups: [],

resource/template/theme-default/network.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
delimiters: ['@#', '#@'],
3737
data: {
3838
page: 'network',
39+
defaultTemplate: {{.Conf.Site.Theme}},
3940
templates: {{.Themes}},
4041
servers: initData,
4142
option: {

resource/template/theme-default/service.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ <h2 style="text-align: center;">{{tr "CycleTransferStats"}}</h2>
8787
delimiters: ['@#', '#@'],
8888
data: {
8989
page: 'service',
90+
defaultTemplate: {{.Conf.Site.Theme}},
9091
templates: {{.Themes}}
9192
},
9293
mixins: [mixinsVue]

resource/template/theme-server-status/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js"></script>
2929
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
3030
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
31-
<script src="/static/theme-server-status/js/mixin.js?v20240225"></script>
31+
<script src="/static/theme-server-status/js/mixin.js?v20240226"></script>
3232
</head>
3333
<body>
3434
{{end}}

resource/template/theme-server-status/home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
delimiters: ['@#', '#@'],
2323
data: {
2424
page: 'index',
25+
defaultTemplate: {{.Conf.Site.Theme}},
2526
templates: {{.Themes}},
2627
nodesTag: [],
2728
nodesNoTag: [],

resource/template/theme-server-status/network.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
delimiters: ['@#', '#@'],
3131
data: {
3232
page: 'network',
33+
defaultTemplate: {{.Conf.Site.Theme}},
3334
templates: {{.Themes}},
3435
servers: initData,
3536
option: {

resource/template/theme-server-status/service.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
delimiters: ['@#', '#@'],
7979
data: {
8080
page: 'service',
81+
defaultTemplate: {{.Conf.Site.Theme}},
8182
templates: {{.Themes}},
8283
servicesTag: [],
8384
servicesNoTag: [],

0 commit comments

Comments
 (0)