Skip to content

Commit 7c3e77a

Browse files
committed
fix: 修复系统提示语在切会话时插入位置bug
1 parent c17997c commit 7c3e77a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Component({
164164
this.setData({
165165
bot,
166166
questions,
167-
chatRecords: [...chatRecords, record],
167+
chatRecords: chatRecords.length > 0 ? chatRecords : [record],
168168
showWebSearchSwitch: allowWebSearch,
169169
showUploadFile: allowUploadFile,
170170
showUploadImg: allowUploadImage,
@@ -266,9 +266,9 @@ Component({
266266
try {
267267
if (this.data.bot.botId) {
268268
const res = await this.fetchConversationList(true, this.data.bot.botId);
269-
if(res) {
270-
const { data } = res
271-
console.log('data default', data.code)
269+
if (res) {
270+
const { data } = res;
271+
console.log("data default", data.code);
272272
if (data && !data.code) {
273273
console.log("data", data);
274274
this.setData({
@@ -370,6 +370,9 @@ Component({
370370
// title: data.title,
371371
// },
372372
// });
373+
this.setData({
374+
refreshText: "下拉加载历史记录",
375+
});
373376
},
374377
scrollConToBottom: async function (e) {
375378
console.log("scrollConToBottom", e);
@@ -387,8 +390,8 @@ Component({
387390
// 调用分页接口查询更多
388391
if (this.data.bot.botId) {
389392
const res = await this.fetchConversationList(false, this.data.bot.botId);
390-
if(res) {
391-
const { data } = res
393+
if (res) {
394+
const { data } = res;
392395
if (data && !data.code) {
393396
const addConversations = [...this.data.conversations, ...data.data];
394397
// TODO: 临时倒序处理
@@ -788,8 +791,12 @@ Component({
788791
return transformItem;
789792
})
790793
.filter((item) => item);
794+
// 只有一条则一定是系统开头语,需要置前,否则则为真实对话,靠后
791795
this.setData({
792-
chatRecords: [...freshChatRecords, ...this.data.chatRecords],
796+
chatRecords:
797+
this.data.chatRecords.length === 1
798+
? [...this.data.chatRecords, ...freshChatRecords]
799+
: [...freshChatRecords, ...this.data.chatRecords],
793800
});
794801
// console.log("totalChatRecords", this.data.chatRecords);
795802
}
@@ -801,6 +808,9 @@ Component({
801808
}
802809
);
803810
},
811+
handleTapClear: function (e) {
812+
this.clearChatRecords();
813+
},
804814
clearChatRecords: function () {
805815
console.log("执行清理");
806816
const chatMode = this.data.chatMode;

apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.wxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
</view>
227227
<!-- 底部工具栏 -->
228228
<view class="tool_box" wx:if="{{showTools}}">
229-
<view class="function" bind:tap="clearChatRecords">
229+
<view class="function" bind:tap="handleTapClear">
230230
<image src="./imgs/clear.svg" alt="widthFix" class="icon" />
231231
<text class="text_desc">清除</text>
232232
</view>

0 commit comments

Comments
 (0)