Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 101 additions & 2 deletions apps/miniprogram-agent-ui/miniprogram/components/agent-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ Component({
},
voiceRecognizing: false,
speedList: [2, 1.5, 1.25, 1, 0.75],

showActionMenu: false, // 是否显示操作菜单
selectedConversation: null, // 当前选中的会话
},
attached: async function () {
const chatMode = this.data.chatMode;
Expand Down Expand Up @@ -482,7 +485,7 @@ Component({
});

commonRequest({
path: `conversation/?botId=${botId}&limit=${limit}&offset=${offset}&isDefault=${isDefault}`,
path: `bots/${botId}/conversation/?limit=${limit}&offset=${offset}&isDefault=${isDefault}`,
method: "GET",
header: {},
success: (res) => {
Expand All @@ -506,7 +509,7 @@ Component({
// const { token } = await cloudInstance.extend.AI.bot.tokenManager.getToken();
return new Promise((resolve, reject) => {
commonRequest({
path: `conversation`,
path: `bots/${this.data.agentConfig.botId}/conversation`,
header: {
// Authorization: `Bearer ${token}`,
},
Expand All @@ -524,6 +527,102 @@ Component({
});
});
},
deleteConversation: async function (conversationId) {
return new Promise((resolve, reject) => {
commonRequest({
path: `bots/${this.data.agentConfig.botId}/conversation/${conversationId}`,
method: "DELETE",
success: (res) => {
resolve(res);
},
fail(e) {
console.log("delete conversation e", e);
reject(e);
},
});
});
},
handleDeleteConversation: async function (e) {
const { conversation } = e.currentTarget.dataset;
const that = this;

this.hideActionMenu();

wx.showModal({
title: "提示",
content: "确认删除当前会话?",
confirmText: "删除",
confirmColor: "#ff303b",
success: async function(res){
if (res.confirm) {
// 删除会话
try{
const deleteRes = await that.deleteConversation(conversation.conversationId);

if (deleteRes && !deleteRes.code) {
// 删除成功后更新本地数据
const updatedConversations = that.data.conversations.filter(
item => item.conversationId !== conversation.conversationId
);
that.setData({
conversations: updatedConversations,
transformConversations: that.transformConversationList(updatedConversations),
});

if (that.data.conversation?.conversationId === conversation.conversationId) {
that.clearChatRecords();
if (updatedConversations.length > 0) {
that.handleClickConversation({
currentTarget: {
dataset: {
conversation: updatedConversations[0],
},
},
});
} else {
that.setData({
conversation: null,
});
}
}

wx.showToast({
title: "删除成功",
icon: "success",
});
await that.resetFetchConversationList();
} else {
wx.showToast({
title: "删除失败,请稍后重试",
icon: "error",
});
}
} catch (error) {
console.error("删除会话失败", error);
wx.showToast({
title: "删除失败,请稍后重试",
icon: "error",
});
}
}
},
});
},
handleLongPressConversation: function (e) {
// 长按会话,显示操作菜单
const { conversation } = e.currentTarget.dataset;
this.setData({
showActionMenu: true,
selectedConversation: conversation,
});
},
hideActionMenu: function () {
// 隐藏操作菜单
this.setData({
showActionMenu: false,
selectedConversation: null,
});
},
clickCreateInDrawer: function () {
this.setData({
isDrawerShow: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,40 @@
<view class="con-block" wx:if="{{transformConversations.todayCon.length}}">
<text class="date-title">今天</text>
<view class="con-container">
<view class="con-item" bind:tap="handleClickConversation" data-conversation="{{item}}" wx:for="{{transformConversations.todayCon}}" wx:key="index">{{item.title}}</view>
<view class="con-item {{item.conversationId === conversation.conversationId ? 'selected-con' : ''}}"
bind:tap="handleClickConversation"
bind:longpress="handleLongPressConversation"
data-conversation="{{item}}"
wx:for="{{transformConversations.todayCon}}"
wx:key="index">
{{item.title}}
</view>
</view>
</view>
<view class="con-block" wx:if="{{transformConversations.curMonthCon.length}}">
<text class="date-title">本月</text>
<view class="con-container">
<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>
<view class="con-item {{item.conversationId === conversation.conversationId ? 'selected-con' : ''}}"
bind:tap="handleClickConversation"
bind:longpress="handleLongPressConversation"
data-conversation="{{item}}"
wx:for="{{transformConversations.curMonthCon}}"
wx:key="index">
{{item.title}}
</view>
</view>
</view>
<view class="con-block" wx:if="{{transformConversations.earlyCon.length}}">
<text class="date-title">更早</text>
<view class="con-container">
<view class="con-item" bind:tap="handleClickConversation" data-conversation="{{item}}" wx:for="{{transformConversations.earlyCon}}" wx:key="index">{{item.title}}</view>
<view class="con-item"
bind:tap="handleClickConversation"
bind:longpress="handleLongPressConversation"
data-conversation="{{item}}"
wx:for="{{transformConversations.earlyCon}}"
wx:key="index">
{{item.title}}
</view>
</view>
</view>
</block>
Expand Down Expand Up @@ -277,4 +298,15 @@
</view>
</view>
<feedback input="{{input}}" aiAnswer="{{aiAnswer}}" isShowFeedback="{{isShowFeedback}}" bind:close="closefeedback" feedbackRecordId="{{feedbackRecordId}}" feedbackType="{{feedbackType}}" botId="{{bot.botId}}"></feedback>
<!-- 底部操作菜单弹窗 -->
<view class="action-menu-modal" wx:if="{{showActionMenu}}" bind:tap="hideActionMenu">
<view class="action-menu" catchtap="">
<view class="action-item" bind:tap="handleDeleteConversation" data-conversation="{{selectedConversation}}">
删除
</view>
<view class="action-item cancel-item" bind:tap="hideActionMenu">
取消
</view>
</view>
</view>
</view>
Original file line number Diff line number Diff line change
Expand Up @@ -742,4 +742,72 @@

.speed-option:active {
background: #f0f0f0;
}
}

/* 底部操作菜单弹窗 */
.action-menu-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 1001;
display: flex;
flex-direction: column;
justify-content: flex-end;
animation: fadeIn 0.3s ease-out;
}

.action-menu {
background: #ffffff;
border-radius: 24rpx 24rpx 0 0;
overflow: hidden;
animation: slideUp 0.3s ease-out;
margin: 0 20rpx 20rpx 20rpx;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}

.action-item {
padding: 32rpx 0;
text-align: center;
font-size: 32rpx;
color: #333333;
background: #ffffff;
border-bottom: 1rpx solid #f0f0f0;
position: relative;
}

.action-item:last-child {
border-bottom: none;
}

.action-item:active {
background: #f8f8f8;
}

.cancel-item {
margin-top: 20rpx;
border-radius: 24rpx;
border-bottom: none;
color: #666666;
}

/* 动画效果 */
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}

@keyframes slideUp {
from {
transform: translateY(100%);
}
to {
transform: translateY(0);
}
}
2 changes: 1 addition & 1 deletion apps/miniprogram-agent-ui/project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"include": []
},
"appid": "wx5ceb4e4809aa1d28",
"libVersion": "3.7.10",
"libVersion": "3.8.1",
"simulatorPluginLibVersion": {}
}
5 changes: 3 additions & 2 deletions apps/miniprogram-agent-ui/project.private.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
},
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "cloudbase-agent-ui",
"libVersion": "3.8.1"
}
"libVersion": "3.9.0",
"condition": {}
}
Loading