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,251 @@
/*
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, useEffect } from 'react';
import { Avatar, Button } from '@douyinfe/semi-ui';
import {
MessageCircle,
Sparkles,
ScanLine,
Zap,
ArrowRight,
} from 'lucide-react';
import { API } from '../../helpers';
import { useTranslation } from 'react-i18next';
/**
* 自定义 Hook:获取客服展示数据
* 供父组件使用,避免多个 CustomerServiceQRCard 实例重复请求
*/
export const useCustomerServiceDisplay = () => {
const [loading, setLoading] = useState(true);
const [agent, setAgent] = useState(null);
const [hasConfig, setHasConfig] = useState(false);
useEffect(() => {
const fetchCustomerService = async () => {
try {
// 先检查是否有启用的客服配置
const configRes = await API.get('/api/customer-service/config');
if (configRes.data.success && configRes.data.data?.enabled) {
setHasConfig(true);
// 使用专门的展示接口获取客服信息(只读,不增加会话计数)
const agentRes = await API.get('/api/customer-service/display');
if (agentRes.data.success && agentRes.data.data) {
setAgent(agentRes.data.data);
}
}
} catch (error) {
// 静默处理错误,不显示给用户
console.error('Failed to fetch customer service:', error);
} finally {
setLoading(false);
}
};
fetchCustomerService();
}, []);
// 检查客服是否至少有一种联系方式
const hasContactMethod = agent && (agent.qrcode_url || agent.wecom_url);
// 是否应该显示客服卡片
const showCard = !loading && hasConfig && !!agent && !!hasContactMethod;
return { loading, agent, hasConfig, showCard };
};
/**
* 客服二维码卡片组件(紧凑版)
* 用于在密钥管理页面侧边栏展示客服二维码,引导用户添加客服咨询
*
* @param {Object} props
* @param {Object} props.agent - 客服信息(由父组件通过 useCustomerServiceDisplay 获取后传入)
*/
const CustomerServiceQRCard = ({ agent }) => {
const { t } = useTranslation();
const [qrcodeError, setQrcodeError] = useState(false);
// 如果没有客服数据,不显示组件
if (!agent) {
return null;
}
// 处理二维码加载失败
const handleQrcodeError = () => {
console.warn('QR code image failed to load:', agent.qrcode_url);
setQrcodeError(true);
};
return (
<div className='relative group/card'>
{/* 卡片外发光 */}
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from/20 via-brand-via/20 to-pink-500/20 rounded-[18px] blur-sm opacity-0 group-hover/card:opacity-100 transition-opacity duration-500' />
<div className='relative bg-white/80 dark:bg-neutral-900/80 backdrop-blur-xl rounded-2xl border border-gray-200/60 dark:border-neutral-800/60 overflow-hidden shadow-sm hover:shadow-lg transition-all duration-300'>
{/* 顶部渐变装饰条 */}
<div className='h-1 bg-gradient-to-r from-brand-from via-brand-via to-pink-500' />
<div className='p-4'>
{/* 标题 + 客服信息 合并为一行 */}
<div className='flex items-center gap-2.5 mb-3'>
{agent.avatar ? (
<div className='relative'>
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from to-brand-to rounded-full opacity-60 blur-[2px]' />
<Avatar
src={agent.avatar}
size='small'
className='relative !w-9 !h-9 border-2 border-white dark:border-neutral-800 flex-shrink-0'
/>
</div>
) : (
<div className='relative'>
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from to-brand-to rounded-full opacity-60 blur-[2px]' />
<div className='relative w-9 h-9 rounded-full bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center text-white font-bold text-xs flex-shrink-0'>
{agent.name ? (
agent.name.charAt(0)
) : (
<MessageCircle size={16} />
)}
</div>
</div>
)}
<div className='flex-1 min-w-0'>
<div className='flex items-center gap-1.5'>
<span className='font-semibold text-sm text-gray-900 dark:text-white truncate'>
{agent.name || t('专属客服')}
</span>
<span className='inline-flex items-center gap-1 px-1.5 py-0.5 bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400 rounded-full text-[10px] font-medium flex-shrink-0'>
<span className='w-1 h-1 bg-emerald-500 rounded-full animate-pulse'></span>
{t('在线')}
</span>
</div>
<p className='text-[11px] text-gray-400 dark:text-gray-500 mt-0.5'>
{t('1对1 密钥配置指导')}
</p>
</div>
</div>
{/* 提示文案 - 吸引用户扫码 */}
<div className='relative mb-3 overflow-hidden rounded-xl'>
{/* 动态渐变背景 */}
<div className='absolute inset-0 bg-gradient-to-r from-brand-from via-brand-via to-pink-500 opacity-[0.08] dark:opacity-[0.15]' />
<div className='absolute inset-0 bg-gradient-to-br from-amber-400/10 to-transparent' />
<div className='relative px-3 py-2.5 border border-brand/50 dark:border-brand-deep/30 rounded-xl'>
<div className='flex items-start gap-2'>
<div className='flex-shrink-0 mt-0.5'>
<div className='w-5 h-5 rounded-md bg-gradient-to-br from-amber-400 to-orange-500 flex items-center justify-center shadow-sm shadow-amber-400/30'>
<Zap size={11} className='text-white' />
</div>
</div>
<div className='flex-1 min-w-0'>
<p className='text-xs font-medium text-gray-800 dark:text-gray-200 leading-relaxed'>
{t('创建密钥后不知道怎么用?')}
</p>
<p className='text-[11px] text-brand-deep dark:text-brand-from font-medium mt-0.5 flex items-center gap-1'>
<Sparkles
size={10}
className='text-amber-500 flex-shrink-0'
/>
{t('扫码咨询获取帮助')}
<ArrowRight
size={10}
className='animate-bounce-x flex-shrink-0'
style={{
animation: 'bounce-x 1.5s ease-in-out infinite',
}}
/>
</p>
</div>
</div>
</div>
<style>{`
@keyframes bounce-x {
0%, 100% { transform: translateX(0); }
50% { transform: translateX(3px); }
}
`}</style>
</div>
{/* 二维码或联系方式 */}
{agent.qrcode_url && !qrcodeError ? (
<div className='flex flex-col items-center'>
{/* 二维码 */}
<div className='relative w-full group/qr'>
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from/20 via-brand-via/20 to-pink-400/20 rounded-xl blur opacity-0 group-hover/qr:opacity-100 transition-opacity duration-300' />
<div className='relative w-full p-3 bg-white dark:bg-neutral-800/50 rounded-xl border border-gray-100 dark:border-neutral-700/50 shadow-inner'>
<img
src={agent.qrcode_url}
alt={t('客服二维码')}
className='w-full aspect-square object-contain rounded-lg'
onError={handleQrcodeError}
/>
</div>
</div>
<div className='mt-2.5 flex items-center gap-1.5 px-3 py-1.5 bg-gradient-to-r from-brand-from/5 to-brand-to/5 dark:from-brand-from/20 dark:to-brand-to/20 rounded-full'>
<ScanLine
size={12}
className='text-brand dark:text-brand-from'
/>
<span className='text-xs font-medium text-brand-deep dark:text-brand-from'>
{t('微信扫码添加客服')}
</span>
</div>
{/* 备用企业微信按钮 */}
{agent.wecom_url && (
<Button
theme='light'
type='tertiary'
size='small'
icon={<MessageCircle size={12} />}
onClick={() => window.open(agent.wecom_url, '_blank')}
className='w-full !rounded-lg mt-2 !text-xs'
>
{t('或点击联系企微')}
</Button>
)}
</div>
) : agent.wecom_url ? (
/* 降级方案 */
<div className='text-center'>
{qrcodeError && (
<div className='mb-2 p-2 bg-amber-50 dark:bg-amber-900/20 rounded-lg'>
<p className='text-[11px] text-amber-600 dark:text-amber-400'>
{t('二维码加载失败,请点击下方按钮')}
</p>
</div>
)}
<Button
theme='solid'
type='primary'
icon={<MessageCircle size={14} />}
onClick={() => window.open(agent.wecom_url, '_blank')}
className='w-full !bg-gradient-to-r !from-brand-from !to-brand-to hover:!from-brand-from hover:!to-brand-to !rounded-xl'
>
{t('联系客服')}
</Button>
</div>
) : null}
</div>
</div>
</div>
);
};
export default CustomerServiceQRCard;
+515
View File
@@ -0,0 +1,515 @@
/*
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, useEffect, useCallback, useRef } from 'react';
import {
Avatar,
Tag,
Spin,
Empty,
Button,
Typography,
Tooltip,
} from '@douyinfe/semi-ui';
import {
MessageCircle,
X,
ChevronRight,
Users,
RefreshCw,
Headphones,
QrCode,
Sparkles,
MessageSquareMore,
} 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;
const CustomerServiceFloat = () => {
const { t } = useTranslation();
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([]);
const [showAgentList, setShowAgentList] = useState(false);
const [error, setError] = useState(null);
const [qrcodeError, setQrcodeError] = useState(false);
const [config, setConfig] = useState({ enabled: false });
// 当前持有 +1 会话计数的客服 id(仅 /allocate 会自增计数)
const allocatedIdRef = useRef(null);
// isOpen 的同步镜像,用于异步回调里判断面板是否已被关闭
const isOpenRef = useRef(false);
// 容器(点击外部关闭)、面板(打开时聚焦)、触发器(关闭后归还焦点)
const containerRef = useRef(null);
const panelRef = useRef(null);
const triggerRef = useRef(null);
// 结束当前持有的会话计数(精确释放 /allocate 自增的那一次)
const endAllocatedSession = useCallback(({ beacon = false } = {}) => {
const id = allocatedIdRef.current;
if (!id) return;
allocatedIdRef.current = null;
const path = `/api/customer-service/end/${id}`;
// 页面卸载场景用 sendBeacon,保证请求能在 unload 时发出(该接口公开、仅读 URL 参数)
if (beacon && typeof navigator !== 'undefined' && navigator.sendBeacon) {
try {
navigator.sendBeacon(`${getServerURL()}${path}`);
return;
} catch {
/* 退回普通请求 */
}
}
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);
};
// 获取客服配置
const fetchConfig = useCallback(async () => {
try {
const res = await API.get('/api/customer-service/config');
if (res.data.success) {
setConfig(res.data.data);
}
} catch (err) {
// 静默失败
}
}, []);
useEffect(() => {
fetchConfig();
}, [fetchConfig]);
// 获取分配的客服(会让后端 current_sessions +1)
const fetchAllocatedAgent = useCallback(async () => {
setLoading(true);
setError(null);
try {
const res = await API.get(
'/api/customer-service/allocate?strategy=weighted',
);
if (res.data.success && res.data.data) {
const agent = res.data.data;
// 竞态保护:如果分配返回前面板已关闭,立即释放刚分配的计数,不缓存
if (!isOpenRef.current) {
API.post(`/api/customer-service/end/${agent.id}`).catch(() => {});
return;
}
setCurrentAgent(agent);
allocatedIdRef.current = agent.id;
setQrcodeError(false);
} else {
setError(res.data.message || t('暂无可用客服'));
}
} catch (err) {
setError(t('获取客服失败,请重试'));
} finally {
setLoading(false);
}
}, [t]);
// 获取所有在线客服。silent=true 用于后台轮询,不触发整屏 loading(避免列表闪烁)
const fetchOnlineAgents = useCallback(async ({ silent = false } = {}) => {
if (!silent) setLoading(true);
try {
const res = await API.get('/api/customer-service/online');
if (res.data.success) {
setAgentList(res.data.data || []);
}
} catch (err) {
console.error('获取客服列表失败', err);
} finally {
if (!silent) setLoading(false);
}
}, []);
// 打开面板时自动获取客服(已缓存则不重复分配)
useEffect(() => {
if (isOpen && !currentAgent && !showAgentList) {
fetchAllocatedAgent();
}
}, [isOpen, currentAgent, showAgentList, fetchAllocatedAgent]);
// 在线列表停留期间轮询刷新,避免展示已下线/已满的客服
useEffect(() => {
if (!isOpen || !showAgentList) return;
const timer = setInterval(
() => fetchOnlineAgents({ silent: true }),
ONLINE_POLL_INTERVAL,
);
return () => clearInterval(timer);
}, [isOpen, showAgentList, fetchOnlineAgents]);
// 选择客服(仅展示,不触发 /allocate,因此不占用计数)
const selectAgent = (agent) => {
setCurrentAgent(agent);
setShowAgentList(false);
setQrcodeError(false);
};
// 切换客服:先释放当前会话计数,再展示在线列表
const switchAgent = () => {
endAllocatedSession();
setCurrentAgent(null);
setShowAgentList(true);
fetchOnlineAgents();
};
// 关闭面板:乐观关闭(不等待网络),释放会话计数,但保留已分配客服以便下次秒开
const handleClose = useCallback(() => {
endAllocatedSession();
setIsOpen(false);
setShowAgentList(false);
// 归还焦点到触发按钮(无障碍)
requestAnimationFrame(() => triggerRef.current?.focus?.());
}, [endAllocatedSession]);
// ESC 关闭 + 点击面板外部关闭
useEffect(() => {
if (!isOpen) return;
const onKeyDown = (e) => {
if (e.key === 'Escape') handleClose();
};
const onPointerDown = (e) => {
if (containerRef.current && !containerRef.current.contains(e.target)) {
handleClose();
}
};
document.addEventListener('keydown', onKeyDown);
document.addEventListener('mousedown', onPointerDown);
return () => {
document.removeEventListener('keydown', onKeyDown);
document.removeEventListener('mousedown', onPointerDown);
};
}, [isOpen, handleClose]);
// 打开后将焦点移入面板(无障碍);同时同步 isOpenRef 供异步回调判断
useEffect(() => {
isOpenRef.current = isOpen;
if (isOpen) {
requestAnimationFrame(() => panelRef.current?.focus?.());
}
}, [isOpen]);
// 页面卸载 / 组件卸载时兜底释放会话计数,避免计数泄漏
useEffect(() => {
const onPageHide = () => endAllocatedSession({ beacon: true });
window.addEventListener('pagehide', onPageHide);
return () => {
window.removeEventListener('pagehide', onPageHide);
endAllocatedSession();
};
}, [endAllocatedSession]);
const getStatusTag = (status) => {
const statusMap = {
1: { text: t('在线'), color: 'green' },
2: { text: t('忙碌'), color: 'orange' },
0: { text: t('离线'), color: 'grey' },
};
const s = statusMap[status] || statusMap[0];
return (
<Tag color={s.color} size='small'>
{s.text}
</Tag>
);
};
// 如果没有启用客服,不显示
if (!config.enabled) {
return null;
}
const hasQrcode = currentAgent?.qrcode_url && !qrcodeError;
const hasContact = hasQrcode || currentAgent?.wecom_url;
return (
<div className='customer-service-container' ref={containerRef}>
{/* 移动端遮罩:点击关闭(桌面端通过点击外部关闭,遮罩隐藏不挡操作) */}
{isOpen && (
<div className='cs-backdrop' onClick={handleClose} aria-hidden='true' />
)}
{/* 收起状态 - 边缘小标签 */}
{!isOpen && isCollapsed && (
<Tooltip content={t('联系客服')} position='left'>
<button
className='cs-collapsed-tab'
onClick={handleExpand}
ref={triggerRef}
aria-label={t('联系客服')}
>
<div className='cs-collapsed-icon'>
<MessageSquareMore size={18} strokeWidth={2.5} />
</div>
<div className='cs-collapsed-indicator' />
</button>
</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
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>
<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',
}}
>
{t('切换')}
</Button>
)}
<button
className='cs-close-btn'
onClick={handleClose}
aria-label={t('关闭')}
>
<X size={18} />
</button>
</div>
</div>
{/* 内容区 */}
<div className='cs-panel-content'>
{loading ? (
<div className='cs-loading'>
<Spin size='large' />
<p className='cs-loading-text'>{t('正在为您分配客服...')}</p>
</div>
) : error ? (
<div className='cs-error'>
<Empty title={t('暂无可用客服')} 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('暂无在线客服')} />
) : (
agentList.map((agent) => (
<div
key={agent.id}
className='cs-agent-item'
onClick={() => selectAgent(agent)}
>
<Avatar
src={agent.avatar}
size='small'
style={{ marginRight: 12, backgroundColor: '#87d068' }}
>
{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-busy'>
{agent.current_sessions}/{agent.max_sessions}
</span>
</div>
))
)}
</div>
) : currentAgent ? (
/* 客服聊天界面 */
<div className='cs-chat-container'>
{/* 当前客服信息 */}
<div className='cs-current-agent'>
<Avatar
src={currentAgent.avatar}
size='small'
style={{ backgroundColor: '#87d068' }}
>
{currentAgent.name?.[0]}
</Avatar>
<span style={{ marginLeft: 8 }}>{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>
</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
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>
</div>
)}
</div>
) : (
<div className='cs-no-contact'>
<Empty
description={
qrcodeError
? t('二维码加载失败,请稍后重试')
: t('客服信息配置不完整')
}
/>
</div>
)}
</div>
) : null}
</div>
</div>
</div>
);
};
export default CustomerServiceFloat;
+970
View File
@@ -0,0 +1,970 @@
/* 客服容器 */
.customer-service-container {
z-index: 1000;
}
/* 遮罩:桌面端隐藏(点击外部由 JS 处理,不阻挡页面操作),
移动端显示暗色遮罩,点击可关闭底部抽屉 */
.cs-backdrop {
position: fixed;
inset: 0;
z-index: 1001;
display: none;
background: transparent;
}
@media (max-width: 767.98px) {
.cs-backdrop {
display: block;
background: rgba(0, 0, 0, 0.45);
-webkit-backdrop-filter: blur(2px);
backdrop-filter: blur(2px);
animation: cs-backdrop-in 0.3s ease;
}
}
@keyframes cs-backdrop-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* ========================================
收起状态 - 边缘小标签
======================================== */
.cs-collapsed-tab {
position: fixed;
bottom: 120px;
right: 0;
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 48px;
padding: 0;
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
color: white;
border: none;
border-radius: 12px 0 0 12px;
cursor: pointer;
box-shadow:
-4px 0 15px color-mix(in srgb, var(--brand-primary) 30%, transparent),
inset 1px 0 0 rgba(255, 255, 255, 0.2);
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
z-index: 1001;
overflow: hidden;
}
.cs-collapsed-tab::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.15) 0%,
transparent 50%
);
border-radius: 12px 0 0 12px;
}
.cs-collapsed-tab:hover {
width: 48px;
box-shadow:
-6px 0 20px color-mix(in srgb, var(--brand-primary) 40%, transparent),
inset 1px 0 0 rgba(255, 255, 255, 0.3);
}
.cs-collapsed-icon {
position: relative;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
animation: cs-collapsed-bounce 2s ease-in-out infinite;
}
@keyframes cs-collapsed-bounce {
0%,
100% {
transform: translateX(0);
}
50% {
transform: translateX(-3px);
}
}
.cs-collapsed-indicator {
position: absolute;
top: 8px;
right: 8px;
width: 8px;
height: 8px;
background: #10b981;
border-radius: 50%;
box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
animation: cs-indicator-blink 1.5s infinite;
}
@keyframes cs-indicator-blink {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
/* ========================================
浮动按钮包装器
======================================== */
.cs-float-wrapper {
position: fixed;
bottom: 32px;
right: 32px;
z-index: 1001;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
}
/* ========================================
悬浮按钮 - 精美客服图标设计
======================================== */
.cs-float-button {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 64px;
height: 64px;
padding: 0;
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
color: white;
border: none;
border-radius: 22px;
cursor: pointer;
box-shadow:
0 8px 32px color-mix(in srgb, var(--brand-primary) 35%, transparent),
0 0 0 0 color-mix(in srgb, var(--brand-primary) 40%, transparent),
inset 0 1px 0 rgba(255, 255, 255, 0.2);
transition: all 0.4s cubic-bezier(0.34, 0.69, 0.1, 1);
overflow: visible;
}
.cs-float-button::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.25) 0%,
transparent 60%
);
border-radius: 22px;
}
.cs-float-button::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background: radial-gradient(
circle at 30% 30%,
rgba(255, 255, 255, 0.35) 0%,
transparent 50%
);
border-radius: 22px;
}
.cs-float-button:hover {
transform: translateY(-6px) scale(1.08);
box-shadow:
0 16px 40px color-mix(in srgb, var(--brand-primary) 45%, transparent),
0 0 0 6px color-mix(in srgb, var(--brand-primary) 12%, transparent),
inset 0 1px 0 rgba(255, 255, 255, 0.3);
border-radius: 24px;
}
.cs-float-button:hover .cs-float-label {
opacity: 1;
transform: translateX(0);
pointer-events: auto;
}
.cs-float-button:active {
transform: translateY(-3px) scale(1.04);
}
/* 光环效果 */
.cs-glow-ring {
position: absolute;
inset: -6px;
border: 2px solid color-mix(in srgb, var(--brand-primary) 30%, transparent);
border-radius: 28px;
animation: cs-glow-pulse 3s ease-in-out infinite;
}
.cs-glow-ring-2 {
inset: -12px;
border-color: color-mix(in srgb, var(--brand-primary) 15%, transparent);
border-radius: 34px;
animation-delay: 0.5s;
}
@keyframes cs-glow-pulse {
0%,
100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.05);
opacity: 0.6;
}
}
/* 悬浮按钮图标容器 */
.cs-float-button .cs-icon-wrapper {
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.3s;
}
.cs-float-button:hover .cs-icon-wrapper {
transform: scale(1.1);
}
/* 脉冲动画 */
.cs-float-button.cs-has-pulse {
animation: cs-button-breathe 4s ease-in-out infinite;
}
@keyframes cs-button-breathe {
0%,
100% {
box-shadow:
0 8px 32px color-mix(in srgb, var(--brand-primary) 35%, transparent),
0 0 0 0 color-mix(in srgb, var(--brand-primary) 40%, transparent),
inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
50% {
box-shadow:
0 12px 36px color-mix(in srgb, var(--brand-primary) 40%, transparent),
0 0 0 4px color-mix(in srgb, var(--brand-primary) 15%, transparent),
inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
}
/* 在线状态指示器 */
.cs-online-indicator {
position: absolute;
top: -4px;
right: -4px;
width: 18px;
height: 18px;
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
border: 3px solid white;
border-radius: 50%;
box-shadow:
0 2px 8px rgba(16, 185, 129, 0.5),
inset 0 1px 0 rgba(255, 255, 255, 0.3);
z-index: 3;
display: flex;
align-items: center;
justify-content: center;
}
.cs-online-dot {
width: 6px;
height: 6px;
background: white;
border-radius: 50%;
animation: cs-dot-pulse 1.5s infinite;
}
@keyframes cs-dot-pulse {
0%,
100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(0.8);
opacity: 0.7;
}
}
/* 悬浮文字提示 */
.cs-float-label {
position: absolute;
right: calc(100% + 12px);
top: 50%;
transform: translateY(-50%) translateX(10px);
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
padding: 8px 14px;
border-radius: 10px;
box-shadow:
0 4px 20px rgba(0, 0, 0, 0.1),
0 0 0 1px color-mix(in srgb, var(--brand-primary) 10%, transparent);
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
z-index: 1;
}
.cs-float-label span {
font-size: 13px;
font-weight: 600;
color: var(--brand-primary);
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.cs-float-label::after {
content: '';
position: absolute;
right: -6px;
top: 50%;
transform: translateY(-50%);
border: 6px solid transparent;
border-left-color: rgba(255, 255, 255, 0.95);
}
.dark .cs-float-label {
background: rgba(30, 30, 30, 0.95);
box-shadow:
0 4px 20px rgba(0, 0, 0, 0.3),
0 0 0 1px rgba(255, 255, 255, 0.1);
}
.dark .cs-float-label::after {
border-left-color: rgba(30, 30, 30, 0.95);
}
/* 收起按钮 */
.cs-collapse-btn {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
padding: 0;
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
color: var(--brand-primary);
border: 1px solid color-mix(in srgb, var(--brand-primary) 20%, transparent);
border-radius: 10px;
cursor: pointer;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transition: all 0.3s;
opacity: 0;
transform: translateX(10px);
}
.cs-float-wrapper:hover .cs-collapse-btn {
opacity: 1;
transform: translateX(0);
}
.cs-collapse-btn:hover {
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
color: white;
border-color: transparent;
transform: translateX(4px);
}
.dark .cs-collapse-btn {
background: rgba(40, 40, 40, 0.9);
border-color: rgba(255, 255, 255, 0.1);
}
.cs-button-text {
display: none;
}
/* ========================================
客服面板 - 现代玻璃态设计
======================================== */
.cs-panel {
position: fixed;
right: -420px;
top: 50%;
transform: translateY(-50%);
width: 380px;
height: 580px;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-radius: 24px;
box-shadow:
0 25px 50px -12px rgba(0, 0, 0, 0.15),
0 0 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
display: flex;
flex-direction: column;
overflow: hidden;
z-index: 1002;
opacity: 0;
pointer-events: none;
border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
}
.dark .cs-panel {
background: rgba(23, 23, 23, 0.95);
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow:
0 25px 50px -12px rgba(0, 0, 0, 0.5),
0 0 0 1px rgba(255, 255, 255, 0.05);
}
.cs-panel-open {
right: 24px;
opacity: 1;
pointer-events: auto;
}
/* ========================================
面板头部 - 渐变背景
======================================== */
.cs-panel-header {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 24px;
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
color: white;
overflow: hidden;
}
.cs-panel-header::before {
content: '';
position: absolute;
top: -50%;
right: -20%;
width: 200px;
height: 200px;
background: radial-gradient(
circle,
rgba(255, 255, 255, 0.15) 0%,
transparent 70%
);
border-radius: 50%;
}
.cs-panel-header::after {
content: '';
position: absolute;
bottom: -30%;
left: -10%;
width: 150px;
height: 150px;
background: radial-gradient(
circle,
rgba(255, 255, 255, 0.1) 0%,
transparent 70%
);
border-radius: 50%;
}
.cs-header-content {
position: relative;
z-index: 1;
display: flex;
align-items: center;
gap: 12px;
}
.cs-header-icon {
width: 40px;
height: 40px;
background: rgba(255, 255, 255, 0.2);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(10px);
}
.cs-header-text {
display: flex;
flex-direction: column;
}
.cs-header-title {
font-weight: 700;
font-size: 18px;
letter-spacing: -0.02em;
}
.cs-header-subtitle {
font-size: 12px;
opacity: 0.8;
margin-top: 2px;
}
.cs-panel-actions {
position: relative;
z-index: 1;
display: flex;
align-items: center;
gap: 8px;
}
.cs-close-btn {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border: none;
background: rgba(255, 255, 255, 0.2);
cursor: pointer;
border-radius: 10px;
color: white;
transition: all 0.2s;
backdrop-filter: blur(10px);
}
.cs-close-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: rotate(90deg);
}
/* ========================================
面板内容区
======================================== */
.cs-panel-content {
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
background: var(--semi-color-bg-0);
}
.cs-loading {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: var(--semi-color-text-2);
gap: 16px;
}
.cs-loading-text {
font-size: 14px;
color: var(--semi-color-text-2);
}
.cs-error {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 32px;
text-align: center;
}
/* ========================================
客服列表
======================================== */
.cs-agent-list {
flex: 1;
overflow-y: auto;
padding: 20px;
}
.cs-list-title {
font-size: 13px;
font-weight: 600;
color: var(--semi-color-text-2);
margin-bottom: 16px;
padding-left: 4px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.cs-agent-item {
display: flex;
align-items: center;
padding: 14px 16px;
border-radius: 16px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
margin-bottom: 10px;
border: 1px solid transparent;
background: var(--semi-color-fill-0);
}
.cs-agent-item:hover {
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-gradient-from) 8%, transparent) 0%,
color-mix(in srgb, var(--brand-gradient-to) 8%, transparent) 100%
);
transform: translateX(6px);
border-color: color-mix(in srgb, var(--brand-primary) 30%, transparent);
box-shadow: 0 4px 12px
color-mix(in srgb, var(--brand-primary) 10%, transparent);
}
.cs-agent-info {
flex: 1;
display: flex;
align-items: center;
gap: 10px;
margin-left: 12px;
}
.cs-agent-name {
font-weight: 600;
color: var(--semi-color-text-0);
font-size: 14px;
}
.cs-agent-busy {
font-size: 12px;
color: var(--semi-color-text-2);
background: var(--semi-color-fill-1);
padding: 2px 8px;
border-radius: 10px;
}
/* ========================================
聊天容器
======================================== */
.cs-chat-container {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.cs-current-agent {
display: flex;
align-items: center;
padding: 16px 20px;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-gradient-from) 5%, transparent) 0%,
color-mix(in srgb, var(--brand-gradient-to) 5%, transparent) 100%
);
gap: 10px;
border-bottom: 1px solid var(--semi-color-border);
}
.cs-current-agent-avatar {
position: relative;
}
.cs-current-agent-avatar .cs-agent-online {
position: absolute;
bottom: 0;
right: 0;
width: 10px;
height: 10px;
background: #10b981;
border: 2px solid white;
border-radius: 50%;
}
.cs-iframe {
flex: 1;
width: 100%;
border: none;
}
/* ========================================
二维码区域
======================================== */
.cs-contact-container {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 32px;
overflow-y: auto;
}
.cs-qrcode {
display: flex;
flex-direction: column;
align-items: center;
padding: 24px;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-gradient-from) 5%, transparent) 0%,
color-mix(in srgb, var(--brand-gradient-to) 5%, transparent) 100%
);
border-radius: 20px;
border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
}
.cs-qrcode-label {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 16px;
font-size: 14px;
font-weight: 500;
color: var(--semi-color-text-1);
}
.cs-qrcode-img {
max-width: 180px;
border-radius: 16px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
border: 1px solid var(--semi-color-border);
padding: 12px;
background: white;
transition: transform 0.3s;
}
.cs-qrcode-img:hover {
transform: scale(1.02);
}
.cs-wecom-link {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.cs-wecom-btn {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 14px 28px;
background: linear-gradient(
135deg,
var(--brand-gradient-from) 0%,
var(--brand-gradient-to) 100%
);
color: white;
border: none;
border-radius: 14px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 4px 15px
color-mix(in srgb, var(--brand-primary) 30%, transparent);
}
.cs-wecom-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px
color-mix(in srgb, var(--brand-primary) 40%, transparent);
}
.cs-divider {
display: flex;
align-items: center;
width: 100%;
margin: 24px 0;
color: var(--semi-color-text-2);
}
.cs-divider::before,
.cs-divider::after {
content: '';
flex: 1;
height: 1px;
background: linear-gradient(
90deg,
transparent,
var(--semi-color-border),
transparent
);
}
.cs-divider span {
padding: 0 16px;
font-size: 12px;
color: var(--semi-color-text-3);
}
.cs-no-contact {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
/* ========================================
暗黑模式适配
======================================== */
.dark .cs-float-button {
box-shadow:
0 4px 20px color-mix(in srgb, var(--brand-primary) 30%, transparent),
0 0 0 0 color-mix(in srgb, var(--brand-primary) 30%, transparent);
}
.dark .cs-float-button:hover {
box-shadow:
0 8px 30px color-mix(in srgb, var(--brand-primary) 40%, transparent),
0 0 0 4px color-mix(in srgb, var(--brand-primary) 10%, transparent);
}
.dark .cs-online-indicator {
border-color: #171717;
}
.dark .cs-qrcode {
background: rgba(255, 255, 255, 0.03);
border-color: rgba(255, 255, 255, 0.1);
}
.dark .cs-qrcode-img {
background: #1a1a1a;
border-color: rgba(255, 255, 255, 0.1);
}
/* ========================================
移动端适配
======================================== */
@media (max-width: 767.98px) {
.cs-float-wrapper {
/* --composer-top-offset 由聊天输入区(CustomInputRender)实测发布:
输入区顶边到视口底部的距离。聊天页(体验中心/控制台演练场)上浮球抬到
输入区之上,否则 90px 正好压住发送按钮;其他页面变量不存在,回退 90px。 */
bottom: calc(var(--composer-top-offset, 78px) + 12px);
right: 16px;
}
.cs-float-button {
width: 56px;
height: 56px;
border-radius: 18px;
}
.cs-glow-ring {
inset: -4px;
border-radius: 22px;
}
.cs-glow-ring-2 {
inset: -8px;
border-radius: 26px;
}
.cs-float-label {
display: none;
}
.cs-collapse-btn {
display: none;
}
.cs-collapsed-tab {
bottom: calc(var(--composer-top-offset, 78px) + 72px);
}
.cs-panel {
width: 100%;
height: 80vh;
right: 0;
top: auto;
bottom: 0;
transform: translateY(100%);
border-radius: 28px 28px 0 0;
opacity: 1;
border-bottom: none;
}
.cs-panel-open {
right: 0;
transform: translateY(0);
}
.cs-panel-header {
padding: 24px;
border-radius: 28px 28px 0 0;
}
.cs-close-btn {
width: 36px;
height: 36px;
}
}
/* ========================================
动画效果
======================================== */
@keyframes cs-float-in {
from {
opacity: 0;
transform: translateY(20px) scale(0.9);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.cs-float-button {
animation: cs-float-in 0.5s cubic-bezier(0.34, 0.69, 0.1, 1);
}
/* ========================================
降低动效偏好 - 关闭常驻/大幅动画
======================================== */
@media (prefers-reduced-motion: reduce) {
.cs-collapsed-icon,
.cs-collapsed-indicator,
.cs-float-button,
.cs-float-button.cs-has-pulse,
.cs-glow-ring,
.cs-glow-ring-2,
.cs-online-dot,
.cs-backdrop {
animation: none !important;
}
.cs-panel,
.cs-collapsed-tab,
.cs-float-button,
.cs-collapse-btn,
.cs-float-label,
.cs-agent-item,
.cs-qrcode-img,
.cs-wecom-btn {
transition-duration: 0.01ms !important;
}
}