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 |   87 +++++++++++++++++++++++++------------------
 1 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/pages/aiQuestions/aiQuestions.vue b/pages/aiQuestions/aiQuestions.vue
index 5ecda57..c194750 100644
--- a/pages/aiQuestions/aiQuestions.vue
+++ b/pages/aiQuestions/aiQuestions.vue
@@ -54,18 +54,18 @@
 							<u-loading mode="circle" v-if="!item.aiLog" size="40" color="#0079FE"
 								class="u-m-r-10"></u-loading>
 							<u-collapse-item :open='true' :title="item.aiLog ? 'AI鎬濊�冨畬鎴�' : 'AI鎬濊�冧腑...'">
-								<view v-html="markdown.render(item.thinkLog)"></view>
+								<view style="font-size: 26rpx;"  v-html="markdown.render(item.thinkLog)"></view>
 							</u-collapse-item>
 						</u-collapse>
 						<view v-else-if="!item.aiLog" class="u-flex" style="color: #0079FE;">
 							<u-loading mode="circle" size="40" color="#0079FE" class="u-m-r-10"></u-loading>
 							AI鎬濊�冧腑路路路
 						</view>
-						<view v-html="markdown.render(item.aiLog)"></view>
+						<view style="font-size: 26rpx;"  v-html="markdown.render(item.aiLog)"></view>
 						<view class="file-list" v-if="item.docInfo.length&&item.isEnd">
-							<view class="one-file" v-for="(file,findex) in item.docInfo" :key='findex'>
+							<view class="one-file" @click="uploadFile(file)" v-for="(file,findex) in item.docInfo" :key='findex'>
 								<image :src="getImg(file.docFormat)" mode=""></image>
-								<text>{{file.docName}}</text>
+								<text style="font-size: 26rpx;">{{file.docName}}</text>
 							</view>
 						</view>
 						<view v-if="item.isEnd||item.logSound" class="u-flex u-p-h-10 function-box">
@@ -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,15 +100,15 @@
 		<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">
+			<!--  <view v-if="!voiceFlg" class="know-btn" :class="{'active-btn':showKnow}" @click="showKnow=true">
 				<view class="btn-box">
 					<image v-if="showKnow" src="/static/wd/book-open.png" mode=""></image>
 					<image v-else src="/static/wd/book.png" mode=""></image>
 				</view>
-			</view>
+			</view> -->
 			<view :class="['btm-btn',{'voice-btn':recording},{'voice-cancel-btn': voiceStop}]">
 				<block v-if="!recording">
 					<image v-if="voiceFlg" src="/static/wd/i03.png" mode="widthFix" class="btnimg2" @click="clickType"
@@ -130,8 +130,9 @@
 					<image src="/static/wd/i02.png" v-if="msg&&!isDisabled" class="btnimg" @click="tiWen"
 						mode="widthFix" alt=""></image>
 				</block>
-			</view>
+				</view>
 		</view>
+		<view class="tipsMsg"> 鍐呭鐢� AI 鐢熸垚锛屼粎渚涘弬鑰冿紝鎮ㄦ嵁姝ゆ墍浣滃垽鏂強鎿嶄綔鍧囩敱鎮ㄨ嚜琛屾壙鎷呰矗浠汇��</view>
 		<!--璁剧疆寮圭獥 -->
 		<u-popup v-model="showSet" mode='top' border-radius="20">
 			<view class='set-box'>
@@ -385,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(',')
 			}
@@ -409,6 +409,9 @@
 			document.removeEventListener('contextmenu', this.noContextmenu)
 		},
 		methods: {
+			uploadFile(file) {
+				window.open(this.baseUrl + file.docPath)
+			},
 			chooseThisLLM(e) {
 				this.chooseLlm = e;
 			},
@@ -417,7 +420,6 @@
 				let res = await checkAppScope({
 					appId: e
 				})
-				console.log(res, '楠岃瘉');
 				if (res.data) {
 					this.openRecord();
 					this.getDetails()
@@ -456,7 +458,6 @@
 					pageSize: 10,
 					pageNum: 1
 				})
