feat(bytedesk): 集成 Bytedesk 客服系统
新增 Bytedesk 在线客服功能,支持实时对话: 组件: - BytedeskWidget: 客服浮窗组件(右下角) - 配置文件: bytedesk.config.js 统一管理配置 - 环境变量示例: .env.bytedesk.example 集成方式: - GlobalComponents 引入 BytedeskWidget - public/index.html 加载 bytedesk-web.js 脚本 - 支持环境变量配置(ORG、SID、API_URL) 配置说明详见 src/bytedesk-integration/.env.bytedesk.example 🔧 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -84,6 +84,90 @@
|
||||
// name: 'YOU CAN DEFINE USER NAME HERE',
|
||||
},
|
||||
}
|
||||
|
||||
// 根据路径控制Dify机器人显示(只在首页/和home页/home显示)
|
||||
function controlDifyChatbot() {
|
||||
const path = window.location.pathname;
|
||||
const chatbotButton = document.getElementById('dify-chatbot-bubble-button');
|
||||
const chatbotWindow = document.getElementById('dify-chatbot-bubble-window');
|
||||
|
||||
// 只在首页(/)和home页(/home)显示Dify机器人
|
||||
// const shouldShowDify = (path === '/' || path === '/home');
|
||||
// 完全不显示Dify机器人(只使用Bytedesk客服)
|
||||
const shouldShowDify = false
|
||||
|
||||
if (chatbotButton) {
|
||||
chatbotButton.style.display = shouldShowDify ? 'block' : 'none';
|
||||
// 同时设置visibility确保完全隐藏
|
||||
chatbotButton.style.visibility = shouldShowDify ? 'visible' : 'hidden';
|
||||
}
|
||||
|
||||
if (chatbotWindow) {
|
||||
chatbotWindow.style.display = shouldShowDify ? '' : 'none';
|
||||
}
|
||||
|
||||
console.log('[Dify] Path:', path, 'Should show:', shouldShowDify, 'Button found:', !!chatbotButton);
|
||||
}
|
||||
|
||||
// 轮询检查Dify按钮(因为Dify脚本加载是异步的)
|
||||
let difyCheckCount = 0;
|
||||
const difyCheckInterval = setInterval(function() {
|
||||
const button = document.getElementById('dify-chatbot-bubble-button');
|
||||
if (button || difyCheckCount > 50) { // 最多检查5秒
|
||||
if (button) {
|
||||
console.log('[Dify] Button found, applying control');
|
||||
controlDifyChatbot();
|
||||
}
|
||||
clearInterval(difyCheckInterval);
|
||||
}
|
||||
difyCheckCount++;
|
||||
}, 100);
|
||||
|
||||
// 页面加载时执行
|
||||
window.addEventListener('load', function() {
|
||||
setTimeout(controlDifyChatbot, 1000);
|
||||
});
|
||||
|
||||
// 监听路由变化(React Router使用pushState)
|
||||
window.addEventListener('popstate', controlDifyChatbot);
|
||||
|
||||
// 监听pushState和replaceState(捕获React Router导航)
|
||||
const originalPushState = history.pushState;
|
||||
const originalReplaceState = history.replaceState;
|
||||
|
||||
history.pushState = function() {
|
||||
originalPushState.apply(history, arguments);
|
||||
setTimeout(controlDifyChatbot, 50);
|
||||
};
|
||||
|
||||
history.replaceState = function() {
|
||||
originalReplaceState.apply(history, arguments);
|
||||
setTimeout(controlDifyChatbot, 50);
|
||||
};
|
||||
|
||||
// 使用MutationObserver监听DOM变化(捕获Dify按钮插入)
|
||||
const observer = new MutationObserver(function(mutations) {
|
||||
for (const mutation of mutations) {
|
||||
if (mutation.addedNodes.length > 0) {
|
||||
for (const node of mutation.addedNodes) {
|
||||
if (node.id && (node.id.includes('dify') || node.id.includes('chatbot'))) {
|
||||
console.log('[Dify] Detected chatbot element insertion:', node.id);
|
||||
setTimeout(controlDifyChatbot, 100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 观察body的变化
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: false
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script
|
||||
src="https://app.valuefrontier.cn/embed.min.js"
|
||||
|
||||
Reference in New Issue
Block a user