From 4750bfcf30232ed4710ca2f0338e02e18550dae9 Mon Sep 17 00:00:00 2001 From: zoujing Date: Tue, 26 Aug 2025 10:54:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=E4=BA=86=E5=85=89?= =?UTF-8?q?=E6=A0=87=20=E7=BC=A9=E7=9F=AD=E6=89=93=E5=8D=B0=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat/ChatMainList.vue | 4 ++-- utils/TypewriterManager.js | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue index ad3c640..24ee1e8 100644 --- a/pages/chat/ChatMainList.vue +++ b/pages/chat/ChatMainList.vue @@ -526,8 +526,8 @@ const initTypewriterManager = () => { } typewriterManager = new TypewriterManager({ - typingSpeed: 50, - cursorText: '|', + typingSpeed: 30, + cursorText: '', }); // 设置回调函数 diff --git a/utils/TypewriterManager.js b/utils/TypewriterManager.js index 2c8089f..894c9dc 100644 --- a/utils/TypewriterManager.js +++ b/utils/TypewriterManager.js @@ -7,7 +7,7 @@ class TypewriterManager { // 配置选项 this.options = { typingSpeed: 50, // 打字速度(毫秒) - cursorText: '|', // 光标样式 + cursorText: '', // 光标样式 ...options }; @@ -59,7 +59,7 @@ class TypewriterManager { if (this.isTyping) return; this.isTyping = true; - this.displayedContent = ""; + // 不要在启动时重置displayedContent,而是从当前位置继续 this._typeNextChar(); } @@ -75,7 +75,7 @@ class TypewriterManager { this.displayedContent.length + 1 ); - const displayContent = this.displayedContent + this.options.cursorText; + const displayContent = this.displayedContent; // 调用内容更新回调 if (this.onContentUpdate) { @@ -87,10 +87,12 @@ class TypewriterManager { this.onCharacterTyped(this.displayedContent); } - // 继续下一个字符 + // 确保最小延迟,避免定时器堆积 + const delay = Math.max(this.options.typingSpeed, 30); // 设置最小延迟30ms this.typewriterTimer = setTimeout(() => { this._typeNextChar(); - }, this.options.typingSpeed); + }, delay); + } else { // 打字完成,移除光标 if (this.onContentUpdate) {