加字体大小设置,修复人工客服轮询和限流问题
This commit is contained in:
+44
-28
@@ -1202,6 +1202,7 @@
|
||||
<span><span class="ai-icon">🤖</span><span id="app-title">柏悦物流智能助手</span></span>
|
||||
<span class="title-actions">
|
||||
<button id="lang-toggle" class="theme-toggle lang-toggle" title="中英文切换(Ctrl+L)">中</button>
|
||||
<button id="font-toggle" class="theme-toggle" title="字体大小">A</button>
|
||||
<button id="theme-toggle" class="theme-toggle" title="切换深色/浅色">🌙</button>
|
||||
</span>
|
||||
</div>
|
||||
@@ -1361,6 +1362,27 @@ window.__busy = false; // 生成中状态,用 window 属性避免作用域
|
||||
}
|
||||
})();
|
||||
|
||||
// ===== 字体大小切换 =====
|
||||
(function(){
|
||||
var KEY = "wuliu-fontsize";
|
||||
var SIZES = [14, 16, 18, 20];
|
||||
var idx = 1;
|
||||
try{ var s = localStorage.getItem(KEY); if(s) idx = parseInt(s); }catch(e){}
|
||||
var btn = document.getElementById("font-toggle");
|
||||
function apply(){
|
||||
document.body.style.fontSize = SIZES[idx] + "px";
|
||||
if(btn) btn.textContent = SIZES[idx] + "px";
|
||||
}
|
||||
apply();
|
||||
if(btn){
|
||||
btn.onclick = function(){
|
||||
idx = (idx + 1) % SIZES.length;
|
||||
apply();
|
||||
try{ localStorage.setItem(KEY, idx); }catch(e){}
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
// ===== 中英文切换 =====
|
||||
const I18N = {
|
||||
zh: {
|
||||
@@ -1872,62 +1894,56 @@ window.showHuman = async function(){
|
||||
addMsg("您已在人工客服会话中,请直接提问。", false);
|
||||
return;
|
||||
}
|
||||
const now = new Date();
|
||||
const day = now.getDay();
|
||||
const h = now.getHours();
|
||||
const work = (day >= 1 && day <= 5) && (h >= 9 && h < 18);
|
||||
var now = new Date();
|
||||
var day = now.getDay();
|
||||
var h = now.getHours();
|
||||
var work = (day >= 1 && day <= 5) && (h >= 9 && h < 19);
|
||||
if(!work){
|
||||
addMsg("人工客服工作时间:周一至周五 9:00-18:00\n当前非工作时间,留言后工作时间内会尽快回复。", false);
|
||||
return;
|
||||
}
|
||||
addMsg("正在为您转接人工客服...", false);
|
||||
if(!currentConvId) await ensureConv();
|
||||
fetch("/api/human/request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conv_id:currentConvId})})
|
||||
.then(r=>r.json()).then(d=>{
|
||||
if(!currentConvId){
|
||||
try{ await ensureConv(); }catch(e){}
|
||||
}
|
||||
fetch("/api/human/request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conv_id:currentConvId||0})})
|
||||
.then(function(r){return r.json()})
|
||||
.then(function(d){
|
||||
if(d.ok){
|
||||
window.humanSid = d.session_id;
|
||||
addMsg("您已加入人工排队,请稍候...", false);
|
||||
startHumanPoll();
|
||||
}else{
|
||||
addMsg("转接失败,请稍后再试。", false);
|
||||
}
|
||||
})
|
||||
.catch(function(){
|
||||
addMsg("网络错误,请稍后再试。", false);
|
||||
});
|
||||
}
|
||||
window.humanSid = 0;
|
||||
function startHumanPoll(){
|
||||
let last=0;
|
||||
let typingShown=null;
|
||||
const t=setInterval(()=>{
|
||||
if(!window.humanSid){ clearInterval(t); return; }
|
||||
fetch("/api/human/poll?sid="+window.humanSid+"&after="+last).then(r=>r.json()).then(d=>{
|
||||
fetch("/api/human/poll?sid="+window.humanSid+"&after="+last)
|
||||
.then(r=>r.json())
|
||||
.then(d=>{
|
||||
if(d.status==="closed"){
|
||||
clearInterval(t);
|
||||
window.humanSid=0;
|
||||
window.__busy=false;
|
||||
if(typeof setBusy==="function") setBusy(false);
|
||||
addMsg("人工客服已结束,您可以继续向 AI 提问。", false);
|
||||
inputDom.focus();
|
||||
return;
|
||||
}
|
||||
if(typingShown){ typingShown.remove(); typingShown=null; }
|
||||
if(d.typing){
|
||||
typingShown = addMsg("对方正在输入...", false);
|
||||
}
|
||||
d.messages.forEach(m=>{
|
||||
last=m.id;
|
||||
if(m.side==="agent"){
|
||||
addMsg(m.content, false);
|
||||
}
|
||||
if(m.side==="agent") addMsg(m.content, false);
|
||||
});
|
||||
// 已读回执:标记最后一条用户消息
|
||||
if(d.messages.some(m=>m.side==="customer" && m.read)){
|
||||
const rows=document.querySelectorAll(".msg-row.user-line");
|
||||
if(rows.length){
|
||||
const last=rows[rows.length-1];
|
||||
const ts=last.querySelector(".msg-time");
|
||||
if(ts && !ts.textContent.includes("已读")) ts.textContent += " ✓已读";
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
})
|
||||
.catch(()=>{});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function addMsg(content, isUser){
|
||||
|
||||
Reference in New Issue
Block a user