Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
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 from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Avatar, Button, Dropdown, Typography } from '@douyinfe/semi-ui';
|
||||
import { ChevronDown, User, Key, LogOut } from 'lucide-react';
|
||||
import {
|
||||
getUserAvatarUrl,
|
||||
stringToColor,
|
||||
isAuthPagePath,
|
||||
} from '../../../helpers';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
import { useActualTheme } from '../../../context/Theme';
|
||||
import { isHeaderModuleEnabled } from '../../../constants/headerNavModules';
|
||||
|
||||
const UserArea = ({
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
rightActions = {},
|
||||
sidebarModulesAdmin = {},
|
||||
logout,
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const location = useLocation();
|
||||
const actualTheme = useActualTheme();
|
||||
const isDark = actualTheme === 'dark';
|
||||
const isActionVisible = (key) => rightActions?.[key] !== false;
|
||||
const hasHeaderModuleConfig =
|
||||
headerNavModules && Object.keys(headerNavModules).length > 0;
|
||||
const isTopNavModuleVisible = (key) =>
|
||||
!hasHeaderModuleConfig || isHeaderModuleEnabled(headerNavModules, key);
|
||||
const isSidebarModuleVisible = (sectionKey, moduleKey) => {
|
||||
const section = sidebarModulesAdmin?.[sectionKey];
|
||||
if (!section) return true;
|
||||
return section.enabled !== false && section[moduleKey] !== false;
|
||||
};
|
||||
|
||||
// 在登录/注册/重置密码/企业登录页面时,未登录用户不显示登录注册按钮,避免重复
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<SkeletonWrapper
|
||||
loading={true}
|
||||
type='userArea'
|
||||
width={50}
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (userState.user) {
|
||||
const displayName = userState.user.display_name || userState.user.username;
|
||||
const avatarUrl = getUserAvatarUrl(userState.user);
|
||||
return (
|
||||
<Dropdown
|
||||
trigger='hover'
|
||||
position='bottomRight'
|
||||
showTick
|
||||
render={
|
||||
<Dropdown.Menu
|
||||
className='!min-w-[180px] !p-2 !backdrop-blur-xl !border !shadow-xl !rounded-xl'
|
||||
style={{
|
||||
backgroundColor: isDark
|
||||
? 'rgba(31,41,55,0.95)'
|
||||
: 'rgba(255,255,255,0.95)',
|
||||
borderColor: isDark ? 'rgba(55,65,81,1)' : 'rgba(243,244,246,1)',
|
||||
boxShadow: isDark
|
||||
? '0 20px 25px -5px rgba(0,0,0,0.3)'
|
||||
: '0 20px 25px -5px rgba(0,0,0,0.05)',
|
||||
}}
|
||||
>
|
||||
{/* 用户信息头部 */}
|
||||
<div
|
||||
className='px-3 py-2 mb-2 border-b'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<Avatar
|
||||
size='small'
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-8 !h-8 !text-xs'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
</Avatar>
|
||||
<div>
|
||||
<div
|
||||
className='text-sm font-semibold'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(243,244,246,0.9)'
|
||||
: 'rgba(31,41,55,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{userState.user.email || t('已登录')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isActionVisible('userSettings') &&
|
||||
isTopNavModuleVisible('userCenter') &&
|
||||
isSidebarModuleVisible('userCenter', 'settings') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/user-center/settings');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(30,58,138,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(219,234,254,1), rgba(224,231,255,1))',
|
||||
}}
|
||||
>
|
||||
<User
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(96,165,250,1)'
|
||||
: 'rgba(37,99,235,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('个人设置')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('管理账户信息')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
{isActionVisible('keyManagement') &&
|
||||
isTopNavModuleVisible('keyManagement') && (
|
||||
<Dropdown.Item
|
||||
onClick={() => {
|
||||
navigate('/key-management');
|
||||
}}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(120,53,15,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,243,199,1), rgba(255,237,213,1))',
|
||||
}}
|
||||
>
|
||||
<Key
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(251,191,36,1)'
|
||||
: 'rgba(217,119,6,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('秘钥管理')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('查看和管理API秘钥')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
|
||||
<div
|
||||
className='my-2 border-t'
|
||||
style={{
|
||||
borderColor: isDark
|
||||
? 'rgba(55,65,81,1)'
|
||||
: 'rgba(243,244,246,1)',
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dropdown.Item
|
||||
onClick={logout}
|
||||
className='!px-3 !py-2.5 !rounded-lg !text-sm !transition-all !duration-200'
|
||||
style={{
|
||||
color: isDark ? 'rgba(229,231,235,1)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div
|
||||
className='w-8 h-8 rounded-lg flex items-center justify-center'
|
||||
style={{
|
||||
background: isDark
|
||||
? 'rgba(127,29,29,0.5)'
|
||||
: 'linear-gradient(to bottom right, rgba(254,226,226,1), rgba(255,228,230,1))',
|
||||
}}
|
||||
>
|
||||
<LogOut
|
||||
size={16}
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(248,113,113,1)'
|
||||
: 'rgba(220,38,38,1)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
className='font-medium'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : undefined,
|
||||
}}
|
||||
>
|
||||
{t('退出登录')}
|
||||
</div>
|
||||
<div
|
||||
className='text-xs'
|
||||
style={{
|
||||
color: isDark
|
||||
? 'rgba(107,114,128,1)'
|
||||
: 'rgba(156,163,175,1)',
|
||||
}}
|
||||
>
|
||||
{t('安全退出账户')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
}
|
||||
>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='flex items-center gap-2 !pl-1.5 !pr-2.5 !py-1.5 !h-10 !rounded-full hover:!bg-brand/10 dark:hover:!bg-brand/15 !bg-transparent !transition-all !duration-200 hover:!-translate-y-0.5 group'
|
||||
>
|
||||
<div className='relative'>
|
||||
<Avatar
|
||||
size='small'
|
||||
src={avatarUrl}
|
||||
color={stringToColor(displayName)}
|
||||
className='!w-7 !h-7 !text-xs ring-2 ring-white dark:ring-gray-800 group-hover:!ring-brand/40 dark:group-hover:!ring-brand/50 transition-all'
|
||||
>
|
||||
{displayName[0].toUpperCase()}
|
||||
</Avatar>
|
||||
{/* 在线状态点 */}
|
||||
<span className='absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 bg-emerald-500 border-2 border-white dark:border-gray-800 rounded-full' />
|
||||
</div>
|
||||
<span className='hidden md:flex flex-col items-start'>
|
||||
<Typography.Text
|
||||
className='!text-sm !font-medium !leading-none'
|
||||
style={{
|
||||
color: isDark ? 'rgba(243,244,246,0.9)' : 'rgba(55,65,81,1)',
|
||||
}}
|
||||
>
|
||||
{displayName}
|
||||
</Typography.Text>
|
||||
</span>
|
||||
<ChevronDown
|
||||
size={14}
|
||||
style={{
|
||||
color: isDark ? 'rgba(209,213,219,1)' : 'rgba(156,163,175,1)',
|
||||
}}
|
||||
className='group-hover:!opacity-80 transition-colors'
|
||||
/>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
);
|
||||
} else {
|
||||
if (isAuthPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showRegisterButton = !isSelfUseMode;
|
||||
|
||||
const commonSizingAndLayoutClass =
|
||||
'flex items-center justify-center !py-[10px] !px-1.5';
|
||||
|
||||
const loginButtonSpecificStyling =
|
||||
'!bg-transparent hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep !transition-all !duration-200';
|
||||
let loginButtonClasses = `${commonSizingAndLayoutClass} ${loginButtonSpecificStyling}`;
|
||||
|
||||
let registerButtonClasses = `${commonSizingAndLayoutClass}`;
|
||||
|
||||
const loginButtonTextSpanClass =
|
||||
'!text-xs !text-semi-color-text-1 dark:!text-gray-300 !p-1.5';
|
||||
const registerButtonTextSpanClass = '!text-xs !text-white !p-1.5';
|
||||
|
||||
if (showRegisterButton) {
|
||||
if (isMobile) {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-l-full !rounded-r-none';
|
||||
}
|
||||
registerButtonClasses += ' !rounded-r-full !rounded-l-none';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex items-center'>
|
||||
<Link to='/org/login' className='flex'>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className={loginButtonClasses}
|
||||
>
|
||||
<span className={loginButtonTextSpanClass}>{t('登录')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
{showRegisterButton && (
|
||||
<div className='hidden md:block'>
|
||||
<Link to='/register' className='flex -ml-px'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
className={registerButtonClasses}
|
||||
>
|
||||
<span className={registerButtonTextSpanClass}>{t('注册')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default UserArea;
|
||||
Reference in New Issue
Block a user