@flexem/chat-box 1.0.6 → 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
- if (!content && attachments.length === 0) {
865
+ // 如果没有内容、没有已上传的附件、也没有正在上传的附件,直接返回
866
+ if (!content && attachments.length === 0 && uploadingAttachments.length === 0) {
847
867
  return;
848
868
  }
849
869
 
850
870
  // 检查是否有正在上传的附件
851
- const uploadingCount = this.data.attachments.filter(item => item.uploading).length;
852
- if (uploadingCount > 0) {
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
  // 重置到初始状态
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@flexem/chat-box",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "index.js"
5
5
  }
@@ -58,7 +58,8 @@ function initAudioPlayer() {
58
58
  if (onPlayStateChange) {
59
59
  onPlayStateChange({ playing: false, id: currentPlayingId });
60
60
  }
61
- currentPlayingId = null;
61
+ // 注意:不在这里清除 currentPlayingId
62
+ // stop() 函数会同步清除,这里异步清除可能会覆盖新播放设置的 ID
62
63
  });
63
64
 
64
65
  innerAudioContext.onEnded(() => {
@@ -179,13 +180,15 @@ function isPlaying() {
179
180
  * 销毁播放器
180
181
  */
181
182
  function destroy() {
183
+ // 先停止所有播放
184
+ stop();
185
+
182
186
  if (innerAudioContext) {
183
187
  innerAudioContext.destroy();
184
188
  innerAudioContext = null;
185
189
  }
186
190
  currentPlayingId = null;
187
191
  onPlayStateChange = null;
188
- stopStreamingPlay();
189
192
  }
190
193
 
191
194
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexem/chat-box",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "chat box",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "miniprogram": "miniprogram_dist",