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 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
:disabled="isBatchDeleteMode"
:threshold="0.3"
@ -123,7 +123,10 @@
</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="checkbox" :class="{ checked: selectAll }">
<text class="checkmark" v-if="selectAll"></text>
@ -164,6 +167,7 @@ export default {
chatHistoryAI: [], // ai
chatHistoryTeacher: [], //
openedItems: {}, //
openedSwipeId: "", // id
};
},
computed: {
@ -207,16 +211,9 @@ export default {
//
closeAllSwipeActions() {
const swipeActionRefs = this.$refs.swipeActionRef || [];
const refs = Array.isArray(swipeActionRefs)
? swipeActionRefs
: [swipeActionRefs];
refs.forEach((ref) => {
if (ref && typeof ref.closeAll === "function") {
ref.closeAll();
}
});
const ids = this.currentHistoryItemIds || [];
ids.forEach((id) => this.closeSwipeActionById(id));
this.openedSwipeId = "";
},
// openedItems closeAllSwipeActions()
@ -225,6 +222,16 @@ export default {
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
async getChatHistoryList() {
this.$u.api.GetConversationPage().then((res) => {
@ -465,6 +472,16 @@ export default {
//
handleSwipeChange(e, itemId) {
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 = "";
}
},
//