2023-05-08 13:45:08 +00:00
|
|
|
{{define "component/themeSwitchTemplate"}}
|
|
|
|
|
<template>
|
2024-04-20 18:45:36 +00:00
|
|
|
<a-menu :theme="themeSwitcher.currentTheme" mode="inline" selected-keys="">
|
|
|
|
|
<a-sub-menu>
|
|
|
|
|
<span slot="title">
|
2026-02-18 18:07:22 +00:00
|
|
|
<a-icon type="bulb" :theme="themeSwitcher.currentTheme === 'light' ? 'outlined' : 'filled'"></a-icon>
|
2025-03-17 11:26:07 +00:00
|
|
|
<span>{{ i18n "menu.theme" }}</span>
|
2024-04-20 18:45:36 +00:00
|
|
|
</span>
|
2026-02-18 18:07:22 +00:00
|
|
|
<a-menu-item
|
|
|
|
|
id="change-theme"
|
|
|
|
|
class="ant-menu-theme-switch theme-picker-item"
|
|
|
|
|
:style="{ height: 'auto', lineHeight: 'normal', paddingTop: '8px', paddingBottom: '8px' }"
|
|
|
|
|
@mousedown.stop="themeSwitcher.animationsOff()"
|
|
|
|
|
@click.stop>
|
|
|
|
|
<a-radio-group :value="themeSwitcher.selectedTheme" @change="themeSwitcher.selectTheme($event.target.value)" @click.stop>
|
|
|
|
|
<a-space direction="vertical" :size="8">
|
|
|
|
|
<a-radio value="light">Light</a-radio>
|
|
|
|
|
<a-radio value="dark">{{ i18n "menu.dark" }}</a-radio>
|
|
|
|
|
<a-radio value="ultra-dark">{{ i18n "menu.ultraDark" }}</a-radio>
|
|
|
|
|
<a-radio value="cyberpunk">Cyberpunk</a-radio>
|
|
|
|
|
</a-space>
|
|
|
|
|
</a-radio-group>
|
2024-04-20 18:45:36 +00:00
|
|
|
</a-menu-item>
|
|
|
|
|
</a-sub-menu>
|
|
|
|
|
</a-menu>
|
|
|
|
|
</template>
|
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
|
|
{{define "component/themeSwitchTemplateLogin"}}
|
|
|
|
|
<template>
|
2025-04-27 04:22:43 +00:00
|
|
|
<a-space @mousedown="themeSwitcher.animationsOff()" id="change-theme" direction="vertical" :size="10" :style="{ width: '100%' }">
|
2026-02-18 18:07:22 +00:00
|
|
|
<a-radio-group :value="themeSwitcher.selectedTheme" @change="themeSwitcher.selectTheme($event.target.value)">
|
|
|
|
|
<a-space direction="vertical" :size="8">
|
|
|
|
|
<a-radio value="light">Light</a-radio>
|
|
|
|
|
<a-radio value="dark">{{ i18n "menu.dark" }}</a-radio>
|
|
|
|
|
<a-radio value="ultra-dark">{{ i18n "menu.ultraDark" }}</a-radio>
|
|
|
|
|
<a-radio value="cyberpunk">Cyberpunk</a-radio>
|
|
|
|
|
</a-space>
|
|
|
|
|
</a-radio-group>
|
2025-04-01 12:24:03 +00:00
|
|
|
</a-space>
|
2023-05-08 13:45:08 +00:00
|
|
|
</template>
|
|
|
|
|
{{end}}
|
|
|
|
|
|
2025-03-17 11:26:07 +00:00
|
|
|
{{define "component/aThemeSwitch"}}
|
2026-02-18 18:07:22 +00:00
|
|
|
<style>
|
|
|
|
|
.theme-picker-item.ant-menu-item-selected {
|
|
|
|
|
background: transparent !important;
|
|
|
|
|
border-color: transparent !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
2023-05-08 13:45:08 +00:00
|
|
|
<script>
|
|
|
|
|
function createThemeSwitcher() {
|
|
|
|
|
const isDarkTheme = localStorage.getItem('dark-mode') === 'true';
|
2024-02-28 11:05:01 +00:00
|
|
|
const isUltra = localStorage.getItem('isUltraDarkThemeEnabled') === 'true';
|
2026-02-18 18:07:22 +00:00
|
|
|
const isCyberpunk = localStorage.getItem('cyberpunk-mode') === 'true';
|
|
|
|
|
|
|
|
|
|
const selectedTheme = isCyberpunk
|
|
|
|
|
? 'cyberpunk'
|
|
|
|
|
: isUltra
|
|
|
|
|
? 'ultra-dark'
|
|
|
|
|
: isDarkTheme
|
|
|
|
|
? 'dark'
|
|
|
|
|
: 'light';
|
|
|
|
|
|
|
|
|
|
function applyTheme(theme) {
|
|
|
|
|
const body = document.querySelector('body');
|
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
const dark = theme !== 'light';
|
|
|
|
|
const ultra = theme === 'ultra-dark';
|
|
|
|
|
const cyberpunk = theme === 'cyberpunk';
|
|
|
|
|
|
|
|
|
|
body.setAttribute('class', dark ? 'dark' : 'light');
|
|
|
|
|
body.classList.toggle('cyberpunk', cyberpunk);
|
|
|
|
|
|
|
|
|
|
if (ultra) {
|
|
|
|
|
root.setAttribute('data-theme', 'ultra-dark');
|
|
|
|
|
} else {
|
|
|
|
|
root.removeAttribute('data-theme');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localStorage.setItem('dark-mode', dark.toString());
|
|
|
|
|
localStorage.setItem('isUltraDarkThemeEnabled', ultra.toString());
|
|
|
|
|
localStorage.setItem('cyberpunk-mode', cyberpunk.toString());
|
2024-02-28 11:05:01 +00:00
|
|
|
}
|
2026-02-18 18:07:22 +00:00
|
|
|
|
|
|
|
|
applyTheme(selectedTheme);
|
|
|
|
|
|
2023-05-08 13:45:08 +00:00
|
|
|
return {
|
2026-02-18 18:07:22 +00:00
|
|
|
selectedTheme,
|
|
|
|
|
isDarkTheme: selectedTheme !== 'light',
|
|
|
|
|
isUltra: selectedTheme === 'ultra-dark',
|
|
|
|
|
isCyberpunk: selectedTheme === 'cyberpunk',
|
|
|
|
|
syncFlags() {
|
|
|
|
|
this.isDarkTheme = this.selectedTheme !== 'light';
|
|
|
|
|
this.isUltra = this.selectedTheme === 'ultra-dark';
|
|
|
|
|
this.isCyberpunk = this.selectedTheme === 'cyberpunk';
|
|
|
|
|
},
|
2024-04-20 18:45:36 +00:00
|
|
|
animationsOff() {
|
|
|
|
|
document.documentElement.setAttribute('data-theme-animations', 'off');
|
|
|
|
|
const themeAnimations = document.querySelector('#change-theme');
|
|
|
|
|
themeAnimations.addEventListener('mouseleave', () => {
|
|
|
|
|
document.documentElement.removeAttribute('data-theme-animations');
|
|
|
|
|
});
|
|
|
|
|
themeAnimations.addEventListener('touchend', () => {
|
|
|
|
|
document.documentElement.removeAttribute('data-theme-animations');
|
|
|
|
|
});
|
|
|
|
|
},
|
2023-05-08 13:45:08 +00:00
|
|
|
get currentTheme() {
|
2026-02-18 18:07:22 +00:00
|
|
|
return this.selectedTheme === 'light' ? 'light' : 'dark';
|
|
|
|
|
},
|
|
|
|
|
selectTheme(theme) {
|
|
|
|
|
this.selectedTheme = theme;
|
|
|
|
|
this.syncFlags();
|
|
|
|
|
applyTheme(theme);
|
|
|
|
|
document.getElementById('message').className = this.currentTheme;
|
2023-05-08 13:45:08 +00:00
|
|
|
},
|
|
|
|
|
toggleTheme() {
|
2026-02-18 18:07:22 +00:00
|
|
|
this.selectTheme(this.currentTheme === 'light' ? 'dark' : 'light');
|
2023-05-08 13:45:08 +00:00
|
|
|
},
|
2024-02-28 11:05:01 +00:00
|
|
|
toggleUltra() {
|
2026-02-18 18:07:22 +00:00
|
|
|
this.selectTheme(this.selectedTheme === 'ultra-dark' ? 'dark' : 'ultra-dark');
|
|
|
|
|
},
|
|
|
|
|
toggleCyberpunk() {
|
|
|
|
|
this.selectTheme(this.selectedTheme === 'cyberpunk' ? 'dark' : 'cyberpunk');
|
2024-02-28 11:05:01 +00:00
|
|
|
}
|
2023-05-08 13:45:08 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const themeSwitcher = createThemeSwitcher();
|
2025-03-08 15:41:27 +00:00
|
|
|
Vue.component('a-theme-switch', {
|
2023-05-08 13:45:08 +00:00
|
|
|
template: `{{template "component/themeSwitchTemplate"}}`,
|
2024-02-28 11:05:01 +00:00
|
|
|
data: () => ({
|
|
|
|
|
themeSwitcher
|
|
|
|
|
}),
|
2024-02-21 12:02:18 +00:00
|
|
|
mounted() {
|
2024-02-28 11:05:01 +00:00
|
|
|
this.$message.config({
|
|
|
|
|
getContainer: () => document.getElementById('message')
|
|
|
|
|
});
|
2024-02-21 12:02:18 +00:00
|
|
|
document.getElementById('message').className = themeSwitcher.currentTheme;
|
2024-04-20 18:45:36 +00:00
|
|
|
}
|
|
|
|
|
});
|
2025-03-08 15:41:27 +00:00
|
|
|
Vue.component('a-theme-switch-login', {
|
2024-04-20 18:45:36 +00:00
|
|
|
template: `{{template "component/themeSwitchTemplateLogin"}}`,
|
|
|
|
|
data: () => ({
|
|
|
|
|
themeSwitcher
|
|
|
|
|
}),
|
|
|
|
|
mounted() {
|
|
|
|
|
this.$message.config({
|
|
|
|
|
getContainer: () => document.getElementById('message')
|
2024-04-01 07:08:22 +00:00
|
|
|
});
|
2024-04-20 18:45:36 +00:00
|
|
|
document.getElementById('message').className = themeSwitcher.currentTheme;
|
2024-02-21 12:02:18 +00:00
|
|
|
}
|
2023-05-08 13:45:08 +00:00
|
|
|
});
|
|
|
|
|
</script>
|
2026-02-18 18:07:22 +00:00
|
|
|
{{end}}
|