fix:调整客服UI
This commit is contained in:
@@ -63,6 +63,59 @@ const BytedeskWidget = ({
|
||||
bytedesk.init();
|
||||
widgetRef.current = bytedesk;
|
||||
|
||||
// ⚡ H5 端样式适配:使用 MutationObserver 立即应用样式(避免闪烁)
|
||||
const isMobile = window.innerWidth <= 768;
|
||||
|
||||
const applyBytedeskStyles = () => {
|
||||
const allElements = document.querySelectorAll('body > div');
|
||||
allElements.forEach(el => {
|
||||
const style = window.getComputedStyle(el);
|
||||
// 检查是否是右下角固定定位的元素(Bytedesk 按钮)
|
||||
if (style.position === 'fixed' && style.right && style.bottom) {
|
||||
const rightVal = parseInt(style.right);
|
||||
const bottomVal = parseInt(style.bottom);
|
||||
if (rightVal >= 0 && rightVal < 100 && bottomVal >= 0 && bottomVal < 100) {
|
||||
// H5 端设置按钮尺寸为 48x48(只执行一次)
|
||||
if (isMobile && !el.dataset.bytedeskStyled) {
|
||||
el.dataset.bytedeskStyled = 'true';
|
||||
const button = el.querySelector('button');
|
||||
if (button) {
|
||||
button.style.width = '48px';
|
||||
button.style.height = '48px';
|
||||
button.style.minWidth = '48px';
|
||||
button.style.minHeight = '48px';
|
||||
}
|
||||
}
|
||||
// 提示框 3 秒后隐藏(查找白色气泡框)
|
||||
const children = el.querySelectorAll('div');
|
||||
children.forEach(child => {
|
||||
if (child.dataset.bytedeskTooltip) return; // 已处理过
|
||||
const childStyle = window.getComputedStyle(child);
|
||||
// 白色背景的提示框
|
||||
if (childStyle.backgroundColor === 'rgb(255, 255, 255)') {
|
||||
child.dataset.bytedeskTooltip = 'true';
|
||||
setTimeout(() => {
|
||||
child.style.transition = 'opacity 0.3s';
|
||||
child.style.opacity = '0';
|
||||
setTimeout(() => child.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 立即执行一次
|
||||
applyBytedeskStyles();
|
||||
|
||||
// 监听 DOM 变化,新元素出现时立即应用样式
|
||||
const observer = new MutationObserver(applyBytedeskStyles);
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
// 5 秒后停止监听(避免性能问题)
|
||||
setTimeout(() => observer.disconnect(), 5000);
|
||||
|
||||
// ⚡ 屏蔽 STOMP WebSocket 错误日志(不影响功能)
|
||||
const originalConsoleError = console.error;
|
||||
console.error = function(...args) {
|
||||
|
||||
Reference in New Issue
Block a user