Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,271 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo } from 'react';
import { Button, Dropdown } from '@douyinfe/semi-ui';
import { useActualTheme } from '../../../context/Theme';
// 自定义浅色图标 — 带光芒的太阳
const LightIcon = ({ size = 18, color = 'currentColor' }) => (
<svg
width={size}
height={size}
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<circle cx='12' cy='12' r='4.5' stroke={color} strokeWidth='1.7' />
<line
x1='12'
y1='2.5'
x2='12'
y2='5'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='12'
y1='19'
x2='12'
y2='21.5'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='21.5'
y1='12'
x2='19'
y2='12'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='5'
y1='12'
x2='2.5'
y2='12'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='18.7'
y1='5.3'
x2='16.9'
y2='7.1'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='7.1'
y1='16.9'
x2='5.3'
y2='18.7'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='18.7'
y1='18.7'
x2='16.9'
y2='16.9'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='7.1'
y1='7.1'
x2='5.3'
y2='5.3'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
</svg>
);
// 自定义深色图标 — 带星星的弯月
const DarkIcon = ({ size = 18, color = 'currentColor' }) => (
<svg
width={size}
height={size}
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<path
d='M20.5 13.5a8.5 8.5 0 01-10-10A8.5 8.5 0 1020.5 13.5z'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
strokeLinejoin='round'
/>
<circle cx='18' cy='5' r='0.8' fill={color} />
<circle cx='20.5' cy='8' r='0.6' fill={color} />
<circle cx='16' cy='3' r='0.5' fill={color} />
</svg>
);
// 自定义自动模式图标 — 半日半月
const AutoIcon = ({ size = 18, color = 'currentColor' }) => (
<svg
width={size}
height={size}
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'
>
<circle cx='12' cy='12' r='8.5' stroke={color} strokeWidth='1.7' />
<path d='M12 3.5v17a8.5 8.5 0 000-17z' fill={color} fillOpacity='0.2' />
<line
x1='12'
y1='1.5'
x2='12'
y2='3.5'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='12'
y1='20.5'
x2='12'
y2='22.5'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='22.5'
y1='12'
x2='20.5'
y2='12'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
<line
x1='3.5'
y1='12'
x2='1.5'
y2='12'
stroke={color}
strokeWidth='1.7'
strokeLinecap='round'
/>
</svg>
);
const ThemeToggle = ({ theme, onThemeToggle, t }) => {
const actualTheme = useActualTheme();
const themeOptions = useMemo(
() => [
{
key: 'light',
icon: <LightIcon />,
buttonIcon: <LightIcon />,
label: t('浅色模式'),
description: t('始终使用浅色主题'),
},
{
key: 'dark',
icon: <DarkIcon />,
buttonIcon: <DarkIcon />,
label: t('深色模式'),
description: t('始终使用深色主题'),
},
{
key: 'auto',
icon: <AutoIcon />,
buttonIcon: <AutoIcon />,
label: t('自动模式'),
description: t('跟随系统主题设置'),
},
],
[t],
);
const getItemClassName = (isSelected) =>
isSelected
? '!bg-semi-color-primary-light-default !font-semibold'
: 'hover:!bg-semi-color-fill-1';
const currentButtonIcon = useMemo(() => {
const currentOption = themeOptions.find((option) => option.key === theme);
return currentOption?.buttonIcon || themeOptions[2].buttonIcon;
}, [theme, themeOptions]);
return (
<Dropdown
position='bottomRight'
render={
<Dropdown.Menu>
{themeOptions.map((option) => (
<Dropdown.Item
key={option.key}
icon={option.icon}
onClick={() => onThemeToggle(option.key)}
className={getItemClassName(theme === option.key)}
>
<div className='flex flex-col'>
<span>{option.label}</span>
<span className='text-xs text-semi-color-text-2'>
{option.description}
</span>
</div>
</Dropdown.Item>
))}
{theme === 'auto' && (
<>
<Dropdown.Divider />
<div className='px-3 py-2 text-xs text-semi-color-text-2'>
{t('当前跟随系统')}:
{actualTheme === 'dark' ? t('深色') : t('浅色')}
</div>
</>
)}
</Dropdown.Menu>
}
>
<Button
icon={currentButtonIcon}
aria-label={t('切换主题')}
theme='borderless'
type='tertiary'
className='!w-8 !h-8 sm:!w-9 sm:!h-9 !flex !items-center !justify-center hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep dark:hover:!text-brand-from !rounded-full !transition-all !duration-200 hover:!scale-[1.08] active:!scale-95'
style={{
color:
actualTheme === 'dark'
? 'rgba(243,244,246,0.9)'
: 'rgba(75,85,99,1)',
}}
/>
</Dropdown>
);
};
export default ThemeToggle;