From e05ab401650433cc7e767e08b482fb7a00be7bbd Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期三, 18 六月 2025 19:16:19 +0800
Subject: [PATCH] refactor(aiQuestions): 修复智能体流式回复解析问题

---
 pages/aiQuestions/aiQuestions.vue |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/pages/aiQuestions/aiQuestions.vue b/pages/aiQuestions/aiQuestions.vue
index 3b04f89..c194750 100644
--- a/pages/aiQuestions/aiQuestions.vue
+++ b/pages/aiQuestions/aiQuestions.vue
@@ -74,7 +74,7 @@
 									<image src="/static/question/copy.png" mode=""></image>
 								</view>
 							</view>
-							<!-- 
+							<!--
 								<view class="function-right">
 								<u-icon name="thumb-up-fill" @click='clickLikes(item)' v-if="item.isLike"
 									color="#2468F2" size="40"></u-icon>
@@ -84,7 +84,7 @@
 									color="#2468F2" size="40"></u-icon>
 								<u-icon name="thumb-down" @click="clickDislikes(item)" v-else color="#98a1b2"
 									size="40"></u-icon>
-							</view>	
+							</view>
 							-->
 						</view>
 					</view>
@@ -100,7 +100,7 @@
 		<view v-else class="tips">
 			鎴戞槸璐㈡斂AI鍔╂墜锛屽緢楂樺叴瑙佸埌浣狅紒鎴戝彲浠ュ洖绛旈」鐩枃妗d腑鐨勫悇绉嶉棶棰橈紝杈撳叆闂蹇潵浣撻獙鍚э紒
 		</view>
-			
+
 		<audio id="audio" src=""></audio>
 		<view class="btmbox" :class="{'isOn':showKnow}">
 			<!--  <view v-if="!voiceFlg" class="know-btn" :class="{'active-btn':showKnow}" @click="showKnow=true">
@@ -386,7 +386,6 @@
 			this.appId = options.id || 1
 			this.userId = options.userId || 1
 			// this.toCheck(this.appId)
-			console.log(options)
 			if(options.knowId) {
 				this.knowIds = options.knowId.split(',')
 			}
@@ -421,7 +420,6 @@
 				let res = await checkAppScope({
 					appId: e
 				})
-				console.log(res, '楠岃瘉');
 				if (res.data) {
 					this.openRecord();
 					this.getDetails()
@@ -460,7 +458,6 @@
 					pageSize: 10,
 					pageNum: 1
 				})
-				console.log(res);
 				this.talkList = res.rows;
 			},
 			toBack() {
@@ -590,7 +587,6 @@
 				this.voicePageY = 0
 				this.voiceText = '鏉惧紑 鍙戦��'
 				this.startRec()
-				console.log('touchstartVoice', this.voicePageY)
 			},
 			// 鎼滅储鐭ヨ瘑搴�
 			toSearch() {
@@ -598,7 +594,6 @@
 			},
 			// 婊戝姩瑙﹀彂
 			touchmoveVoice(e) {
-				// console.log(e.changedTouches[0])
 				if (!this.voicePageY) {
 					this.voicePageY = (e.changedTouches[0].pageY).toFixed(2)
 				}
@@ -619,7 +614,7 @@
 			// 鏉惧紑瑙﹀彂
 			touchendVoice() {
 				this.stopRec(this.voiceStop); //褰曢煶缁撴潫
-				console.log('鏉惧紑瑙﹀彂')
+				// console.log('鏉惧紑瑙﹀彂')
 			},
 			// 涓鍥炵瓟
 			async isSuspend() {
@@ -650,7 +645,7 @@
 			// 鎵撴柇瑙﹀彂
 			touchcancelVoice() {
 				this.stopRec(this.voiceStop); //褰曢煶缁撴潫
-				console.log('鎵撴柇瑙﹀彂')
+				// console.log('鎵撴柇瑙﹀彂')
 			},
 			async tiWen() {
 				if (this.$u.test.isEmpty(this.msg) && this.$u.test.isEmpty(this.recMsg)) {
@@ -727,10 +722,8 @@
 					const reader = response.body.getReader();
 					if (this.suspend) {
 						reader.cancel().then(() => {
-							console.log('娴佸紡鍝嶅簲宸插彇娑�');
 							if (controller) {
 								controller.abort();
-								console.log('涓fetch璇锋眰');
 							}
 						})
 						return
@@ -747,7 +740,9 @@
 					let docIds = null
 					let isGetId = false
 					let isThink = false
+          let count = 0
 					while (result) {
+            count++
 						if (this.suspend) break
 						// done琛ㄧず娴佹槸鍚﹀凡缁忓畬鎴愯鍙�  value鍖呭惈璇诲彇鍒扮殑鏁版嵁鍧�
 						const {
@@ -776,7 +771,7 @@
 								let asIdx = this.getContainedIdx(value, ansCode)
 								if (asIdx !== -1) {
 									isThink = false
-									curMsg.thinkLog += textDecoder.decode(value.slice(0, asIdx))
+									curMsg.thinkLog += textDecoder.decode(value.slice(thkCode.length, asIdx))
 									dataArr = new Uint8Array([...value.slice(asIdx)])
 								} else {
                   if(thkIdx===0){
@@ -791,9 +786,12 @@
 								// 妫�鏌ユ暟鎹暟缁勪腑鏄惁鍖呭惈鍊间负10鐨勫厓绱狅紝浠ョ‘瀹氭槸鍚﹂渶瑕佽幏鍙栨枃妗D
 								isGetId = dataArr.includes(10)
 							}
-							// dataArr = new Uint8Array([...dataArr, ...value])
-							// isGetId = dataArr.includes(10)
 						}
+            if (count === 1) {
+              const idx = dataArr.indexOf(10)
+              // 灏嗘暟鎹暟缁勪粠绱㈠紩浣嶇疆+1寮�濮嬬殑閮ㄥ垎涓庡綋鍓嶅�煎悎骞讹紝骞惰В鐮佷负瀛楃涓�
+              curMsg.aiLog = textDecoder.decode(dataArr.slice(idx + 1))
+            }
 						curMsg.debug = 0
 						this.intoView = "";
 						this.$nextTick(() => {
@@ -815,7 +813,6 @@
 					this.msgList[this.msgList.length - 1].isPlay = 0
 					this.resetRec()
 				} catch (err) {
-					console.log(err);
 					if (this.msgList[this.msgList.length - 1].aiLog === '' || !this.msgList[this.msgList.length - 1]
 						.isEnd) {
 						this.msgList.pop()

--
Gitblit v1.9.1