fix(widget): 优化访客在线续接与历史地区回填
CI / Backend (go vet + test) (push) Failing after 9m33s
CI / Frontend (typecheck + lint + build) (push) Successful in 11m57s

This commit is contained in:
yml2213
2026-11-06 18:51:44 +08:00
parent de1ffbf4f6
commit 93ef9f2040
6 changed files with 178 additions and 10 deletions
+21 -4
View File
@@ -143,6 +143,7 @@
function setOpen(next) {
open = next;
if (open) {
markSessionStarted();
ensureIframe();
panel.style.display = 'block';
btn.style.display = 'none';
@@ -164,12 +165,25 @@
}
function shouldAutoOpenOnce() {
if (hasStartedSession()) return false;
markSessionStarted();
return true;
}
function hasStartedSession() {
var key = 'kefu_widget_auto_opened_' + channelKey;
try {
return window.sessionStorage.getItem(key) === '1';
} catch (e) {
return false;
}
}
function markSessionStarted() {
var key = 'kefu_widget_auto_opened_' + channelKey;
try {
if (window.sessionStorage.getItem(key) === '1') return false;
window.sessionStorage.setItem(key, '1');
} catch (e) { /* privacy mode: fall back to opening on each page load */ }
return true;
} catch (e) { /* ignore */ }
}
btn.addEventListener('click', function () { setOpen(true); });
@@ -227,7 +241,10 @@
function mount() {
document.body.appendChild(btn);
document.body.appendChild(panel);
if (autoOpen) {
if (hasStartedSession()) {
// 同站后续页面保持隐藏 iframe 心跳和轨迹,不重复自动展开面板。
ensureIframe();
} else if (autoOpen) {
window.setTimeout(function () {
if (!open && shouldAutoOpenOnce()) setOpen(true);
}, 600);