fix(widget): 完善自动回复与新会话进线提醒
CI / Backend (go vet + test) (push) Failing after 40m21s
CI / Frontend (typecheck + lint + build) (push) Successful in 1h21m3s

This commit is contained in:
yml2213
2026-11-03 19:29:32 +08:00
parent 0eb16c1ce2
commit 24fac1bcf1
15 changed files with 275 additions and 115 deletions
+15
View File
@@ -18,6 +18,7 @@
console.warn('[kefu-widget] missing data-id on script tag');
return;
}
var autoOpen = !(script && /^(false|0)$/i.test(script.getAttribute('data-auto-open') || ''));
var src = script && script.src ? script.src : '';
var base = '';
@@ -139,6 +140,15 @@
}
}
function shouldAutoOpenOnce() {
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;
}
btn.addEventListener('click', function () { setOpen(true); });
window.addEventListener('message', function (event) {
@@ -188,6 +198,11 @@
function mount() {
document.body.appendChild(btn);
document.body.appendChild(panel);
if (autoOpen) {
window.setTimeout(function () {
if (!open && shouldAutoOpenOnce()) setOpen(true);
}, 600);
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', mount);