feat(历史记录): 添加滑动删除功能并优化批量删除交互

This commit is contained in:
yangzhe 2025-12-17 10:51:45 +08:00
parent 142541a80d
commit ef41da80ff
1 changed files with 163 additions and 34 deletions

View File

@ -51,10 +51,34 @@
> >
<view class="date-header">{{ group.id }}</view> <view class="date-header">{{ group.id }}</view>
<view v-for="item in group.conversation" :key="item.id">
<uni-swipe-action ref="swipeActionRef">
<uni-swipe-action-item
:disabled="isBatchDeleteMode"
:threshold="0.3"
:auto-close="true"
@change="handleSwipeChange($event, item.id)"
>
<template v-slot:right>
<view
class="right-btn-box"
@touchend.stop="handleSingleDelete(item)"
>
<!-- <u-icon name="trash" color="#fff" size="34"></u-icon> -->
<image
src="/static/common/images/icon_delete.png"
mode="widthFix"
style="width: 32rpx; height: 32rpx"
/>
<text>删除</text>
</view>
</template>
<view <view
class="history-item" class="history-item"
v-for="item in group.conversation" :class="{
:key="item.id" 'no-right-radius': openedItems[item.id] === 'right',
}"
> >
<!-- 批量删除模式下的选择框 --> <!-- 批量删除模式下的选择框 -->
<view <view
@ -66,7 +90,9 @@
class="checkbox" class="checkbox"
:class="{ checked: selectedItems.includes(item.id) }" :class="{ checked: selectedItems.includes(item.id) }"
> >
<text class="checkmark" v-if="selectedItems.includes(item.id)" <text
class="checkmark"
v-if="selectedItems.includes(item.id)"
></text ></text
> >
</view> </view>
@ -86,6 +112,9 @@
<!-- <view class="item-description">{{ item.content }}</view> --> <!-- <view class="item-description">{{ item.content }}</view> -->
</view> </view>
</view> </view>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
</view> </view>
</view> </view>
</view> </view>
@ -111,10 +140,12 @@
<script> <script>
import HeaderBar from "@/components/HeaderBar.vue"; import HeaderBar from "@/components/HeaderBar.vue";
import UniSwipeAction from "@/uni_modules/uni-swipe-action/components/uni-swipe-action/uni-swipe-action.vue";
export default { export default {
components: { components: {
HeaderBar, HeaderBar,
UniSwipeAction,
}, },
data() { data() {
return { return {
@ -129,6 +160,7 @@ export default {
selectAll: false, // selectAll: false, //
chatHistoryAI: [], // ai chatHistoryAI: [], // ai
chatHistoryTeacher: [], // chatHistoryTeacher: [], //
openedItems: {}, //
}; };
}, },
computed: { computed: {
@ -170,6 +202,26 @@ export default {
this.isBatchDeleteMode = false; this.isBatchDeleteMode = false;
}, },
//
closeAllSwipeActions() {
const swipeActionRefs = this.$refs.swipeActionRef || [];
const refs = Array.isArray(swipeActionRefs)
? swipeActionRefs
: [swipeActionRefs];
refs.forEach((ref) => {
if (ref && typeof ref.closeAll === "function") {
ref.closeAll();
}
});
},
// openedItems closeAllSwipeActions()
resetSwipeState() {
this.openedItems = {};
this.closeAllSwipeActions();
},
// ai // ai
async getChatHistoryList() { async getChatHistoryList() {
this.$u.api.GetConversationPage().then((res) => { this.$u.api.GetConversationPage().then((res) => {
@ -189,7 +241,7 @@ export default {
// }; // };
// }); // });
// } // }
console.log("this.chatHistoryAI", this.chatHistoryAI); // console.log("this.chatHistoryAI", this.chatHistoryAI);
}); });
}, },
@ -279,6 +331,7 @@ export default {
} }
this.activeTab = tab; this.activeTab = tab;
this.resetSwipeState();
// tabtab // tabtab
if (tab === "1") { if (tab === "1") {
this.getChatHistoryList(); this.getChatHistoryList();
@ -300,6 +353,7 @@ export default {
// //
cancelBatchDelete() { cancelBatchDelete() {
this.resetBatchState(); this.resetBatchState();
this.resetSwipeState();
}, },
// //
@ -313,6 +367,9 @@ export default {
// //
toggleBatchDeleteMode() { toggleBatchDeleteMode() {
this.isBatchDeleteMode = !this.isBatchDeleteMode; this.isBatchDeleteMode = !this.isBatchDeleteMode;
if (this.isBatchDeleteMode) {
this.resetSwipeState();
}
if (!this.isBatchDeleteMode) { if (!this.isBatchDeleteMode) {
// 退 // 退
this.selectedItems = []; this.selectedItems = [];
@ -369,7 +426,9 @@ export default {
if (isAiTab) { if (isAiTab) {
res = await this.$u.api.DeleteDialogueManagement({ id: deleteIds }); res = await this.$u.api.DeleteDialogueManagement({ id: deleteIds });
} else { } else {
res = await this.$u.api.DeleteDialogueApi({ dialogueManagementIds: deleteIds }); res = await this.$u.api.DeleteDialogueApi({
dialogueManagementIds: deleteIds,
});
} }
if (res && res.succeed === true) { if (res && res.succeed === true) {
@ -399,6 +458,55 @@ export default {
}); });
} }
}, },
//
handleSwipeChange(e, itemId) {
this.$set(this.openedItems, itemId, e);
},
//
async handleSingleDelete(item) {
if (!item || !item.id) return;
if (this.isBatchDeleteMode) return;
const isAiTab = this.activeTab === "1";
const deleteIds = [item.id];
try {
let res = null;
if (isAiTab) {
res = await this.$u.api.DeleteDialogueManagement({ id: deleteIds });
} else {
res = await this.$u.api.DeleteDialogueApi({
dialogueManagementIds: deleteIds,
});
}
if (res && res.succeed === true) {
if (isAiTab) {
this.getChatHistoryList();
} else {
this.GetDialogueList_User();
}
this.$refs.uToast.show({
title: "删除成功",
type: "success",
});
return;
}
this.$refs.uToast.show({
title: (res && (res.msg || res.message)) || "删除失败",
type: "error",
});
} catch (e) {
this.$refs.uToast.show({
title: "删除失败",
type: "error",
});
}
},
}, },
}; };
</script> </script>
@ -520,6 +628,19 @@ export default {
} }
.history-list { .history-list {
.right-btn-box {
width: 160rpx;
color: #ffffff;
background-color: #ff4757;
display: flex;
flex-direction: column;
gap: 10rpx;
align-items: center;
justify-content: center;
border-radius: 0 16rpx 16rpx 0;
border-left: 1px solid #fff;
}
.date-group { .date-group {
margin-bottom: 32rpx; margin-bottom: 32rpx;
} }
@ -534,7 +655,15 @@ export default {
.history-item { .history-item {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;
padding: 24rpx 0; padding: 24rpx;
background-color: #ffffff;
border-radius: 16rpx;
transition: border-radius 0.3s;
&.no-right-radius {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.item-checkbox { .item-checkbox {
margin-right: 24rpx; margin-right: 24rpx;