feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-04 19:59:06 +08:00
parent 1fd4e084b6
commit 15192c433b
576 changed files with 18075 additions and 18912 deletions
+98 -193
View File
@@ -23,39 +23,26 @@ import {
Spin,
Empty,
Button,
Typography,
Tooltip,
} from '@douyinfe/semi-ui';
import {
MessageCircle,
X,
ChevronRight,
Users,
RefreshCw,
Headphones,
QrCode,
Sparkles,
MessageSquareMore,
} from 'lucide-react';
Divider,
theme,
} from 'antd';
import { X, RefreshCw, Headphones } from 'lucide-react';
import { API } from '../../helpers';
import { getServerURL } from '../../helpers/config';
import { useTranslation } from 'react-i18next';
import './styles.css';
const { Text } = Typography;
// 本地存储 key
const COLLAPSED_STORAGE_KEY = 'cs-collapsed';
// 在线客服列表停留时的轮询间隔
const ONLINE_POLL_INTERVAL = 15000;
// 页面内“联系客服”入口派发的可取消事件;客服启用时由本组件 preventDefault 并打开面板。
export const CUSTOMER_SERVICE_OPEN_EVENT = 'customer-service:open';
const CustomerServiceFloat = () => {
const { t } = useTranslation();
const { token } = theme.useToken();
const [isOpen, setIsOpen] = useState(false);
const [isCollapsed, setIsCollapsed] = useState(() => {
// 从本地存储读取收起状态
return localStorage.getItem(COLLAPSED_STORAGE_KEY) === 'true';
});
const [loading, setLoading] = useState(false);
const [currentAgent, setCurrentAgent] = useState(null);
const [agentList, setAgentList] = useState([]);
@@ -91,20 +78,8 @@ const CustomerServiceFloat = () => {
API.post(path).catch(() => {});
}, []);
// 切换收起状态
const toggleCollapse = (e) => {
e.stopPropagation();
const newState = !isCollapsed;
setIsCollapsed(newState);
localStorage.setItem(COLLAPSED_STORAGE_KEY, String(newState));
};
// 展开并打开面板
// 打开客服面板;不再读取或提供边缘收起状态。
const handleExpand = () => {
if (isCollapsed) {
setIsCollapsed(false);
localStorage.setItem(COLLAPSED_STORAGE_KEY, 'false');
}
setIsOpen(true);
};
@@ -124,6 +99,18 @@ const CustomerServiceFloat = () => {
fetchConfig();
}, [fetchConfig]);
// 页面内入口(如密钥管理“联系客服”)与悬浮按钮共用同一打开逻辑。
useEffect(() => {
if (!config.enabled) return undefined;
const onOpenRequest = (event) => {
event.preventDefault();
setIsOpen(true);
};
window.addEventListener(CUSTOMER_SERVICE_OPEN_EVENT, onOpenRequest);
return () =>
window.removeEventListener(CUSTOMER_SERVICE_OPEN_EVENT, onOpenRequest);
}, [config.enabled]);
// 获取分配的客服(会让后端 current_sessions +1)
const fetchAllocatedAgent = useCallback(async () => {
setLoading(true);
@@ -249,14 +236,10 @@ const CustomerServiceFloat = () => {
const statusMap = {
1: { text: t('在线'), color: 'green' },
2: { text: t('忙碌'), color: 'orange' },
0: { text: t('离线'), color: 'grey' },
0: { text: t('离线'), color: 'default' },
};
const s = statusMap[status] || statusMap[0];
return (
<Tag color={s.color} size='small'>
{s.text}
</Tag>
);
return <Tag color={s.color}>{s.text}</Tag>;
};
// 如果没有启用客服,不显示
@@ -268,241 +251,163 @@ const CustomerServiceFloat = () => {
const hasContact = hasQrcode || currentAgent?.wecom_url;
return (
<div className='customer-service-container' ref={containerRef}>
{/* 移动端遮罩:点击关闭(桌面端通过点击外部关闭,遮罩隐藏不挡操作) */}
<div
className='customer-service-container'
ref={containerRef}
style={{
'--cs-surface': token.colorBgContainer,
'--cs-text': token.colorText,
'--cs-muted': token.colorTextSecondary,
'--cs-border': token.colorBorderSecondary,
'--cs-fill': token.colorFillQuaternary,
'--cs-hover': token.colorFillTertiary,
'--cs-primary': token.colorPrimary,
'--cs-primary-bg': token.colorPrimaryBg,
'--cs-primary-border': token.colorPrimaryBorder,
'--cs-primary-text': token.colorPrimaryText,
'--cs-mask': token.colorBgMask,
'--cs-shadow': token.boxShadowSecondary,
}}
>
{isOpen && (
<div className='cs-backdrop' onClick={handleClose} aria-hidden='true' />
)}
{/* 收起状态 - 边缘小标签 */}
{!isOpen && isCollapsed && (
<Tooltip content={t('联系客服')} position='left'>
<button
className='cs-collapsed-tab'
onClick={handleExpand}
<div className='cs-float-wrapper'>
<Tooltip title={isOpen ? t('关闭客服') : t('联系客服')}>
<Button
type='primary'
shape='circle'
className='cs-float-button'
onClick={isOpen ? handleClose : handleExpand}
ref={triggerRef}
aria-label={t('联系客服')}
>
<div className='cs-collapsed-icon'>
<MessageSquareMore size={18} strokeWidth={2.5} />
</div>
<div className='cs-collapsed-indicator' />
</button>
aria-label={isOpen ? t('关闭客服') : t('联系客服')}
icon={
isOpen ? (
<X size={22} strokeWidth={1.5} />
) : (
<Headphones size={22} strokeWidth={1.5} />
)
}
/>
</Tooltip>
)}
{/* 展开状态的浮动按钮 - 精美客服图标 */}
{!isOpen && !isCollapsed && (
<div className='cs-float-wrapper'>
<button
className='cs-float-button cs-has-pulse'
onClick={handleExpand}
ref={triggerRef}
aria-label={t('联系客服')}
>
{/* 装饰性光环 */}
<div className='cs-glow-ring' />
<div className='cs-glow-ring cs-glow-ring-2' />
{/* 主图标 */}
<div className='cs-icon-wrapper'>
<Headphones size={26} strokeWidth={2} />
</div>
{/* 在线状态指示器 */}
<div className='cs-online-indicator'>
<div className='cs-online-dot' />
</div>
{/* 悬浮文字提示 */}
<div className='cs-float-label'>
<span>{t('在线客服')}</span>
</div>
</button>
{/* 收起按钮 */}
<button
className='cs-collapse-btn'
onClick={toggleCollapse}
title={t('收起')}
aria-label={t('收起')}
>
<ChevronRight size={14} />
</button>
</div>
)}
{/* 展开的客服面板 */}
</div>
<div
className={`cs-panel ${isOpen ? 'cs-panel-open' : ''}`}
role='dialog'
aria-label={t('在线客服')}
aria-hidden={!isOpen}
/* 关闭时让面板内子元素(关闭按钮等)从 Tab 序列与可达性树中移除,
避免键盘焦点跑进屏幕外的隐藏面板(也消除 aria-hidden 含焦点元素的告警) */
inert={!isOpen ? '' : undefined}
tabIndex={-1}
ref={panelRef}
>
{/* 头部 - 渐变背景 */}
<div className='cs-panel-header'>
<div className='cs-header-content'>
<div className='cs-header-icon'>
<Headphones size={20} />
</div>
<div className='cs-header-text'>
<span className='cs-header-title'>{t('在线客服')}</span>
<span className='cs-header-subtitle'>{t('随时为您服务')}</span>
</div>
</div>
<span className='cs-header-title'>{t('在线客服')}</span>
<div className='cs-panel-actions'>
{currentAgent && (
<Button
size='small'
theme='borderless'
icon={<Users size={14} />}
onClick={switchAgent}
style={{
color: 'white',
background: 'rgba(255,255,255,0.2)',
borderRadius: '10px',
}}
>
{currentAgent && !showAgentList && (
<Button type='text' size='small' onClick={switchAgent}>
{t('切换')}
</Button>
)}
<button
<Button
type='text'
className='cs-close-btn'
onClick={handleClose}
aria-label={t('关闭')}
>
<X size={18} />
</button>
icon={<X size={16} strokeWidth={1.5} />}
/>
</div>
</div>
{/* 内容区 */}
<div className='cs-panel-content'>
{loading ? (
<div className='cs-loading'>
<Spin size='large' />
<p className='cs-loading-text'>{t('正在为您分配客服...')}</p>
<p>{t('正在为您分配客服...')}</p>
</div>
) : error ? (
<div className='cs-error'>
<Empty title={t('暂无可用客服')} description={error} />
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={error} />
<Button
icon={<RefreshCw size={14} />}
onClick={fetchAllocatedAgent}
style={{ marginTop: 16 }}
>
{t('重新获取')}
</Button>
</div>
) : showAgentList ? (
/* 客服选择列表 */
<div className='cs-agent-list'>
<p className='cs-list-title'>{t('请选择客服')}</p>
{agentList.length === 0 ? (
<Empty description={t('暂无在线客服')} />
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={t('暂无在线客服')}
/>
) : (
agentList.map((agent) => (
<div
<Button
key={agent.id}
className='cs-agent-item'
onClick={() => selectAgent(agent)}
>
<Avatar
src={agent.avatar}
size='small'
style={{ marginRight: 12, backgroundColor: '#87d068' }}
>
<Avatar src={agent.avatar} size={32}>
{agent.name?.[0]}
</Avatar>
<div className='cs-agent-info'>
<span className='cs-agent-name'>{agent.name}</span>
{getStatusTag(agent.status)}
</div>
<span className='cs-agent-name'>{agent.name}</span>
{getStatusTag(agent.status)}
<span className='cs-agent-busy'>
{agent.current_sessions}/{agent.max_sessions}
</span>
</div>
</Button>
))
)}
</div>
) : currentAgent ? (
/* 客服聊天界面 */
<div className='cs-chat-container'>
{/* 当前客服信息 */}
<div className='cs-current-agent'>
<Avatar
src={currentAgent.avatar}
size='small'
style={{ backgroundColor: '#87d068' }}
>
<Avatar src={currentAgent.avatar} size={32}>
{currentAgent.name?.[0]}
</Avatar>
<span style={{ marginLeft: 8 }}>{currentAgent.name}</span>
<span className='cs-agent-name'>{currentAgent.name}</span>
{getStatusTag(currentAgent.status)}
</div>
{/* 客服内容 */}
{hasContact ? (
<div className='cs-contact-container'>
{/* 二维码区域 */}
{hasQrcode && (
<div className='cs-qrcode'>
<div className='cs-qrcode-label'>
<QrCode size={16} />
<span>{t('扫码联系客服')}</span>
<p className='cs-qrcode-label'>{t('扫码联系客服')}</p>
<div className='cs-qrcode-frame'>
<img
src={currentAgent.qrcode_url}
alt={t('客服二维码')}
className='cs-qrcode-img'
onError={() => setQrcodeError(true)}
/>
</div>
<img
src={currentAgent.qrcode_url}
alt={t('客服二维码')}
className='cs-qrcode-img'
onError={() => setQrcodeError(true)}
/>
</div>
)}
{/* 跳转按钮区域 */}
{currentAgent.wecom_url && (
<div className='cs-wecom-link'>
{hasQrcode && (
<div className='cs-divider'>
<span>{t('或')}</span>
</div>
)}
<button
{hasQrcode && <Divider plain>{t('或')}</Divider>}
<Button
type='primary'
className='cs-wecom-btn'
onClick={() =>
window.open(currentAgent.wecom_url, '_blank')
}
>
<MessageCircle size={18} />
{t('打开微信客服')}
<Sparkles size={14} />
</button>
<Text
type='tertiary'
size='small'
style={{ marginTop: 12, opacity: 0.7 }}
>
{t('点击后将跳转至微信')}
</Text>
</Button>
</div>
)}
</div>
) : (
<div className='cs-no-contact'>
<Empty
description={
qrcodeError
? t('二维码加载失败,请稍后重试')
: t('客服信息配置不完整')
}
/>
</div>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={
qrcodeError
? t('二维码加载失败,请稍后重试')
: t('客服信息配置不完整')
}
/>
)}
</div>
) : null}