修复微信端获取不到会话列表
This commit is contained in:
78
index.html
78
index.html
@@ -1559,13 +1559,13 @@
|
||||
});
|
||||
}
|
||||
function isMobile() {
|
||||
// 获取UA字符串
|
||||
const userAgent = navigator.userAgent;
|
||||
// 匹配主流手机相关关键词,忽略大小写
|
||||
const mobileRegex = /iPhone|Android|BlackBerry|IEMobile|Opera Mini|RedMi|Huawei|Vivo/i;
|
||||
// 返回匹配结果
|
||||
return mobileRegex.test(userAgent);
|
||||
}
|
||||
// 获取UA字符串
|
||||
const userAgent = navigator.userAgent;
|
||||
// 匹配主流手机相关关键词,忽略大小写
|
||||
const mobileRegex = /iPhone|Android|BlackBerry|IEMobile|Opera Mini|RedMi|Huawei|Vivo/i;
|
||||
// 返回匹配结果
|
||||
return mobileRegex.test(userAgent);
|
||||
}
|
||||
function bindToLogin() {
|
||||
document.querySelector('.popbox .loading-box').classList.remove('none');
|
||||
const data = {
|
||||
@@ -1673,6 +1673,9 @@
|
||||
}
|
||||
|
||||
function getUserByOpenId(id) {
|
||||
if (document.querySelector(".weixin-loading").classList.contains("none")) {
|
||||
document.querySelector(".weixin-loading").classList.remove("none");
|
||||
}
|
||||
const data = {
|
||||
sourceType: 5,
|
||||
openId: id,
|
||||
@@ -1693,6 +1696,7 @@
|
||||
} else if (res.code == 200) {
|
||||
setCookie('token', res.token);
|
||||
userId = res.userId;
|
||||
getSessionList();
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -1700,6 +1704,9 @@
|
||||
showToast("网络异常,请稍后再试");
|
||||
})
|
||||
.finally(() => {
|
||||
if (!document.querySelector(".weixin-loading").classList.contains("none")) {
|
||||
document.querySelector(".weixin-loading").classList.add("none");
|
||||
}
|
||||
console.log("登录请求结束");
|
||||
});
|
||||
// fetch("https://ai.satabot.com/api/remote/login", {
|
||||
@@ -1945,7 +1952,7 @@
|
||||
panel.classList.remove('show');
|
||||
}
|
||||
const chatbox = document.querySelector(".chat-input");
|
||||
if (!sidebar.contains(e.target) && !chatbox.contains(e.target)&& isMobile()) {
|
||||
if (!sidebar.contains(e.target) && !chatbox.contains(e.target) && isMobile()) {
|
||||
if (!sidebar.classList.contains("collapsed")) {
|
||||
sidebar.classList.add("collapsed");
|
||||
toggleBtn.style.left = "10px"; // 收起后
|
||||
@@ -2082,10 +2089,10 @@
|
||||
chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
}
|
||||
function uuid() {
|
||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2145,21 +2152,21 @@
|
||||
getAiResponse(imgUrl);
|
||||
}
|
||||
let renderPending = false;
|
||||
let lastRendered = "";
|
||||
let lastRendered = "";
|
||||
|
||||
// 实时渲染 + 不闪烁 + 性能好
|
||||
function smartRender(msgDiv, text) {
|
||||
if (renderPending) return; // 避免频繁渲染
|
||||
// 实时渲染 + 不闪烁 + 性能好
|
||||
function smartRender(msgDiv, text) {
|
||||
if (renderPending) return; // 避免频繁渲染
|
||||
|
||||
renderPending = true;
|
||||
requestAnimationFrame(() => {
|
||||
if (lastRendered !== text) {
|
||||
msgDiv.innerHTML = marked.parse(text); // 实时解析 Markdown
|
||||
lastRendered = text;
|
||||
}
|
||||
renderPending = false;
|
||||
});
|
||||
}
|
||||
renderPending = true;
|
||||
requestAnimationFrame(() => {
|
||||
if (lastRendered !== text) {
|
||||
msgDiv.innerHTML = marked.parse(text); // 实时解析 Markdown
|
||||
lastRendered = text;
|
||||
}
|
||||
renderPending = false;
|
||||
});
|
||||
}
|
||||
let reader;
|
||||
const getAiResponse = async (img) => {
|
||||
|
||||
@@ -2189,7 +2196,7 @@ function smartRender(msgDiv, text) {
|
||||
// ✅ 创建 AbortController
|
||||
controller = new AbortController();
|
||||
// sendParam.requestId = crypto.randomUUID();
|
||||
sendParam.requestId=uuid();
|
||||
sendParam.requestId = uuid();
|
||||
|
||||
const res = await fetch("https://serviceai.satabot.com/analyze", {
|
||||
method: "POST",
|
||||
@@ -2199,9 +2206,11 @@ function smartRender(msgDiv, text) {
|
||||
}).catch(err => {
|
||||
console.log("✅ 流被中断:", err.name);
|
||||
clearInterval(interval);
|
||||
controller.abort();
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
controller = null;
|
||||
}
|
||||
|
||||
controller = null;
|
||||
|
||||
|
||||
const sendBtnImg = document.querySelector('#sendBtn img');
|
||||
@@ -2273,7 +2282,7 @@ function smartRender(msgDiv, text) {
|
||||
stopBtn.classList.add('none');
|
||||
msgDiv.innerHTML = marked.parse(aiMsg.content);
|
||||
|
||||
|
||||
|
||||
setTimeout(scrollToBottom, 0); // chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
|
||||
return;
|
||||
@@ -2300,7 +2309,7 @@ function smartRender(msgDiv, text) {
|
||||
// msgDiv.innerHTML = marked.parse(aiMsg.content);
|
||||
|
||||
// chatMessages.scrollTop = chatMessages.scrollHeight;
|
||||
setTimeout(scrollToBottom, 0);
|
||||
// setTimeout(scrollToBottom, 0);
|
||||
}
|
||||
}
|
||||
if (obj.content && obj.type == 'title') {
|
||||
@@ -2746,10 +2755,11 @@ function smartRender(msgDiv, text) {
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
controller = null;
|
||||
if (sendBtnImg.classList.contains('none')) {
|
||||
sendBtnImg.classList.remove('none');
|
||||
stopBtn.classList.add('none')
|
||||
}
|
||||
}
|
||||
|
||||
if (sendBtnImg.classList.contains('none')) {
|
||||
sendBtnImg.classList.remove('none');
|
||||
stopBtn.classList.add('none')
|
||||
}
|
||||
});
|
||||
// DOM 加载完成后执行
|
||||
|
||||
Reference in New Issue
Block a user