mirror of
https://github.com/alireza0/x-ui.git
synced 2026-06-28 19:50:48 +00:00
42 lines
No EOL
1.3 KiB
HTML
42 lines
No EOL
1.3 KiB
HTML
{{define "component/themeSwitchTemplate"}}
|
|
<template>
|
|
<a-tooltip :title="themeSwitcher.isDarkTheme ? 'Dark Mode' : 'Light Mode'">
|
|
<a-icon type="bulb"
|
|
:theme="themeSwitcher.isDarkTheme ? 'filled' : 'outlined'"
|
|
style="font-size: 1rem; margin-right: .5rem;"
|
|
@click="themeSwitcher.toggleTheme()" />
|
|
</a-tooltip>
|
|
</template>
|
|
{{end}}
|
|
|
|
{{define "component/themeSwitcher"}}
|
|
<script>
|
|
function createThemeSwitcher() {
|
|
const isDarkTheme = localStorage.getItem('dark-mode') === 'true';
|
|
const theme = isDarkTheme ? 'dark' : 'light';
|
|
return {
|
|
isDarkTheme,
|
|
get currentTheme() {
|
|
return this.isDarkTheme ? 'dark' : 'light';
|
|
},
|
|
toggleTheme() {
|
|
this.isDarkTheme = !this.isDarkTheme;
|
|
localStorage.setItem('dark-mode', this.isDarkTheme);
|
|
document.getElementById('message').className = themeSwitcher.currentTheme;
|
|
},
|
|
};
|
|
}
|
|
|
|
const themeSwitcher = createThemeSwitcher();
|
|
|
|
Vue.component('theme-switch', {
|
|
props: [],
|
|
template: `{{template "component/themeSwitchTemplate"}}`,
|
|
data: () => ({ themeSwitcher }),
|
|
mounted() {
|
|
this.$message.config({getContainer: () => document.getElementById('message')});
|
|
document.getElementById('message').className = themeSwitcher.currentTheme;
|
|
}
|
|
});
|
|
</script>
|
|
{{end}} |