fix(widget): 优化访客在线续接与历史地区回填
This commit is contained in:
+21
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user