checkbox fixed

Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
MHSanaei 2024-02-28 01:18:59 +03:30
parent 6856638e2e
commit 0abca75c5d
3 changed files with 47 additions and 64 deletions

View file

@ -15,10 +15,6 @@
<a-icon type="tool"></a-icon> <a-icon type="tool"></a-icon>
<span><b>{{ i18n "menu.xray"}}</b></span> <span><b>{{ i18n "menu.xray"}}</b></span>
</a-menu-item> </a-menu-item>
<!--<a-menu-item key="{{ .base_path }}panel/clients">-->
<!-- <a-icon type="laptop"></a-icon>-->
<!-- <span>Client</span>-->
<!--</a-menu-item>-->
<a-menu-item key="{{ .base_path }}logout"> <a-menu-item key="{{ .base_path }}logout">
<a-icon type="logout"></a-icon> <a-icon type="logout"></a-icon>
<span><b>{{ i18n "menu.logout"}}</b></span> <span><b>{{ i18n "menu.logout"}}</b></span>
@ -28,14 +24,7 @@
{{define "commonSider"}} {{define "commonSider"}}
<a-layout-sider :theme="themeSwitcher.currentTheme" id="sider" collapsible breakpoint="md" collapsed-width="0"> <a-layout-sider :theme="themeSwitcher.currentTheme" id="sider" collapsible breakpoint="md" collapsed-width="0">
<a-menu :theme="themeSwitcher.currentTheme" mode="inline" selected-keys=""> <theme-switch></theme-switch>
<a-menu-item mode="inline">
<a-icon type="bulb" :theme="themeSwitcher.isDarkTheme ? 'filled' : 'outlined'"></a-icon>
<theme-switch>
</theme-switch>
<a-checkbox v-if="themeSwitcher.isDarkTheme" style="padding-left: 1rem;" id="ultradarktheme">Ultra</a-checkbox>
</a-menu-item>
</a-menu>
<a-menu :theme="themeSwitcher.currentTheme" mode="inline" :selected-keys="['{{ .request_uri }}']" <a-menu :theme="themeSwitcher.currentTheme" mode="inline" :selected-keys="['{{ .request_uri }}']"
@click="({key}) => key.startsWith('http') ? window.open(key) : location.href = key"> @click="({key}) => key.startsWith('http') ? window.open(key) : location.href = key">
{{template "menuItems" .}} {{template "menuItems" .}}

View file

@ -1,8 +1,16 @@
{{define "component/themeSwitchTemplate"}} {{define "component/themeSwitchTemplate"}}
<template> <template>
<a-switch size="small" :default-checked="themeSwitcher.isDarkTheme" <a-menu :theme="themeSwitcher.currentTheme" mode="inline" selected-keys="">
@change="themeSwitcher.toggleTheme()"> <a-menu-item mode="inline">
<a-icon type="bulb" :theme="themeSwitcher.isDarkTheme ? 'filled' : 'outlined'"></a-icon>
<a-switch size="small" :default-checked="themeSwitcher.isDarkTheme" @change="themeSwitcher.toggleTheme()">
</a-switch> </a-switch>
<a-checkbox v-if="themeSwitcher.isDarkTheme" style="padding-left: 1rem; vertical-align: middle;"
:checked="themeSwitcher.isUltra" @click="themeSwitcher.toggleUltra()">
Ultra
</a-checkbox>
</a-menu-item>
</a-menu>
</template> </template>
{{end}} {{end}}
@ -10,19 +18,35 @@
<script> <script>
function createThemeSwitcher() { function createThemeSwitcher() {
const isDarkTheme = localStorage.getItem('dark-mode') === 'true'; const isDarkTheme = localStorage.getItem('dark-mode') === 'true';
const isUltra = localStorage.getItem('isUltraDarkThemeEnabled') === 'true';
if (isUltra) {
document.documentElement.setAttribute('data-theme', 'ultra-dark');
}
const theme = isDarkTheme ? 'dark' : 'light'; const theme = isDarkTheme ? 'dark' : 'light';
document.querySelector('body').setAttribute('class', theme) document.querySelector('body').setAttribute('class', theme);
return { return {
isDarkTheme, isDarkTheme,
isUltra,
get currentTheme() { get currentTheme() {
return this.isDarkTheme ? 'dark' : 'light'; return this.isDarkTheme ? 'dark' : 'light';
}, },
toggleTheme() { toggleTheme() {
this.isDarkTheme = !this.isDarkTheme; this.isDarkTheme = !this.isDarkTheme;
localStorage.setItem('dark-mode', this.isDarkTheme); localStorage.setItem('dark-mode', this.isDarkTheme);
document.querySelector('body').setAttribute('class', this.isDarkTheme ? 'dark' : 'light') document.querySelector('body').setAttribute('class', this.isDarkTheme ? 'dark' : 'light');
document.getElementById('message').className = themeSwitcher.currentTheme; document.getElementById('message').className = themeSwitcher.currentTheme;
}, },
toggleUltra() {
this.isUltra = !this.isUltra;
if (this.isUltra) {
document.documentElement.setAttribute('data-theme', 'ultra-dark');
} else {
document.documentElement.removeAttribute('data-theme');
}
localStorage.setItem('isUltraDarkThemeEnabled', this.isUltra.toString());
}
}; };
} }
@ -39,32 +63,3 @@
}); });
</script> </script>
{{end}} {{end}}
{{define "component/ultraDarkTheme"}}
<script>
const isUltraDarkThemeEnabled = localStorage.getItem('isUltraDarkThemeEnabled') === 'true';
document.addEventListener('DOMContentLoaded', function () {
const uthemeToggle = document.getElementById('ultradarktheme');
if (uthemeToggle) {
uthemeToggle.checked = isUltraDarkThemeEnabled;
function ultraToggleTheme() {
if (uthemeToggle.checked) {
document.documentElement.setAttribute('data-theme', 'ultra-dark');
localStorage.setItem('isUltraDarkThemeEnabled', 'true');
} else {
document.documentElement.removeAttribute('data-theme');
localStorage.setItem('isUltraDarkThemeEnabled', 'false');
}
}
uthemeToggle.addEventListener('change', ultraToggleTheme);
ultraToggleTheme();
} else {
console.error("Element with ID 'ultradarktheme' not found.");
}
});
</script>
{{end}}

View file

@ -343,7 +343,6 @@
{{template "js" .}} {{template "js" .}}
<script src="{{ .base_path }}assets/clipboard/clipboard.min.js"></script> <script src="{{ .base_path }}assets/clipboard/clipboard.min.js"></script>
{{template "component/themeSwitcher" .}} {{template "component/themeSwitcher" .}}
{{template "component/ultraDarkTheme" .}}
{{template "textModal"}} {{template "textModal"}}
<script> <script>