fix: 提交
This commit is contained in:
parent
01529b1b99
commit
d74c06325d
@ -7,8 +7,14 @@
|
|||||||
<view v-if="customScroll" class="page-scroll">
|
<view v-if="customScroll" class="page-scroll">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</view>
|
</view>
|
||||||
<scroll-view v-else scroll-y="true" :scroll-top="scrollTop" class="page-scroll" @scrolltolower="scrolltolower"
|
<scroll-view
|
||||||
@scroll="onScroll">
|
v-else
|
||||||
|
scroll-y="true"
|
||||||
|
:scroll-top="scrollTop"
|
||||||
|
class="page-scroll"
|
||||||
|
@scrolltolower="scrolltolower"
|
||||||
|
@scroll="onScroll"
|
||||||
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
@ -16,19 +22,19 @@
|
|||||||
<slot name="footer"></slot>
|
<slot name="footer"></slot>
|
||||||
</view>
|
</view>
|
||||||
<!-- #ifdef MP-->
|
<!-- #ifdef MP-->
|
||||||
<view class="safeareaBottom"></view>
|
<!-- <view class="safeareaBottom"></view> -->
|
||||||
<!-- #endif -->
|
<!-- #endif -->
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, useSlots, ref } from 'vue';
|
import { computed, useSlots, ref } from "vue";
|
||||||
import useDebounce from '@/utils/useDebounce';
|
import useDebounce from "@/utils/useDebounce";
|
||||||
|
|
||||||
const emits = defineEmits(['reachBottom']);
|
const emits = defineEmits(["reachBottom"]);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
customScroll: { type: Boolean, default: false },
|
customScroll: { type: Boolean, default: false },
|
||||||
mainStyle: { default: '' },
|
mainStyle: { default: "" },
|
||||||
pageStyle: { default: '' }
|
pageStyle: { default: "" },
|
||||||
});
|
});
|
||||||
const slots = useSlots();
|
const slots = useSlots();
|
||||||
const hasHeader = computed(() => !!slots.header);
|
const hasHeader = computed(() => !!slots.header);
|
||||||
@ -37,7 +43,7 @@ const hasFooter = computed(() => !!slots.footer);
|
|||||||
const scrollTop = ref(0);
|
const scrollTop = ref(0);
|
||||||
|
|
||||||
const scrolltolower = useDebounce(() => {
|
const scrolltolower = useDebounce(() => {
|
||||||
emits('reachBottom');
|
emits("reachBottom");
|
||||||
});
|
});
|
||||||
|
|
||||||
const onScroll = useDebounce((e) => {
|
const onScroll = useDebounce((e) => {
|
||||||
@ -49,9 +55,8 @@ function scrollToBottom() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
scrollToBottom
|
scrollToBottom,
|
||||||
})
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.full-page {
|
.full-page {
|
||||||
|
|||||||
@ -285,14 +285,17 @@ const setupConversationListener = () => {
|
|||||||
existing.lastMessageTime !== conversationData.lastMessageTime ||
|
existing.lastMessageTime !== conversationData.lastMessageTime ||
|
||||||
existing.unreadCount !== conversationData.unreadCount
|
existing.unreadCount !== conversationData.unreadCount
|
||||||
) {
|
) {
|
||||||
// 使用 Object.assign 更新,保持引用稳定
|
// 只更新变化的字段,保持头像和未读数稳定
|
||||||
Object.assign(
|
conversationList.value[existingIndex] = {
|
||||||
conversationList.value[existingIndex],
|
...conversationData,
|
||||||
conversationData
|
// 保持原有头像,避免闪动
|
||||||
);
|
avatar: existing.avatar || conversationData.avatar,
|
||||||
|
// 保留较大的未读数(避免被后端数据覆盖)
|
||||||
|
unreadCount: Math.max(existing.unreadCount || 0, conversationData.unreadCount || 0)
|
||||||
|
};
|
||||||
needSort = true;
|
needSort = true;
|
||||||
console.log(
|
console.log(
|
||||||
`已更新会话: ${conversationData.name}, unreadCount: ${conversationData.unreadCount}`
|
`已更新会话: ${conversationData.name}, unreadCount: ${conversationList.value[existingIndex].unreadCount}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -325,19 +328,23 @@ const setupConversationListener = () => {
|
|||||||
if (conversationIndex !== -1) {
|
if (conversationIndex !== -1) {
|
||||||
const conversation = conversationList.value[conversationIndex];
|
const conversation = conversationList.value[conversationIndex];
|
||||||
|
|
||||||
// 检查当前页面栈,判断用户是否正在查看该会话
|
// 检查当前页面栈,判断用户是否正在查看该会话的聊天详情页
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
const currentPage = pages[pages.length - 1];
|
const currentPage = pages[pages.length - 1];
|
||||||
const isViewingConversation =
|
|
||||||
currentPage?.route === "pages/message/index";
|
|
||||||
|
|
||||||
// 如果用户正在查看该会话,不增加未读数
|
// 获取当前页面的 groupID 参数(如果在聊天详情页)
|
||||||
if (isViewingConversation) {
|
const currentGroupID = currentPage?.options?.groupID;
|
||||||
|
const isViewingThisConversation =
|
||||||
|
currentPage?.route === "pages/message/index" &&
|
||||||
|
currentGroupID === conversation.groupID;
|
||||||
|
|
||||||
|
// 如果用户正在查看这个具体的会话,不增加未读数
|
||||||
|
if (isViewingThisConversation) {
|
||||||
console.log("用户正在查看该会话,不增加未读数");
|
console.log("用户正在查看该会话,不增加未读数");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只在用户不在聊天页面时才增加未读数
|
// 只在用户不在该会话的聊天页面时才增加未读数
|
||||||
conversation.unreadCount = (conversation.unreadCount || 0) + 1;
|
conversation.unreadCount = (conversation.unreadCount || 0) + 1;
|
||||||
console.log(
|
console.log(
|
||||||
"已更新会话未读数:",
|
"已更新会话未读数:",
|
||||||
|
|||||||
@ -143,8 +143,8 @@ function mergeConversationData(conversation, groupDetailsMap) {
|
|||||||
// 更新显示名称(使用后端的患者信息)
|
// 更新显示名称(使用后端的患者信息)
|
||||||
name: formatConversationName(groupDetail),
|
name: formatConversationName(groupDetail),
|
||||||
|
|
||||||
// 更新头像
|
// 更新头像(优先使用已有头像,避免闪动)
|
||||||
avatar: groupDetail.patient?.avatar || conversation.avatar || '/static/default-avatar.png'
|
avatar: conversation.avatar || groupDetail.patient?.avatar || '/static/default-avatar.png'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user