|
@@ -12,12 +12,32 @@ class ChatUI {
|
|
|
}
|
|
|
this.aiService = window.aiService;
|
|
|
|
|
|
- this.typingSpeed = 50; // 打字速度(毫秒/字符)
|
|
|
+ this.typingSpeed = 50;
|
|
|
+ this.inputWrapper = document.querySelector(".input-wrapper");
|
|
|
+
|
|
|
+ // 先添加过渡动画类
|
|
|
+ this.input.classList.add("input-transition");
|
|
|
|
|
|
+ // 设置初始高度
|
|
|
+ this.input.style.height = "40px";
|
|
|
+
|
|
|
+ // 初始化其他组件
|
|
|
this.setupEventListeners();
|
|
|
- this.adjustInputHeight();
|
|
|
this.init();
|
|
|
|
|
|
+ // 使用微任务确保DOM更新后再调整高度
|
|
|
+ Promise.resolve().then(() => {
|
|
|
+ // 第一帧:等待过渡动画类生效
|
|
|
+ requestAnimationFrame(() => {
|
|
|
+ // 第二帧:执行高度调整
|
|
|
+ requestAnimationFrame(() => {
|
|
|
+ this.adjustInputHeight();
|
|
|
+ // 触发一次输入框focus以确保正确的高度
|
|
|
+ this.input.focus();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
// 添加新消息指示器
|
|
|
this.createNewMessageIndicator();
|
|
|
|
|
@@ -45,7 +65,6 @@ class ChatUI {
|
|
|
|
|
|
this.isTyping = false; // 添加打字状态标记
|
|
|
this.loadingDiv = null; // 添加加载动画的引用
|
|
|
- this.inputWrapper = document.querySelector(".input-wrapper");
|
|
|
|
|
|
// 初始化页面信息卡片
|
|
|
this.initPageInfoCard();
|
|
@@ -74,6 +93,11 @@ class ChatUI {
|
|
|
// 自动调整输入框高度
|
|
|
this.input.addEventListener("input", () => this.adjustInputHeight());
|
|
|
|
|
|
+ // 添加focus事件监听,确保在获得焦点时高度正确
|
|
|
+ this.input.addEventListener("focus", () => {
|
|
|
+ requestAnimationFrame(() => this.adjustInputHeight());
|
|
|
+ });
|
|
|
+
|
|
|
// 快捷指令面板
|
|
|
this.promptButton.addEventListener("click", () => this.togglePromptPanel());
|
|
|
document.querySelector(".close-prompt").addEventListener("click", () => {
|
|
@@ -271,8 +295,24 @@ class ChatUI {
|
|
|
}
|
|
|
|
|
|
adjustInputHeight() {
|
|
|
+ const scrollPos = this.input.scrollTop;
|
|
|
+
|
|
|
+ // 获取当前高度
|
|
|
+ const currentHeight = this.input.style.height;
|
|
|
+
|
|
|
+ // 重置高度
|
|
|
this.input.style.height = "auto";
|
|
|
- this.input.style.height = Math.min(this.input.scrollHeight, 120) + "px";
|
|
|
+
|
|
|
+ // 计算新高度
|
|
|
+ const newHeight = Math.min(this.input.scrollHeight, 120);
|
|
|
+
|
|
|
+ // 如果高度有变化才设置
|
|
|
+ if (currentHeight !== `${newHeight}px`) {
|
|
|
+ this.input.style.height = `${newHeight}px`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 恢复滚动位置
|
|
|
+ this.input.scrollTop = scrollPos;
|
|
|
}
|
|
|
|
|
|
scrollToBottom() {
|