mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复主题逻辑判断
This commit is contained in:
parent
3a1de79322
commit
386eff8a0b
|
@ -3,6 +3,7 @@ import ProLayout from '@ant-design/pro-layout';
|
|||
import {
|
||||
enable as enableDarkMode,
|
||||
disable as disableDarkMode,
|
||||
auto as followSystemColorScheme,
|
||||
setFetchMethod,
|
||||
} from 'darkreader';
|
||||
import defaultProps from './defaultProps';
|
||||
|
@ -26,18 +27,14 @@ export default function (props: any) {
|
|||
}, [props.location.pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
const colorScheme =
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches && 'dark';
|
||||
let localTheme = localStorage.getItem('qinglong_dark_theme');
|
||||
if (localTheme === 'auto') {
|
||||
localTheme = null;
|
||||
}
|
||||
const theme = localTheme || colorScheme || 'light';
|
||||
const theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
||||
setFetchMethod(window.fetch);
|
||||
if (theme === 'dark') {
|
||||
enableDarkMode({ darkSchemeTextColor: '#fff' });
|
||||
} else if (theme === 'light') {
|
||||
disableDarkMode();
|
||||
} else {
|
||||
followSystemColorScheme({ darkSchemeTextColor: '#fff' });
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { request } from '@/utils/http';
|
|||
import {
|
||||
enable as enableDarkMode,
|
||||
disable as disableDarkMode,
|
||||
auto as followSystemColorScheme,
|
||||
setFetchMethod,
|
||||
} from 'darkreader';
|
||||
|
||||
|
@ -21,10 +22,7 @@ const Password = () => {
|
|||
const [marginTop, setMarginTop] = useState(-72);
|
||||
const [value, setValue] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const colorScheme =
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches && 'dark';
|
||||
const defaultDarken =
|
||||
localStorage.getItem('qinglong_dark_theme') || colorScheme;
|
||||
const defaultDarken = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
||||
const [theme, setTheme] = useState(defaultDarken);
|
||||
|
||||
const handleOk = (values: any) => {
|
||||
|
@ -69,7 +67,7 @@ const Password = () => {
|
|||
} else if (theme === 'light') {
|
||||
disableDarkMode();
|
||||
} else {
|
||||
enableDarkMode({ darkSchemeTextColor: '#fff' });
|
||||
followSystemColorScheme({ darkSchemeTextColor: '#fff' });
|
||||
}
|
||||
}, [theme]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user