Skip to content

Commit 5fb0e3e

Browse files
committed
fix: 支持用户内容粘贴及修改
1 parent 761be1b commit 5fb0e3e

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed
Lines changed: 2 additions & 0 deletions
Loading

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Component({
5454
},
5555

5656
data: {
57+
showMenu: false,
58+
tapMenuRecordId: "",
5759
isLoading: true, // 判断是否尚在加载中
5860
article: {},
5961
windowInfo: wx.getWindowInfo(),
@@ -158,6 +160,45 @@ Component({
158160
});
159161
},
160162
methods: {
163+
handleCopyAll(e) {
164+
const { content } = e.currentTarget.dataset;
165+
wx.setClipboardData({
166+
data: content,
167+
success: () => {
168+
wx.showToast({
169+
title: "复制成功",
170+
icon: "success",
171+
});
172+
this.hideMenu();
173+
},
174+
});
175+
},
176+
handleEdit(e) {
177+
const { content } = e.currentTarget.dataset;
178+
this.setData({
179+
inputValue: content,
180+
});
181+
this.hideMenu();
182+
},
183+
handleLongPress(e) {
184+
const { id } = e.currentTarget.dataset;
185+
this.setData({
186+
showMenu: true,
187+
tapMenuRecordId: id,
188+
});
189+
},
190+
hideMenu() {
191+
this.setData({
192+
showMenu: false,
193+
tapMenuRecordId: "",
194+
});
195+
},
196+
// 点击页面其他地方隐藏菜单
197+
onTapPage() {
198+
if (this.data.showMenu) {
199+
this.hideMenu();
200+
}
201+
},
161202
transformToolName: function (str) {
162203
if (str) {
163204
const strArr = str.split("/");

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- agent ui 组件根容器 -->
2-
<view class="agent-ui">
2+
<view class="agent-ui" bind:tap="onTapPage">
33
<view class="navBar" wx:if="{{chatMode === 'bot'}}">
44
<view class="nav-content">
55
<!-- <image src="{{bot.avatar}}" mode="aspectFill" class="bot-avatar"/> -->
@@ -113,9 +113,20 @@
113113
</view>
114114
<!-- 用户输入 -->
115115
<view class="userContent" wx:if="{{item.role==='user'}}">
116-
<view class="user" style="padding-left: {{showBotAvatar?80:0}}rpx;">
117-
<view class="user_content">
116+
<view class="user" style="padding-left: {{showBotAvatar?80:0}}rpx;display: flex;">
117+
<view class="user_content" bind:longpress="handleLongPress" data-content="{{item.content}}" data-id="{{item.record_id}}">
118118
{{item.content}}
119+
<!-- 长按菜单 -->
120+
<view class="operation-menu" wx:if="{{showMenu && tapMenuRecordId === item.record_id}}">
121+
<view class="menu-item" bind:tap="handleCopyAll" data-content="{{item.content}}">
122+
<image src="./imgs/copy.svg" class="menu-icon" />
123+
<text>复制全文</text>
124+
</view>
125+
<view class="menu-item" bind:tap="handleEdit" data-content="{{item.content}}">
126+
<image src="./imgs/edit.svg" class="menu-icon" />
127+
<text>修改</text>
128+
</view>
129+
</view>
119130
</view>
120131
</view>
121132
<view class="fileBar">

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,50 @@
370370
word-wrap: break-word;
371371
word-break: break-all;
372372
font-size: 32rpx;
373+
position: relative;
374+
}
375+
376+
.operation-menu {
377+
position: absolute;
378+
bottom: -120rpx;
379+
left: 0;
380+
background: rgba(0, 0, 0, 1);
381+
border-radius: 8rpx;
382+
display: flex;
383+
padding: 16rpx 24rpx;
384+
gap: 32rpx;
385+
z-index: 100;
386+
}
387+
388+
/* 添加三角形指示器 */
389+
.operation-menu::before {
390+
content: '';
391+
position: absolute;
392+
top: -16rpx; /* 调整三角形位置 */
393+
left: 30rpx; /* 调整三角形的水平位置,使其指向文本 */
394+
border-left: 16rpx solid transparent;
395+
border-right: 16rpx solid transparent;
396+
border-bottom: 16rpx solid rgba(0, 0, 0, 0.8);
397+
width: 0;
398+
height: 0;
399+
}
400+
401+
.menu-item {
402+
display: flex;
403+
flex-direction: column;
404+
align-items: center;
405+
gap: 8rpx;
406+
}
407+
408+
.menu-item text {
409+
color: #ffffff;
410+
font-size: 24rpx;
411+
}
412+
413+
.menu-icon {
414+
width: 36rpx;
415+
height: 36rpx;
416+
filter: brightness(0) invert(1);
373417
}
374418

375419
.feedback_modal {

0 commit comments

Comments
 (0)