Skip to content

Commit b375ce6

Browse files
authored
Merge pull request #79 from TencentCloudBase/dev
Dev
2 parents dee3b1d + c00ac3e commit b375ce6

File tree

10 files changed

+415
-18
lines changed

10 files changed

+415
-18
lines changed

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

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ Component({
128128
},
129129
voiceRecognizing: false,
130130
speedList: [2, 1.5, 1.25, 1, 0.75],
131+
132+
showActionMenu: false, // 是否显示操作菜单
133+
selectedConversation: null, // 当前选中的会话
131134
},
132135
attached: async function () {
133136
const chatMode = this.data.chatMode;
@@ -482,7 +485,7 @@ Component({
482485
});
483486

484487
commonRequest({
485-
path: `conversation/?botId=${botId}&limit=${limit}&offset=${offset}&isDefault=${isDefault}`,
488+
path: `bots/${botId}/conversation/?limit=${limit}&offset=${offset}&isDefault=${isDefault}`,
486489
method: "GET",
487490
header: {},
488491
success: (res) => {
@@ -506,7 +509,7 @@ Component({
506509
// const { token } = await cloudInstance.extend.AI.bot.tokenManager.getToken();
507510
return new Promise((resolve, reject) => {
508511
commonRequest({
509-
path: `conversation`,
512+
path: `bots/${this.data.agentConfig.botId}/conversation`,
510513
header: {
511514
// Authorization: `Bearer ${token}`,
512515
},
@@ -524,6 +527,101 @@ Component({
524527
});
525528
});
526529
},
530+
deleteConversation: async function (conversationId) {
531+
return new Promise((resolve, reject) => {
532+
commonRequest({
533+
path: `bots/${this.data.agentConfig.botId}/conversation/${conversationId}`,
534+
method: "DELETE",
535+
success: (res) => {
536+
resolve(res);
537+
},
538+
fail(e) {
539+
console.log("delete conversation e", e);
540+
reject(e);
541+
},
542+
});
543+
});
544+
},
545+
handleDeleteConversation: async function (e) {
546+
const { conversation } = e.currentTarget.dataset;
547+
const that = this;
548+
549+
this.hideActionMenu();
550+
551+
wx.showModal({
552+
title: "提示",
553+
content: "确认删除当前会话?",
554+
confirmText: "删除",
555+
confirmColor: "#ff303b",
556+
success: async function(res){
557+
if (res.confirm) {
558+
// 删除会话
559+
try{
560+
const deleteRes = await that.deleteConversation(conversation.conversationId);
561+
562+
if (deleteRes && !deleteRes.code) {
563+
// 删除成功后更新本地数据
564+
const updatedConversations = that.data.conversations.filter(
565+
item => item.conversationId !== conversation.conversationId
566+
);
567+
that.setData({
568+
conversations: updatedConversations,
569+
transformConversations: that.transformConversationList(updatedConversations),
570+
});
571+
572+
if (that.data.conversation?.conversationId === conversation.conversationId) {
573+
that.clearChatRecords();
574+
if (updatedConversations.length > 0) {
575+
that.handleClickConversation({
576+
currentTarget: {
577+
dataset: {
578+
conversation: updatedConversations[0],
579+
},
580+
},
581+
});
582+
} else {
583+
that.setData({
584+
conversation: null,
585+
});
586+
}
587+
}
588+
589+
wx.showToast({
590+
title: "删除成功",
591+
icon: "success",
592+
});
593+
} else {
594+
wx.showToast({
595+
title: "删除失败,请稍后重试",
596+
icon: "error",
597+
});
598+
}
599+
} catch (error) {
600+
console.error("删除会话失败", error);
601+
wx.showToast({
602+
title: "删除失败,请稍后重试",
603+
icon: "error",
604+
});
605+
}
606+
}
607+
},
608+
});
609+
},
610+
handleLongPressConversation: function (e) {
611+
// 长按会话,显示操作菜单
612+
const { conversation } = e.currentTarget.dataset;
613+
this.setData({
614+
showActionMenu: true,
615+
selectedConversation: conversation,
616+
});
617+
},
618+
hideActionMenu: function () {
619+
// 隐藏操作菜单
620+
this.setData({
621+
showActionMenu: false,
622+
selectedConversation: null,
623+
});
624+
},
527625
clickCreateInDrawer: function () {
528626
this.setData({
529627
isDrawerShow: false,

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,40 @@
2020
<view class="con-block" wx:if="{{transformConversations.todayCon.length}}">
2121
<text class="date-title">今天</text>
2222
<view class="con-container">
23-
<view class="con-item" bind:tap="handleClickConversation" data-conversation="{{item}}" wx:for="{{transformConversations.todayCon}}" wx:key="index">{{item.title}}</view>
23+
<view class="con-item {{item.conversationId === conversation.conversationId ? 'selected-con' : ''}}"
24+
bind:tap="handleClickConversation"
25+
bind:longpress="handleLongPressConversation"
26+
data-conversation="{{item}}"
27+
wx:for="{{transformConversations.todayCon}}"
28+
wx:key="index">
29+
{{item.title}}
30+
</view>
2431
</view>
2532
</view>
2633
<view class="con-block" wx:if="{{transformConversations.curMonthCon.length}}">
2734
<text class="date-title">本月</text>
2835
<view class="con-container">
29-
<view class="con-item {{item.conversationId === conversation.conversationId ? 'selected-con' : ''}}" bind:tap="handleClickConversation" data-conversation="{{item}}" wx:for="{{transformConversations.curMonthCon}}" wx:key="index">{{item.title}}</view>
36+
<view class="con-item {{item.conversationId === conversation.conversationId ? 'selected-con' : ''}}"
37+
bind:tap="handleClickConversation"
38+
bind:longpress="handleLongPressConversation"
39+
data-conversation="{{item}}"
40+
wx:for="{{transformConversations.curMonthCon}}"
41+
wx:key="index">
42+
{{item.title}}
43+
</view>
3044
</view>
3145
</view>
3246
<view class="con-block" wx:if="{{transformConversations.earlyCon.length}}">
3347
<text class="date-title">更早</text>
3448
<view class="con-container">
35-
<view class="con-item" bind:tap="handleClickConversation" data-conversation="{{item}}" wx:for="{{transformConversations.earlyCon}}" wx:key="index">{{item.title}}</view>
49+
<view class="con-item"
50+
bind:tap="handleClickConversation"
51+
bind:longpress="handleLongPressConversation"
52+
data-conversation="{{item}}"
53+
wx:for="{{transformConversations.earlyCon}}"
54+
wx:key="index">
55+
{{item.title}}
56+
</view>
3657
</view>
3758
</view>
3859
</block>
@@ -277,4 +298,15 @@
277298
</view>
278299
</view>
279300
<feedback input="{{input}}" aiAnswer="{{aiAnswer}}" isShowFeedback="{{isShowFeedback}}" bind:close="closefeedback" feedbackRecordId="{{feedbackRecordId}}" feedbackType="{{feedbackType}}" botId="{{bot.botId}}"></feedback>
301+
<!-- 底部操作菜单弹窗 -->
302+
<view class="action-menu-modal" wx:if="{{showActionMenu}}" bind:tap="hideActionMenu">
303+
<view class="action-menu" catchtap="">
304+
<view class="action-item" bind:tap="handleDeleteConversation" data-conversation="{{selectedConversation}}">
305+
删除
306+
</view>
307+
<view class="action-item cancel-item" bind:tap="hideActionMenu">
308+
取消
309+
</view>
310+
</view>
311+
</view>
280312
</view>

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,4 +742,72 @@
742742

743743
.speed-option:active {
744744
background: #f0f0f0;
745-
}
745+
}
746+
747+
/* 底部操作菜单弹窗 */
748+
.action-menu-modal {
749+
position: fixed;
750+
top: 0;
751+
left: 0;
752+
right: 0;
753+
bottom: 0;
754+
background: rgba(0, 0, 0, 0.4);
755+
z-index: 1001;
756+
display: flex;
757+
flex-direction: column;
758+
justify-content: flex-end;
759+
animation: fadeIn 0.3s ease-out;
760+
}
761+
762+
.action-menu {
763+
background: #ffffff;
764+
border-radius: 24rpx 24rpx 0 0;
765+
overflow: hidden;
766+
animation: slideUp 0.3s ease-out;
767+
margin: 0 20rpx 20rpx 20rpx;
768+
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
769+
}
770+
771+
.action-item {
772+
padding: 32rpx 0;
773+
text-align: center;
774+
font-size: 32rpx;
775+
color: #333333;
776+
background: #ffffff;
777+
border-bottom: 1rpx solid #f0f0f0;
778+
position: relative;
779+
}
780+
781+
.action-item:last-child {
782+
border-bottom: none;
783+
}
784+
785+
.action-item:active {
786+
background: #f8f8f8;
787+
}
788+
789+
.cancel-item {
790+
margin-top: 20rpx;
791+
border-radius: 24rpx;
792+
border-bottom: none;
793+
color: #666666;
794+
}
795+
796+
/* 动画效果 */
797+
@keyframes fadeIn {
798+
from {
799+
opacity: 0;
800+
}
801+
to {
802+
opacity: 1;
803+
}
804+
}
805+
806+
@keyframes slideUp {
807+
from {
808+
transform: translateY(100%);
809+
}
810+
to {
811+
transform: translateY(0);
812+
}
813+
}

apps/miniprogram-agent-ui/project.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@
7272
"include": []
7373
},
7474
"appid": "wx5ceb4e4809aa1d28",
75-
"libVersion": "3.7.10",
75+
"libVersion": "3.8.1",
7676
"simulatorPluginLibVersion": {}
7777
}

apps/miniprogram-agent-ui/project.private.config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
},
2121
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
2222
"projectname": "cloudbase-agent-ui",
23-
"libVersion": "3.8.1"
24-
}
23+
"libVersion": "3.9.0",
24+
"condition": {}
25+
}

0 commit comments

Comments
 (0)