mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-23 13:18:13 -05:00
470fa69ad9
* ✨ feat: add server-status theme
* add `ServerStatus` theme to README
---------
Co-authored-by: naiba <hi@nai.ba>
49 lines
1.6 KiB
JavaScript
Vendored
49 lines
1.6 KiB
JavaScript
Vendored
const mixinsVue = {
|
|
data: {
|
|
cache: [],
|
|
theme: "light",
|
|
isSystemTheme: false
|
|
},
|
|
created() {
|
|
this.initTheme()
|
|
},
|
|
methods: {
|
|
setTheme(title, store = false) {
|
|
this.theme = title
|
|
document.body.setAttribute("theme", title)
|
|
if (store) {
|
|
localStorage.setItem("theme", title)
|
|
this.isSystemTheme = false
|
|
}
|
|
},
|
|
setSystemTheme() {
|
|
localStorage.removeItem("theme")
|
|
this.initTheme()
|
|
this.isSystemTheme = true
|
|
},
|
|
initTheme() {
|
|
const storeTheme = localStorage.getItem("theme")
|
|
if (storeTheme === 'dark' || storeTheme === 'light') {
|
|
this.setTheme(storeTheme, true);
|
|
} else {
|
|
this.isSystemTheme = true
|
|
const handleChange = (mediaQueryListEvent) => {
|
|
if (localStorage.getItem("theme")) {
|
|
return
|
|
}
|
|
if (mediaQueryListEvent.matches) {
|
|
this.setTheme('dark');
|
|
} else {
|
|
this.setTheme('light');
|
|
}
|
|
}
|
|
const mediaQueryListDark = window.matchMedia('(prefers-color-scheme: dark)');
|
|
this.setTheme(mediaQueryListDark.matches ? 'dark' : 'light');
|
|
mediaQueryListDark.addEventListener("change", handleChange);
|
|
}
|
|
},
|
|
toFixed2(f) {
|
|
return f.toFixed(2)
|
|
},
|
|
}
|
|
} |