Files
KCGL/inventory-web/index.html
2026-05-20 09:09:33 +08:00

128 lines
4.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/jetbrains://idea/navigate/reference?project=inventory-web&path=public%2Firis.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MOM</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<script>
window.initDifyChatbot = function() {
var currentToken = localStorage.getItem('access_token') || localStorage.getItem('token') || '';
var username = localStorage.getItem("username") || '';
if (!currentToken) {
console.log('未检测到 Token暂不加载 Dify');
return;
}
// 【新增 1】彻底清理浏览器内存中残留的 Dify 全局对象
window.difyChatbot = undefined;
delete window.difyChatbot;
// 【新增 2】清理旧的 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。
var dynamicUserId = username + '_' + currentToken.slice(-8);
window.difyChatbotConfig = {
token: '6T0eTgukUEqzK0iW',
baseUrl: 'http://172.16.0.198:8080',
inputs: {
"user_token": currentToken
},
systemVariables: {
"user_id": dynamicUserId // <- 这里使用了动态 ID
},
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);
</script>
<!--<script-->
<!-- src="http://172.16.0.198:8080/embed.min.js"-->
<!-- id="6T0eTgukUEqzK0iW"-->
<!-- defer>-->
<!--</script>-->
<style>
#dify-chatbot-bubble-button {
background-color: #409EFF !important;
box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4) !important;
}
/* 变成"独立悬浮窗口" */
#dify-chatbot-bubble-window {
/* 👇 解除原本锁定在右下角的限制,将其定位在屏幕中间偏左上 */
top: 15vh !important;
left: 20vw !important;
bottom: auto !important;
right: auto !important;
/* 设置初始宽高为半个屏幕左右 */
width: 60vw !important;
height: 70vh !important;
border-radius: 12px !important;
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2) !important; /* 增加超大弥散阴影,浮现感更强 */
/* 👇 开启右下角拖拽,并强制留出 16px 的白边给拖拽手柄 */
resize: both !important;
overflow: hidden !important;
padding-bottom: 16px !important;
padding-right: 16px !important;
background-color: #ffffff !important;
/* 极限尺寸防崩 */
min-width: 300px !important;
min-height: 400px !important;
max-width: 95vw !important;
max-height: 90vh !important;
}
/* 内层 iframe 填满剩余空间,加上圆角更好看 */
#dify-chatbot-bubble-window iframe {
width: 100% !important;
height: 100% !important;
border: none !important;
border-radius: 8px !important;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('click', function(event) {
var bubbleWindow = document.getElementById('dify-chatbot-bubble-window');
var bubbleButton = document.getElementById('dify-chatbot-bubble-button');
if (bubbleWindow && bubbleButton) {
var isWindowOpen = window.getComputedStyle(bubbleWindow).display !== 'none';
if (isWindowOpen && !bubbleWindow.contains(event.target) && !bubbleButton.contains(event.target)) {
bubbleButton.click();
}
}
});
});
</script>
</body>
</html>