refactor(历史记录): 实现侧滑互斥:打开新项自动收起旧项

This commit is contained in:
yangzhe 2025-12-18 09:17:50 +08:00
parent 59d492dfb9
commit 909cf26549
1 changed files with 29 additions and 12 deletions

View File

@ -52,7 +52,7 @@
<view class="date-header">{{ group.id }}</view> <view class="date-header">{{ group.id }}</view>
<view v-for="item in group.conversation" :key="item.id"> <view v-for="item in group.conversation" :key="item.id">
<uni-swipe-action ref="swipeActionRef"> <uni-swipe-action :ref="'swipe-' + item.id">
<uni-swipe-action-item <uni-swipe-action-item
:disabled="isBatchDeleteMode" :disabled="isBatchDeleteMode"
:threshold="0.3" :threshold="0.3"
@ -123,7 +123,10 @@
</view> </view>
<!-- 批量删除操作栏 --> <!-- 批量删除操作栏 -->
<view class="batch-actions" v-if="isBatchDeleteMode && currentHistoryItems.length"> <view
class="batch-actions"
v-if="isBatchDeleteMode && currentHistoryItems.length"
>
<view class="select-all-container" @click="toggleSelectAll"> <view class="select-all-container" @click="toggleSelectAll">
<view class="checkbox" :class="{ checked: selectAll }"> <view class="checkbox" :class="{ checked: selectAll }">
<text class="checkmark" v-if="selectAll"></text> <text class="checkmark" v-if="selectAll"></text>
@ -164,6 +167,7 @@ export default {
chatHistoryAI: [], // ai chatHistoryAI: [], // ai
chatHistoryTeacher: [], // chatHistoryTeacher: [], //
openedItems: {}, // openedItems: {}, //
openedSwipeId: "", // id
}; };
}, },
computed: { computed: {
@ -207,16 +211,9 @@ export default {
// //
closeAllSwipeActions() { closeAllSwipeActions() {
const swipeActionRefs = this.$refs.swipeActionRef || []; const ids = this.currentHistoryItemIds || [];
const refs = Array.isArray(swipeActionRefs) ids.forEach((id) => this.closeSwipeActionById(id));
? swipeActionRefs this.openedSwipeId = "";
: [swipeActionRefs];
refs.forEach((ref) => {
if (ref && typeof ref.closeAll === "function") {
ref.closeAll();
}
});
}, },
// openedItems closeAllSwipeActions() // openedItems closeAllSwipeActions()
@ -225,6 +222,16 @@ export default {
this.closeAllSwipeActions(); this.closeAllSwipeActions();
}, },
closeSwipeActionById(itemId) {
if (!itemId) return;
const swipeRef = this.$refs[`swipe-${itemId}`];
const ref = Array.isArray(swipeRef) ? swipeRef[0] : swipeRef;
if (ref && typeof ref.closeAll === "function") {
ref.closeAll();
}
this.$set(this.openedItems, itemId, "none");
},
// ai // ai
async getChatHistoryList() { async getChatHistoryList() {
this.$u.api.GetConversationPage().then((res) => { this.$u.api.GetConversationPage().then((res) => {
@ -465,6 +472,16 @@ export default {
// //
handleSwipeChange(e, itemId) { handleSwipeChange(e, itemId) {
this.$set(this.openedItems, itemId, e); this.$set(this.openedItems, itemId, e);
if (e === "right" || e === "left") {
if (this.openedSwipeId && this.openedSwipeId !== itemId) {
this.closeSwipeActionById(this.openedSwipeId);
}
this.openedSwipeId = itemId;
return;
}
if (e === "none" && this.openedSwipeId === itemId) {
this.openedSwipeId = "";
}
}, },
// //