Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
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, { useState } from 'react';
|
||||
import { Button, Popover, Typography, Modal } from '@douyinfe/semi-ui';
|
||||
import { IconMail, IconShield, IconGithubLogo } from '@douyinfe/semi-icons';
|
||||
import { Link2, ExternalLink, Check, X } from 'lucide-react';
|
||||
import {
|
||||
TelegramBrandIcon,
|
||||
WechatBrandIcon,
|
||||
LinuxBrandIcon,
|
||||
DiscordBrandIcon,
|
||||
} from '../../../common/icons/BrandIcons';
|
||||
import TelegramLoginButton from 'react-telegram-login';
|
||||
import {
|
||||
onGitHubOAuthClicked,
|
||||
onOIDCClicked,
|
||||
onLinuxDOOAuthClicked,
|
||||
onDiscordOAuthClicked,
|
||||
} from '../../../../helpers';
|
||||
|
||||
// 绑定卡片配置
|
||||
const BINDING_CARDS = [
|
||||
{
|
||||
key: 'email',
|
||||
icon: IconMail,
|
||||
gradient: 'from-blue-500 to-cyan-500',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-blue-50/78 to-cyan-50/70 dark:from-blue-500/[0.09] dark:to-cyan-400/[0.07]',
|
||||
},
|
||||
{
|
||||
key: 'wechat',
|
||||
icon: WechatBrandIcon,
|
||||
gradient: 'from-green-500 to-emerald-500',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-green-50/78 to-emerald-50/70 dark:from-green-500/[0.09] dark:to-emerald-400/[0.07]',
|
||||
isBrandIcon: true,
|
||||
},
|
||||
{
|
||||
key: 'github',
|
||||
icon: IconGithubLogo,
|
||||
gradient: 'from-gray-700 to-gray-900',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-gray-50/88 to-slate-50/75 dark:from-slate-500/[0.10] dark:to-slate-700/[0.10]',
|
||||
},
|
||||
{
|
||||
key: 'discord',
|
||||
icon: DiscordBrandIcon,
|
||||
gradient: 'from-brand-from to-brand-to',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-brand-from/10 to-brand-to/10 dark:from-brand-from/[0.14] dark:to-brand-to/[0.12]',
|
||||
isBrandIcon: true,
|
||||
},
|
||||
{
|
||||
key: 'oidc',
|
||||
icon: IconShield,
|
||||
gradient: 'from-orange-500 to-red-500',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-orange-50/78 to-red-50/70 dark:from-orange-500/[0.10] dark:to-red-500/[0.08]',
|
||||
},
|
||||
{
|
||||
key: 'telegram',
|
||||
icon: TelegramBrandIcon,
|
||||
gradient: 'from-sky-500 to-blue-500',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-sky-50/78 to-blue-50/70 dark:from-sky-500/[0.10] dark:to-blue-500/[0.08]',
|
||||
isBrandIcon: true,
|
||||
},
|
||||
{
|
||||
key: 'linuxdo',
|
||||
icon: LinuxBrandIcon,
|
||||
gradient: 'from-yellow-500 to-orange-500',
|
||||
panelClass:
|
||||
'bg-gradient-to-br from-yellow-50/78 to-orange-50/70 dark:from-yellow-500/[0.10] dark:to-orange-500/[0.08]',
|
||||
isBrandIcon: true,
|
||||
},
|
||||
];
|
||||
|
||||
const AccountBindingSection = ({
|
||||
t,
|
||||
userState,
|
||||
status,
|
||||
setShowEmailBindModal,
|
||||
setShowWeChatBindModal,
|
||||
}) => {
|
||||
const [showTelegramBindModal, setShowTelegramBindModal] = useState(false);
|
||||
|
||||
const isBound = (accountId) => Boolean(accountId);
|
||||
|
||||
const renderAccountInfo = (accountId, label) => {
|
||||
if (!accountId || accountId === '') {
|
||||
return <span className='text-gray-400'>{t('未绑定')}</span>;
|
||||
}
|
||||
|
||||
const popContent = (
|
||||
<div className='text-xs p-2'>
|
||||
<Typography.Paragraph copyable={{ content: accountId }}>
|
||||
{accountId}
|
||||
</Typography.Paragraph>
|
||||
{label && <div className='mt-1 text-[11px] text-gray-500'>{label}</div>}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover content={popContent} position='top' trigger='hover'>
|
||||
<span className='text-sm text-gray-600 dark:text-gray-300 hover:text-blue-600 cursor-pointer truncate max-w-[120px] inline-block'>
|
||||
{accountId}
|
||||
</span>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
const getBindingData = (key) => {
|
||||
switch (key) {
|
||||
case 'email':
|
||||
return {
|
||||
name: t('邮箱'),
|
||||
value: userState.user?.email,
|
||||
label: t('邮箱地址'),
|
||||
enabled: true,
|
||||
onBind: () => setShowEmailBindModal(true),
|
||||
};
|
||||
case 'wechat':
|
||||
return {
|
||||
name: t('微信'),
|
||||
value: userState.user?.wechat_id,
|
||||
label: t('微信账号'),
|
||||
enabled: status.wechat_login,
|
||||
onBind: () => setShowWeChatBindModal(true),
|
||||
};
|
||||
case 'github':
|
||||
return {
|
||||
name: 'GitHub',
|
||||
value: userState.user?.github_id,
|
||||
label: 'GitHub ID',
|
||||
enabled: status.github_oauth,
|
||||
onBind: () => onGitHubOAuthClicked(status.github_client_id),
|
||||
disableWhenBound: true,
|
||||
};
|
||||
case 'discord':
|
||||
return {
|
||||
name: 'Discord',
|
||||
value: userState.user?.discord_id,
|
||||
label: 'Discord ID',
|
||||
enabled: status.discord_oauth,
|
||||
onBind: () => onDiscordOAuthClicked(status.discord_client_id),
|
||||
disableWhenBound: true,
|
||||
};
|
||||
case 'oidc':
|
||||
return {
|
||||
name: 'OIDC',
|
||||
value: userState.user?.oidc_id,
|
||||
label: 'OIDC ID',
|
||||
enabled: status.oidc_enabled,
|
||||
onBind: () =>
|
||||
onOIDCClicked(
|
||||
status.oidc_authorization_endpoint,
|
||||
status.oidc_client_id,
|
||||
),
|
||||
disableWhenBound: true,
|
||||
};
|
||||
case 'telegram':
|
||||
return {
|
||||
name: 'Telegram',
|
||||
value: userState.user?.telegram_id,
|
||||
label: 'Telegram ID',
|
||||
enabled: status.telegram_oauth,
|
||||
onBind: () => setShowTelegramBindModal(true),
|
||||
disableWhenBound: true,
|
||||
};
|
||||
case 'linuxdo':
|
||||
return {
|
||||
name: 'LinuxDO',
|
||||
value: userState.user?.linux_do_id,
|
||||
label: 'LinuxDO ID',
|
||||
enabled: status.linuxdo_oauth,
|
||||
onBind: () => onLinuxDOOAuthClicked(status.linuxdo_client_id),
|
||||
disableWhenBound: true,
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
{/* 页面标题 */}
|
||||
<div className='flex items-center gap-3 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
|
||||
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-sky-500 to-cyan-400 flex items-center justify-center shadow-lg shadow-sky-500/20'>
|
||||
<Link2 className='w-5 h-5 text-white' />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
|
||||
{t('账号绑定')}
|
||||
</h2>
|
||||
<p className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{t('管理邮箱和第三方登录方式')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 绑定卡片网格 */}
|
||||
<div className='grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4'>
|
||||
{BINDING_CARDS.map((card) => {
|
||||
const data = getBindingData(card.key);
|
||||
if (!data) return null;
|
||||
// 未启用的绑定方式不显示卡片
|
||||
if (!data.enabled) return null;
|
||||
|
||||
const Icon = card.icon;
|
||||
const bound = isBound(data.value);
|
||||
const disabled = data.disableWhenBound && bound;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={card.key}
|
||||
className={`relative group p-5 rounded-[22px] border backdrop-blur-xl transition-all duration-300 ${
|
||||
bound
|
||||
? 'bg-white/62 dark:bg-white/[0.055] border-white/70 dark:border-white/10'
|
||||
: `${card.panelClass} border-white/70 dark:border-white/10 hover:border-white dark:hover:border-white/20`
|
||||
} hover:shadow-[0_18px_45px_rgba(15,23,42,0.10)] hover:-translate-y-0.5`}
|
||||
>
|
||||
{/* 状态指示器 */}
|
||||
<div className='absolute top-3 right-3'>
|
||||
{bound ? (
|
||||
<div className='flex items-center gap-1 px-2 py-0.5 bg-emerald-100 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400 rounded-full text-xs font-medium'>
|
||||
<Check size={12} />
|
||||
{t('已绑定')}
|
||||
</div>
|
||||
) : (
|
||||
<div className='flex items-center gap-1 px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 rounded-full text-xs'>
|
||||
<X size={12} />
|
||||
{t('未绑定')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 图标和名称 */}
|
||||
<div className='flex items-center gap-3 mb-4 pr-20'>
|
||||
<div
|
||||
className={`w-12 h-12 rounded-2xl flex items-center justify-center bg-gradient-to-br ${card.gradient} shadow-lg`}
|
||||
>
|
||||
{card.isBrandIcon ? (
|
||||
<Icon size={24} color='#FFFFFF' />
|
||||
) : (
|
||||
<Icon size='extra-large' className='text-white' />
|
||||
)}
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<h3 className='font-semibold text-gray-900 dark:text-white'>
|
||||
{data.name}
|
||||
</h3>
|
||||
<div className='text-sm'>
|
||||
{bound ? renderAccountInfo(data.value, data.label) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<Button
|
||||
theme={bound ? 'light' : 'solid'}
|
||||
type='primary'
|
||||
size='small'
|
||||
disabled={disabled}
|
||||
onClick={data.onBind}
|
||||
className={`w-full !rounded-lg ${
|
||||
!bound
|
||||
? `!bg-gradient-to-r ${card.gradient} !border-0 hover:opacity-90`
|
||||
: ''
|
||||
}`}
|
||||
icon={bound ? null : <ExternalLink size={14} />}
|
||||
>
|
||||
{bound
|
||||
? data.disableWhenBound
|
||||
? t('已绑定')
|
||||
: t('修改绑定')
|
||||
: t('立即绑定')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Telegram 绑定弹窗 */}
|
||||
<Modal
|
||||
title={t('绑定 Telegram')}
|
||||
visible={showTelegramBindModal}
|
||||
onCancel={() => setShowTelegramBindModal(false)}
|
||||
footer={null}
|
||||
>
|
||||
<div className='my-3 text-sm text-gray-600'>
|
||||
{t('点击下方按钮通过 Telegram 完成绑定')}
|
||||
</div>
|
||||
<div className='flex justify-center'>
|
||||
<div className='scale-90'>
|
||||
<TelegramLoginButton
|
||||
dataAuthUrl='/api/oauth/telegram/bind'
|
||||
botName={status.telegram_bot_name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AccountBindingSection;
|
||||
Reference in New Issue
Block a user