2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
176 lines
7.0 KiB
React
176 lines
7.0 KiB
React
import { MessageCircle as ActionMessageCircle } from '@/components/common/icons/ActionIcons';
|
|
import React, { useState, useEffect } from 'react';
|
|
import { Avatar } from '@/components/ui';
|
|
import { MessageCircle, ScanLine } from 'lucide-react';
|
|
import { API } from '../../helpers';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
/**
|
|
* 登录/注册页面的客服浮窗
|
|
* 右上角固定展示客服二维码,始终可见
|
|
*/
|
|
const AuthCustomerServiceFloat = () => {
|
|
const { t } = useTranslation();
|
|
const [agent, setAgent] = useState(null);
|
|
const [visible, setVisible] = useState(false);
|
|
const [qrcodeError, setQrcodeError] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const fetchAgent = async () => {
|
|
try {
|
|
const configRes = await API.get('/api/customer-service/config');
|
|
if (!configRes.data.success || !configRes.data.data?.enabled) return;
|
|
|
|
const agentRes = await API.get('/api/customer-service/display');
|
|
if (agentRes.data.success && agentRes.data.data) {
|
|
const data = agentRes.data.data;
|
|
if (data.qrcode_url || data.wecom_url) {
|
|
setAgent(data);
|
|
setVisible(true);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
// 静默处理,不影响登录页
|
|
}
|
|
};
|
|
fetchAgent();
|
|
}, []);
|
|
|
|
if (!visible || !agent) return null;
|
|
|
|
const hasQrcode = agent.qrcode_url && !qrcodeError;
|
|
|
|
return (
|
|
<div className='fixed top-28 right-5 z-[200] w-52'>
|
|
<style>{`
|
|
.auth-cs-glass-card {
|
|
box-shadow:
|
|
0 20px 45px -15px rgba(15, 42, 80, 0.25),
|
|
0 8px 20px -8px rgb(var(--brand-primary-rgb) / 0.18),
|
|
inset 0 1px 0 rgba(255, 255, 255, 0.7),
|
|
inset 0 -1px 0 rgba(255, 255, 255, 0.18);
|
|
}
|
|
.dark .auth-cs-glass-card {
|
|
box-shadow:
|
|
0 20px 45px -15px rgba(0, 0, 0, 0.6),
|
|
0 10px 24px -8px rgb(var(--brand-primary-rgb) / 0.22),
|
|
inset 0 1px 0 rgba(255, 255, 255, 0.1),
|
|
inset 0 -1px 0 rgba(255, 255, 255, 0.03);
|
|
}
|
|
.auth-cs-aurora {
|
|
top: -30%;
|
|
left: -20%;
|
|
width: 90%;
|
|
height: 90%;
|
|
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.18) 0%, transparent 70%);
|
|
animation: authCsAurora 18s ease-in-out infinite;
|
|
}
|
|
.dark .auth-cs-aurora {
|
|
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.22) 0%, transparent 70%);
|
|
}
|
|
@keyframes authCsAurora {
|
|
0%, 100% { transform: translate(0%, 0%); }
|
|
50% { transform: translate(20%, 18%); }
|
|
}
|
|
@media (max-width: 640px) {
|
|
.auth-cs-glass-card {
|
|
backdrop-filter: blur(20px);
|
|
-webkit-backdrop-filter: blur(20px);
|
|
}
|
|
}
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.auth-cs-aurora,
|
|
.auth-cs-glass-card { animation: none; transition: none; }
|
|
}
|
|
`}</style>
|
|
{/* 外层柔光晕 - 增强浮空立体感 */}
|
|
<div className='absolute -inset-3 bg-gradient-to-br from-brand-from/15 via-brand-via/10 to-brand-to/15 rounded-3xl blur-xl opacity-80 pointer-events-none' />
|
|
|
|
{/* 展示面板 - 玻璃拟态立体效果 */}
|
|
<div
|
|
className='
|
|
auth-cs-glass-card relative isolate
|
|
backdrop-blur-2xl rounded-xl overflow-hidden
|
|
ring-1 ring-white/50 dark:ring-white/[0.06]
|
|
border border-white/30 dark:border-white/[0.05]
|
|
bg-white/55 dark:bg-neutral-900/55
|
|
transition-[transform,box-shadow] duration-500 ease-out
|
|
hover:scale-[1.01]
|
|
'
|
|
>
|
|
{/* 内层 aurora - 缓慢漂移品牌色辉光 */}
|
|
<div className='auth-cs-aurora absolute -z-10 pointer-events-none' />
|
|
|
|
{/* 顶部渐变装饰线 */}
|
|
<div className='h-0.5 bg-gradient-to-r from-brand-from via-brand-via to-brand-to' />
|
|
|
|
{/* 顶部高光反射 - 位于装饰线下方,模拟玻璃反光 */}
|
|
<div className='absolute top-0.5 left-[15%] right-[15%] h-px bg-gradient-to-r from-transparent via-white/90 dark:via-white/40 to-transparent pointer-events-none' />
|
|
|
|
<div className='p-3'>
|
|
{/* 客服信息 */}
|
|
<div className='flex items-center gap-2 mb-2.5'>
|
|
{agent.avatar ? (
|
|
<Avatar
|
|
src={agent.avatar}
|
|
size='extra-small'
|
|
className='!w-7 !h-7 flex-shrink-0'
|
|
/>
|
|
) : (
|
|
<div className='w-7 h-7 rounded-full bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center flex-shrink-0'>
|
|
<MessageCircle size={13} className='text-white' />
|
|
</div>
|
|
)}
|
|
<div className='flex-1 min-w-0'>
|
|
<div className='flex items-center gap-1'>
|
|
<span className='text-xs font-semibold text-gray-800 dark:text-white truncate'>
|
|
{agent.name || t('在线客服')}
|
|
</span>
|
|
<span className='inline-flex items-center gap-0.5 px-1 py-px bg-emerald-50 dark:bg-emerald-900/30 rounded-full flex-shrink-0'>
|
|
<span className='w-1 h-1 bg-emerald-500 rounded-full animate-pulse' />
|
|
<span className='text-[9px] text-emerald-600 dark:text-emerald-400 font-medium'>
|
|
{t('在线')}
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 提示文案 */}
|
|
<p className='text-[11px] text-gray-500 dark:text-gray-400 mb-2.5 leading-relaxed'>
|
|
{t('登录遇到问题?扫码咨询客服解决')}
|
|
</p>
|
|
|
|
{/* 二维码 - 始终展示 */}
|
|
{hasQrcode ? (
|
|
<div className='flex flex-col items-center'>
|
|
<div className='w-full p-2 bg-white dark:bg-neutral-800/60 rounded-lg border border-gray-100 dark:border-neutral-700/50'>
|
|
<img
|
|
src={agent.qrcode_url}
|
|
alt={t('客服二维码')}
|
|
className='w-full aspect-square object-contain rounded'
|
|
onError={() => setQrcodeError(true)}
|
|
/>
|
|
</div>
|
|
<div className='mt-2 flex items-center gap-1 text-[10px] text-brand-deep dark:text-brand-from font-medium'>
|
|
<ScanLine size={10} />
|
|
<span>{t('微信扫码添加客服')}</span>
|
|
</div>
|
|
</div>
|
|
) : agent.wecom_url ? (
|
|
<button
|
|
onClick={() => window.open(agent.wecom_url, '_blank')}
|
|
className='app-action-button w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-gradient-to-r from-brand-from to-brand-to hover:from-brand-from hover:to-brand-to text-white text-xs font-medium rounded-lg transition-colors'
|
|
>
|
|
<ActionMessageCircle size={12} />
|
|
{t('联系客服')}
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AuthCustomerServiceFloat;
|