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) {