mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-06 05:30:05 +00:00
✨ feat: add server-status theme (#295)
* ✨ feat: add server-status theme * add `ServerStatus` theme to README --------- Co-authored-by: naiba <hi@nai.ba>
This commit is contained in:
49
resource/static/theme-server-status/js/mixin.js
vendored
Normal file
49
resource/static/theme-server-status/js/mixin.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
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)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user