优化内容自动滚动

This commit is contained in:
2025-10-27 13:44:13 +08:00
parent 9229444a2d
commit fc279a1b05
194 changed files with 45898 additions and 83 deletions

View File

@@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>新能源智能体</title>
<link rel="icon" href="./img/logo.png" type="image/x-icon">
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> -->
<style>
body {
margin: 0;
@@ -221,6 +223,7 @@
padding: 20px;
overflow-y: auto;
position: relative;
height: 400px
}
.message {
@@ -573,8 +576,8 @@
/* 按钮样式 */
.userinfo-toggle {
padding: 10px 16px;
border-radius: 50px;
padding: 7px 2px;
border-radius: 9px;
border: none;
background: #0057ff;
color: #fff;
@@ -582,7 +585,7 @@
cursor: pointer;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
transition: background 0.3s;
max-width: 70px;
max-width: 38px;
overflow-x: hidden;
}
@@ -877,6 +880,13 @@
</div>
<script src="./marked.min.js"></script>
<!-- <script>
// 开启 vConsole 调试面板
var vConsole = new VConsole();
console.log("✅ vConsole 已经启动");
</script> -->
@@ -898,6 +908,14 @@
console.log(params.get("userId"), 644);
const encodedUserId = params.get("userId");
const from = params.get("from");
const code = params.get("code");
const appid = "wx364b8ebf17fe45fe";
// 回调地址(必须和公众号后台配置的网页授权域名一致)
const redirect_uri = encodeURIComponent("http://ai.satabot.com");
// 授权方式:snsapi_base(静默) 或 snsapi_userinfo(需要用户确认)
const scope = "snsapi_userinfo";
// 自定义参数,授权后会原样返回
const state = "12399";
@@ -915,6 +933,34 @@
if (isMobile()) {
toggleSidebar();
}
console.log(isWeChat(), 999, code)
// if (isWeChat()) {
// if (code) {
// // gotoWeiXin();
// // 用 code 换取 openid 和 access_token
// fetch(`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appid}&secret=SECRET&code=CODE&grant_type=authorization_code?code=${code}`)
// .then(res => res.json())
// .then(data => {
// // data 里返回 userId / openid
// setCookie("userId", data.userId);
// window.location.href = "/"; // 回到首页
// });
// } else {
// // 没拿到 code,再次走 gotoWeiXin()
// gotoWeiXin();
// }
// } else {
if (getCookie("userId")) {
getSessionList();
} else {
deleteCookie('userId');
window.location.href = 'http://ri.satabot.com/#/login?goRemote=1&clear=1';
}
// }
const questions = document.querySelectorAll(".question");
// 获取到用户名称
function getUserName(userId) {
@@ -1061,18 +1107,23 @@
setTimeout(() => toast.remove(), 300); // 动画结束后移除
}, 2000);
}
// function toggleSidebar() {
// sidebar.classList.toggle("collapsed");
// }
function scrollToBottom() {
const chatMessages = document.getElementById("chatMessages");
setTimeout(() => {
if (!chatMessages) return;
requestAnimationFrame(() => {
chatMessages.scrollTop = chatMessages.scrollHeight;
chatMessages.bottom = '0px';
}, 0);
});
}
// function scrollToBottom() {
// const chatMessages = document.getElementById("chatMessages");
// setTimeout(() => {
// chatMessages.scrollTop = chatMessages.scrollHeight;
// chatMessages.bottom = '0px';
// }, 0);
// }
const panel = document.querySelector('.userinfo-panel');
const toggleButton = document.querySelector('.userinfo-toggle');
function toggleUserInfo() {
@@ -1094,7 +1145,6 @@
function renderChatList(isNew) {
console.log(sessIdList);
chatList.innerHTML = '';
if (!sessIdList || sessIdList.length == 0) {
@@ -1152,7 +1202,7 @@
}
addMessage(msg.content, msg.role, msg.image_base64);
});
scrollToBottom();
setTimeout(scrollToBottom, 0);
}
// 内容 角色 图片 创造时间
function addMessage(content = '', role = "assistant", imgUrl = null, time = null) {
@@ -1277,8 +1327,7 @@
const data = line.slice(5).trim();
if (data === "[DONE]") {
// 更新聊天滚动条
scrollToBottom();
// chatMessages.scrollTop = chatMessages.scrollHeight;
setTimeout(scrollToBottom, 0); // chatMessages.scrollTop = chatMessages.scrollHeight;
return;
}
@@ -1296,8 +1345,9 @@
for (const char of obj.content) {
aiMsg.content += char;
msgDiv.innerHTML = marked.parse(aiMsg.content);
chatMessages.scrollTop = chatMessages.scrollHeight;
scrollToBottom();
// chatMessages.scrollTop = chatMessages.scrollHeight;
setTimeout(scrollToBottom, 0);
}
}
if (obj.content && obj.type == 'title') {
@@ -1380,16 +1430,6 @@
}
// 初始化
// if (chats.length === 0) {
// newChat();
// } else {
// if (!activeChatId || !chats.find(c => c.id === activeChatId)) {
// activeChatId = chats[0].id;
// }
// renderChatList();
// renderMessages();
// }
function handleSendFile() {
console.log("选择文件");
@@ -1478,19 +1518,13 @@
// gotoWeiXin();
function gotoWeiXin() {
console.log(isWeChat(), 8888, navigator.userAgent);
if (isWeChat()) {
const appid = "wx549f4ae0f85eb3ea";
// 回调地址(必须和公众号后台配置的网页授权域名一致)
const redirect_uri = encodeURIComponent("http://ai.satabot.com/");
// 授权方式:snsapi_base(静默) 或 snsapi_userinfo(需要用户确认)
const scope = "snsapi_userinfo";
// 自定义参数,授权后会原样返回
const state = "123";
// 拼接完整的授权链接
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
// 跳转到微信授权
window.location.href = authUrl;
}
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
// 拼接完整的授权链接
// const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
// 跳转到微信授权
console.log("跳转链接:", authUrl);
window.location.href = authUrl;
}
@@ -1499,12 +1533,12 @@
// }else{
// }
if (getCookie("userId")) {
getSessionList();
} else {
deleteCookie('userId');
window.location.href = 'http://ri.satabot.com/#/login?goRemote=1&clear=1';
}
// if (!isWeChat()) {
// } else {
// gotoWeiXin();
// }
function getSessionList() {