@flexem/chat-box 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -332,6 +332,15 @@ Component({
|
|
|
332
332
|
* 语音按钮按下
|
|
333
333
|
*/
|
|
334
334
|
onVoiceStart(e) {
|
|
335
|
+
// 检查是否正在流式输出
|
|
336
|
+
if (this.properties.isGenerating) {
|
|
337
|
+
wx.showToast({
|
|
338
|
+
title: '回答输出中,请稍后操作',
|
|
339
|
+
icon: 'none'
|
|
340
|
+
});
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
335
344
|
// 通知父组件停止语音播放
|
|
336
345
|
this.triggerEvent('voicerecordstart');
|
|
337
346
|
|
|
@@ -840,18 +849,41 @@ Component({
|
|
|
840
849
|
* 发送消息
|
|
841
850
|
*/
|
|
842
851
|
onSend() {
|
|
852
|
+
// 检查是否正在流式输出
|
|
853
|
+
if (this.properties.isGenerating) {
|
|
854
|
+
wx.showToast({
|
|
855
|
+
title: '回答输出中,请稍后操作',
|
|
856
|
+
icon: 'none'
|
|
857
|
+
});
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
|
|
843
861
|
const content = this.data.inputValue.trim();
|
|
844
862
|
const attachments = this.data.attachments.filter(item => !item.uploading);
|
|
863
|
+
const uploadingAttachments = this.data.attachments.filter(item => item.uploading);
|
|
845
864
|
|
|
846
|
-
|
|
865
|
+
// 如果没有内容、没有已上传的附件、也没有正在上传的附件,直接返回
|
|
866
|
+
if (!content && attachments.length === 0 && uploadingAttachments.length === 0) {
|
|
847
867
|
return;
|
|
848
868
|
}
|
|
849
869
|
|
|
850
870
|
// 检查是否有正在上传的附件
|
|
851
|
-
|
|
852
|
-
|
|
871
|
+
if (uploadingAttachments.length > 0) {
|
|
872
|
+
// 区分图片和文件
|
|
873
|
+
const hasUploadingImage = uploadingAttachments.some(item => item.type === 'image');
|
|
874
|
+
const hasUploadingFile = uploadingAttachments.some(item => item.type === 'file');
|
|
875
|
+
|
|
876
|
+
let message = '';
|
|
877
|
+
if (hasUploadingImage && hasUploadingFile) {
|
|
878
|
+
message = '图片和文件上传中,请稍后';
|
|
879
|
+
} else if (hasUploadingImage) {
|
|
880
|
+
message = '图片上传中,请稍后';
|
|
881
|
+
} else {
|
|
882
|
+
message = '文件上传中,请稍后';
|
|
883
|
+
}
|
|
884
|
+
|
|
853
885
|
wx.showToast({
|
|
854
|
-
title:
|
|
886
|
+
title: message,
|
|
855
887
|
icon: 'none'
|
|
856
888
|
});
|
|
857
889
|
return;
|
|
@@ -457,6 +457,21 @@ Component({
|
|
|
457
457
|
* 新建对话(仅重置状态,实际创建在发送第一条消息时进行)
|
|
458
458
|
*/
|
|
459
459
|
onNewChat() {
|
|
460
|
+
// 检查是否正在流式输出
|
|
461
|
+
if (this.data.isStreaming) {
|
|
462
|
+
wx.showToast({
|
|
463
|
+
title: '回答输出中,请稍后操作',
|
|
464
|
+
icon: 'none'
|
|
465
|
+
});
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 停止正在播放的语音
|
|
470
|
+
if (this.data.playingMessageId) {
|
|
471
|
+
audio.stop();
|
|
472
|
+
this.setData({ playingMessageId: null, synthesizingMessageId: null });
|
|
473
|
+
}
|
|
474
|
+
|
|
460
475
|
this.closeDropdown();
|
|
461
476
|
|
|
462
477
|
// 重置到初始状态
|
|
@@ -58,7 +58,8 @@ function initAudioPlayer() {
|
|
|
58
58
|
if (onPlayStateChange) {
|
|
59
59
|
onPlayStateChange({ playing: false, id: currentPlayingId });
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
// 注意:不在这里清除 currentPlayingId
|
|
62
|
+
// stop() 函数会同步清除,这里异步清除可能会覆盖新播放设置的 ID
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
innerAudioContext.onEnded(() => {
|