mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-23 13:18:13 -05:00
f4c6f4c57d
* ServerStatus主题优化 1.更新世界地图基础geo文件,中国部分包含南海10段线,藏南部分划线更准 geo在大佬仓库https://github.com/Surbowl/world-geo-json-zh的基础上加工 2.世界地图可以在后台设置自定义代码切换是否包含南极洲,中国港澳台是否单独统计vps数 ```<script> localStorage.setItem('countryMapGeoFile', 'nezha.world.geo.json'); //默认 // localStorage.setItem('countryMapGeoFile', 'nezha.world.plus.geo.json'); //单独绘制香港,澳门,台湾 // localStorage.setItem('countryMapGeoFile', 'nezha.world.antarctica.geo.json'); //有南极洲 // localStorage.setItem('countryMapGeoFile', 'nezha.world.plus.antarctica.geo.json'); //有南极洲,单独绘制香港,澳门,台湾 </script> ``` 3. mixin.js文件删除冗余代码 4. 首页agent下拉详情,控制网络折线图tooltip数字最多显示小数点后两位 * 修正geo文件路径 * 修复世界地图中国港澳台单独绘制时,vps数量计算逻辑 * 删除header中的无用的地图基础数据引用 * 增加温度控制cpu型号识别
124 lines
4.4 KiB
JavaScript
Vendored
124 lines
4.4 KiB
JavaScript
Vendored
const mixinsVue = {
|
|
data: {
|
|
cache: [],
|
|
theme: "light",
|
|
isSystemTheme: false,
|
|
showGroup: false,
|
|
showGoTop: false,
|
|
preferredTemplate: null,
|
|
isMobile: 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.preferredTemplate = this.getCookie('preferred_theme') ? this.getCookie('preferred_theme') : this.$root.defaultTemplate;
|
|
window.addEventListener('scroll', this.handleScroll);
|
|
},
|
|
destroyed() {
|
|
window.removeEventListener('scroll', this.handleScroll);
|
|
},
|
|
methods: {
|
|
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();
|
|
}
|
|
},
|
|
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;
|
|
},
|
|
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;
|
|
}
|
|
}
|
|
} |