|
@@ -186,6 +186,20 @@
|
|
|
window.visualViewport.addEventListener('resize',syncAppHeight);
|
|
window.visualViewport.addEventListener('resize',syncAppHeight);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ============================================================
|
|
|
|
|
+ // 用户行为埋点(fire-and-forget,不影响主流程)
|
|
|
|
|
+ // ============================================================
|
|
|
|
|
+ function track(type, data){
|
|
|
|
|
+ var payload = {event_type: type, event_data: data || {}, page_url: window.location.href};
|
|
|
|
|
+ var h = {'Content-Type': 'application/json'};
|
|
|
|
|
+ if (TOKEN) h['Authorization'] = 'Bearer ' + TOKEN;
|
|
|
|
|
+ try {
|
|
|
|
|
+ fetch(API_BASE + '/api/v1/analytics/events', {
|
|
|
|
|
+ method: 'POST', headers: h, body: JSON.stringify(payload), keepalive: true
|
|
|
|
|
+ }).catch(function(){});
|
|
|
|
|
+ } catch(e) {}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function authHeaders(){
|
|
function authHeaders(){
|
|
|
var h = {'Content-Type':'application/json'};
|
|
var h = {'Content-Type':'application/json'};
|
|
|
if (TOKEN) h['Authorization'] = 'Bearer ' + TOKEN;
|
|
if (TOKEN) h['Authorization'] = 'Bearer ' + TOKEN;
|
|
@@ -448,7 +462,7 @@
|
|
|
document.getElementById('chat').scrollTop=document.getElementById('chat').scrollHeight;
|
|
document.getElementById('chat').scrollTop=document.getElementById('chat').scrollHeight;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- window.quickAsk=function(t){document.getElementById('userInput').value=t;send()};
|
|
|
|
|
|
|
+ window.quickAsk=function(t){document.getElementById('userInput').value=t;track('click', {label: t});send()};
|
|
|
function resetSendBtn(){document.getElementById('sendBtn').disabled=false;document.getElementById('stopBtn').style.display='none'}
|
|
function resetSendBtn(){document.getElementById('sendBtn').disabled=false;document.getElementById('stopBtn').style.display='none'}
|
|
|
window.stopCurrent=function(){STREAMING=false;if(streamAbort){streamAbort.abort();streamAbort=null}resetSendBtn()};
|
|
window.stopCurrent=function(){STREAMING=false;if(streamAbort){streamAbort.abort();streamAbort=null}resetSendBtn()};
|
|
|
|
|
|
|
@@ -504,6 +518,7 @@
|
|
|
if(!text&&!hasMedia)return;input.value='';if(STREAMING)return;
|
|
if(!text&&!hasMedia)return;input.value='';if(STREAMING)return;
|
|
|
// 强鉴权:无 token 直接弹登录框
|
|
// 强鉴权:无 token 直接弹登录框
|
|
|
if(!TOKEN){ showLoginModal(); return; }
|
|
if(!TOKEN){ showLoginModal(); return; }
|
|
|
|
|
+ track('chat', {query: text});
|
|
|
doSend(text,hasMedia?pendingMedia:null);
|
|
doSend(text,hasMedia?pendingMedia:null);
|
|
|
};
|
|
};
|
|
|
function doSend(text,media){
|
|
function doSend(text,media){
|
|
@@ -656,6 +671,7 @@
|
|
|
renderDrugCards(ALL_DRUGS);
|
|
renderDrugCards(ALL_DRUGS);
|
|
|
};
|
|
};
|
|
|
window.switchTab=function(tab){
|
|
window.switchTab=function(tab){
|
|
|
|
|
+ track('switch_tab', {tab: tab});
|
|
|
document.querySelectorAll('.nav-btn').forEach(function(b){b.classList.toggle('active',b.dataset.tab===tab)});
|
|
document.querySelectorAll('.nav-btn').forEach(function(b){b.classList.toggle('active',b.dataset.tab===tab)});
|
|
|
document.getElementById('tabChat').classList.toggle('hidden',tab!=='chat');
|
|
document.getElementById('tabChat').classList.toggle('hidden',tab!=='chat');
|
|
|
document.getElementById('tabDrugs').classList.toggle('hidden',tab!=='drugs');
|
|
document.getElementById('tabDrugs').classList.toggle('hidden',tab!=='drugs');
|
|
@@ -669,6 +685,7 @@
|
|
|
};
|
|
};
|
|
|
// 初始化:打开本地数据库 → 恢复对话 → 预加载药品列表 → 加载快捷提问标签
|
|
// 初始化:打开本地数据库 → 恢复对话 → 预加载药品列表 → 加载快捷提问标签
|
|
|
(async function init(){
|
|
(async function init(){
|
|
|
|
|
+ track('page_view');
|
|
|
await openChatDB();
|
|
await openChatDB();
|
|
|
await restoreChat();
|
|
await restoreChat();
|
|
|
loadDrugList();
|
|
loadDrugList();
|