mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-23 21:28:14 -05:00
d9097540c3
* server-status主题优化 1.前台增加半透明样式切换按钮,同时适配了深色和浅色模式 2.右小角功能区增加收纳,点击展开,滚动页面关闭 3.vps世界分布地图全屏展示 4.修改默认页底版权信息位置,从跟随container box修改为默认置于页面底部,container box到底底部后再跟随 5.修改container box默认宽度和最大宽度,适配高分辨率显示器 6.优化样式文件结构,删除无用的样式文件 7.一些小优化 * 修改默认背景图 * 修改背景图片 * 1.echart图表适配半透明样式切换 2.echart图表移动端设置更细折线 3.修改半透明样式下的默认背景图 * echart Y轴移动端更细刻度线 * fixbug * 修改半透明样式默认背景图片为本地调用
153 lines
5.6 KiB
JavaScript
Vendored
153 lines
5.6 KiB
JavaScript
Vendored
const mixinsVue = {
|
|
data: {
|
|
cache: [],
|
|
isMobile: false,
|
|
theme: "light",
|
|
isSystemTheme: false,
|
|
showGroup: false,
|
|
showGoTop: false,
|
|
showTools: false,
|
|
preferredTemplate: null,
|
|
semiTransparent: false,
|
|
staticUrl: '/static/theme-server-status',
|
|
adaptedTemplates: [
|
|
{ key: 'default', name: 'Default', icon: 'th large' },
|
|
{ key: 'angel-kanade', name: 'AngelKanade', icon: 'square' },
|
|
{ key: 'server-status', name: 'ServerStatus', icon: 'list' }
|
|
]
|
|
},
|
|
created() {
|
|
this.isMobile = this.checkIsMobile();
|
|
this.theme = this.initTheme();
|
|
this.showGroup = this.initShowGroup();
|
|
this.semiTransparent = this.initSemiTransparent();
|
|
this.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : this.$root.defaultTemplate;
|
|
window.addEventListener('scroll', this.handleScroll);
|
|
},
|
|
destroyed() {
|
|
window.removeEventListener('scroll', this.handleScroll);
|
|
},
|
|
methods: {
|
|
toggleTemplate(template) {
|
|
if( template != this.preferredTemplate){
|
|
this.preferredTemplate = template;
|
|
this.updateCookie("preferred_theme", template);
|
|
window.location.reload();
|
|
}
|
|
},
|
|
toggleShowTools() {
|
|
this.showTools = !this.showTools;
|
|
},
|
|
initTheme() {
|
|
const storedTheme = localStorage.getItem("theme");
|
|
const theme = (storedTheme === 'dark' || storedTheme === 'light') ? storedTheme : (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
this.setTheme(theme);
|
|
return theme;
|
|
},
|
|
setTheme(theme) {
|
|
document.body.setAttribute("theme", theme);
|
|
this.theme = theme;
|
|
localStorage.setItem("theme", theme);
|
|
// 重新赋值全局调色
|
|
this.colors = this.theme == "dark" ? this.colorsDark : this.colorsLight;
|
|
|
|
if(this.$root.page == 'index') {
|
|
this.reloadCharts(); // 重新载入echarts图表
|
|
}
|
|
},
|
|
initShowGroup() {
|
|
const storedShowGroup = localStorage.getItem("showGroup");
|
|
const showGroup = storedShowGroup !== null ? JSON.parse(storedShowGroup) : false;
|
|
if (storedShowGroup === null) {
|
|
localStorage.setItem("showGroup", showGroup);
|
|
}
|
|
return showGroup;
|
|
},
|
|
toggleShowGroup() {
|
|
this.showGroup = !this.showGroup;
|
|
localStorage.setItem("showGroup", this.showGroup);
|
|
if (this.$root.page == 'service') {
|
|
this.$root.initTooltip();
|
|
}
|
|
},
|
|
initSemiTransparent() {
|
|
const storedSemiTransparent = localStorage.getItem("semiTransparent");
|
|
const semiTransparent = storedSemiTransparent !== null ? JSON.parse(storedSemiTransparent) : false;
|
|
if (storedSemiTransparent === null) {
|
|
localStorage.setItem("semiTransparent", semiTransparent);
|
|
}
|
|
return semiTransparent;
|
|
},
|
|
toggleSemiTransparent(){
|
|
this.semiTransparent = !this.semiTransparent;
|
|
localStorage.setItem("semiTransparent", this.semiTransparent);
|
|
if(this.$root.page == 'index') {
|
|
this.reloadCharts(); // 重新载入echarts图表
|
|
}
|
|
},
|
|
updateCookie(name, value) {
|
|
document.cookie = name + "=" + value +"; path=/";
|
|
},
|
|
getCookie(name) {
|
|
const cookies = document.cookie.split(';');
|
|
let cookieValue = null;
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i].trim();
|
|
if (cookie.startsWith(name + '=')) {
|
|
cookieValue = cookie.substring(name.length + 1, cookie.length);
|
|
break;
|
|
}
|
|
}
|
|
return cookieValue;
|
|
},
|
|
toFixed2(f) {
|
|
return f.toFixed(2)
|
|
},
|
|
logOut(id) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/api/logout',
|
|
data: JSON.stringify({ id: id }),
|
|
contentType: 'application/json',
|
|
success: function (resp) {
|
|
if (resp.code == 200) {
|
|
window.location.reload();
|
|
} else {
|
|
alert('注销失败(Error ' + resp.code + '): ' + resp.message);
|
|
}
|
|
},
|
|
error: function (err) {
|
|
alert('网络错误: ' + err.responseText);
|
|
}
|
|
});
|
|
},
|
|
goTop() {
|
|
$('html, body').animate({ scrollTop: 0 }, 400);
|
|
return false;
|
|
},
|
|
handleScroll() {
|
|
this.showGoTop = window.scrollY >= 100;
|
|
if(this.showTools) this.showTools = false;
|
|
},
|
|
groupingData(data, field) {
|
|
let map = new Map();
|
|
let dest = [];
|
|
|
|
data.forEach(item => {
|
|
if (!map.has(item[field])) {
|
|
dest.push({
|
|
[field]: item[field],
|
|
data: [item]
|
|
});
|
|
map.set(item[field], item);
|
|
} else {
|
|
dest.find(dItem => dItem[field] === item[field]).data.push(item);
|
|
}
|
|
});
|
|
return dest;
|
|
},
|
|
checkIsMobile() { // 检测设备类型,页面宽度小于768px认为是移动设备
|
|
return window.innerWidth <= 768;
|
|
}
|
|
}
|
|
} |