-				console.log(res);
 				this.talkList = res.rows;
 			},
 			toBack() {
@@ -586,7 +587,6 @@
 				this.voicePageY = 0
 				this.voiceText = '鏉惧紑 鍙戦��'
 				this.startRec()
-				console.log('touchstartVoice', this.voicePageY)
 			},
 			// 鎼滅储鐭ヨ瘑搴�
 			toSearch() {
@@ -594,7 +594,6 @@
 			},
 			// 婊戝姩瑙﹀彂
 			touchmoveVoice(e) {
-				// console.log(e.changedTouches[0])
 				if (!this.voicePageY) {
 					this.voicePageY = (e.changedTouches[0].pageY).toFixed(2)
 				}
@@ -615,7 +614,7 @@
 			// 鏉惧紑瑙﹀彂
 			touchendVoice() {
 				this.stopRec(this.voiceStop); //褰曢煶缁撴潫
-				console.log('鏉惧紑瑙﹀彂')
+				// console.log('鏉惧紑瑙﹀彂')
 			},
 			// 涓鍥炵瓟
 			async isSuspend() {
@@ -646,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)) {
@@ -723,10 +722,8 @@
 					const reader = response.body.getReader();
 					if (this.suspend) {
 						reader.cancel().then(() => {
-							console.log('娴佸紡鍝嶅簲宸插彇娑�');
 							if (controller) {
 								controller.abort();
-								console.log('涓fetch璇锋眰');
 							}
 						})
 						return
@@ -743,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 {
@@ -772,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){
@@ -787,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(() => {
@@ -811,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()
@@ -832,8 +833,9 @@
 				}
 				// 瑙g爜鏁版嵁鏁扮粍鐨勫墠鍗婇儴鍒嗭紝骞舵彁鍙栨枃妗D
 				const idStr = textDecoder.decode(dataArr.slice(0, idx)).trim()
-				const idArr = idStr.substring(idStr.indexOf("锛�") + 1).match(/\d+/g)
-				const docIds = idArr.join(',')
+				// const idArr = idStr.substring(idStr.indexOf("锛�") + 1).match(/\d+/g)
+				const idArr = idStr.substring(idStr.indexOf("锛�") + 1)
+				const docIds = idArr.split(',')
 				// 濡傛灉鏂囨。ID鏈夋晥涓斾笉涓�'0'锛屽垯鏌ヨ鏂囨。
 				if (docIds && docIds !== '0' && !this.suspend) {
 					// 鏍规嵁鏂囨。ID鍒楄〃鑾峰彇鏂囨。淇℃伅
@@ -855,7 +857,7 @@
 							// lastMsgBot.scrollIntoView(false)
 						})
 					})
-					return idArr.join(',')
+					return idArr.split(',')
 				}
 				return docIds
 			},
@@ -1132,6 +1134,7 @@
 	}
 </style>
 <style lang="scss" scoped>
+
 	// 璁剧疆寮圭獥
 	.set-box {
 		padding: 0 34rpx;
@@ -1165,7 +1168,7 @@
 					}
 
 					text {
-						font-size: 32rpx;
+						font-size: 26rpx;
 						color: #000000;
 						font-weight: 400;
 					}
@@ -1182,7 +1185,7 @@
 					}
 
 					text {
-						font-size: 32rpx;
+						font-size: 26rpx;
 						color: #000000;
 						font-weight: 400;
 					}
@@ -1205,7 +1208,7 @@
 			display: flex;
 			align-items: center;
 			justify-content: space-between;
-			font-size: 34rpx;
+			font-size: 30rpx;
 			color: #000000;
 			font-weight: 700;
 			line-height: 50rpx;
@@ -1247,7 +1250,7 @@
 
 					.details {
 						.know-name {
-							font-size: 32rpx;
+							font-size: 28rpx;
 							color: #000000;
 							line-height: 50rpx;
 							font-weight: 500;
@@ -1262,6 +1265,7 @@
 							display: inline-block;
 							line-height: 42rpx;
 							border-radius: 8rpx;
+							font-size: 28rpx;
 						}
 					}
 				}
@@ -1363,10 +1367,17 @@
 			}
 		}
 	}
-
+	.tipsMsg{
+		position: fixed;
+		bottom: 0rpx;
+		text-align: center;
+		color: #c0c4cc;
+		height: 80rpx;
+		font-size: 26rpx;
+	}
 	.btmbox {
 		position: fixed;
-		bottom: 0;
+		bottom: 80rpx;
 		height: 120rpx;
 		background-color: #F3F5F9;
 		display: flex;
@@ -1447,7 +1458,7 @@
 		border-radius: 10rpx;
 		background: #0AAFB0;
 		padding: 10rpx 18rpx;
-		font-size: 30rpx;
+		font-size: 28rpx;
 		color: white;
 		text-align: center;
 	}
@@ -1457,7 +1468,7 @@
 		flex-direction: row;
 		justify-content: flex-end;
 		width: 100%;
-
+		font-size: 26rpx;
 		.div {
 			background: linear-gradient(273deg, #2F7AFA 0.22%, #226FF4 99.8%);
 			color: #fff;
@@ -1466,6 +1477,7 @@
 			max-width: 100%;
 			padding: 12px 16px;
 			white-space: pre-wrap;
+			font-size: 26rpx;
 		}
 	}
 
@@ -1506,6 +1518,7 @@
 		background: #fff;
 		border-radius: 24rpx;
 		margin: 40rpx;
+		font-size: 26rpx;
 	}
 	.msgbox1 {
 		margin-bottom: 20rpx;
@@ -1564,7 +1577,7 @@
 				}
 
 				text {
-					font-size: 30rpx;
+					font-size: 26rpx;
 					color: #101828;
 					line-height: 50rpx;
 					font-weight: 400;
@@ -1720,7 +1733,7 @@
 			position: relative;
 			z-index: 2;
 			padding-top: 70rpx;
-			font-size: 32rpx;
+			font-size: 28rpx;
 			text-indent: 4em;
 		}
 
@@ -1747,7 +1760,7 @@
 
 				.top {
 					color: #000000;
-					font-size: 32rpx;
+					font-size: 28rpx;
 					font-weight: bold;
 
 					span {

--
Gitblit v1.9.1