feat: 添加以图搜图功能(CLIP ONNX + pgvector)+ Dify会话修复 + 版本升至V3.30

This commit is contained in:
DXC
2026-05-21 14:09:57 +08:00
parent 621431dcb9
commit 1a7c06f197
11 changed files with 804 additions and 25 deletions

View File

@ -11,6 +11,15 @@
<script type="module" src="/src/main.ts"></script>
<script>
window.initDifyChatbot = function() {
// 【关键】增加保护检查:确保 DOM 已经就绪
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', performInit);
} else {
performInit();
}
};
function performInit() {
var currentToken = localStorage.getItem('access_token') || localStorage.getItem('token') || '';
var username = localStorage.getItem("username") || '';
@ -19,17 +28,16 @@
return;
}
// 【新增 1】彻底清理浏览器内存中残留的 Dify 全局对象
// 彻底清理浏览器内存中残留的 Dify 全局对象
window.difyChatbot = undefined;
delete window.difyChatbot;
// 【新增 2】清理旧的 DOM 节点
// 清理旧的 DOM 节点
var oldScript = document.getElementById('6T0eTgukUEqzK0iW');
if (oldScript) oldScript.remove();
document.querySelectorAll('[id^="dify-chatbot-"]').forEach(function(el) { el.remove(); });
// 【核心破解 3】动态化 user_id打破 Dify 会话锁定机制
// 取 token 的最后 8 位拼在用户名后。只要 Token 变了Dify 就会开启新会话,强制读取新 Token。
// 动态化 user_id打破 Dify 会话锁定机制
var dynamicUserId = username + '_' + currentToken.slice(-8);
window.difyChatbotConfig = {
@ -39,22 +47,20 @@
"user_token": currentToken
},
systemVariables: {
"user_id": dynamicUserId // <- 这里使用了动态 ID
"user_id": dynamicUserId
},
userVariables: {},
};
// 【新增 4】在脚本 URL 后加上时间戳,破除浏览器强缓存
// 重新挂载
var script = document.createElement('script');
script.src = 'http://172.16.0.198:8080/embed.min.js?t=' + new Date().getTime();
script.id = '6T0eTgukUEqzK0iW';
script.defer = true;
document.head.appendChild(script);
console.log('✅ Dify chatbot 已挂载新会话,当前绑定 ID:', dynamicUserId);
};
setTimeout(window.initDifyChatbot, 100);
console.log('✅ Dify chatbot 已挂载新会话,当前绑定 ID:', dynamicUserId);
}
</script>
<!--<script-->
@ -71,7 +77,7 @@
/* 变成"独立悬浮窗口" */
#dify-chatbot-bubble-window {
/* 👇 解除原本锁定在右下角的限制,将其定位在屏幕中间偏左上 */
/* 解除原本锁定在右下角的限制,将其定位在屏幕中间偏左上 */
top: 15vh !important;
left: 20vw !important;
bottom: auto !important;
@ -82,9 +88,9 @@
height: 70vh !important;
border-radius: 12px !important;
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2) !important; /* 增加超大弥散阴影,浮现感更强 */
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2) !important;
/* 👇 开启右下角拖拽,并强制留出 16px 的白边给拖拽手柄 */
/* 开启右下角拖拽,并强制留出 16px 的白边给拖拽手柄 */
resize: both !important;
overflow: hidden !important;
padding-bottom: 16px !important;
@ -124,4 +130,4 @@
});
</script>
</body>
</html>
</html>