2024-07-15 03:53:35 +00:00
|
|
|
|
<template>
|
2024-07-16 08:23:49 +00:00
|
|
|
|
<!-- 聊天虚拟列表 -->
|
|
|
|
|
<z-paging ref="pagingRef" v-model="messageList" use-chat-record-mode use-virtual-list
|
|
|
|
|
cell-height-mode="dynamic" default-page-size="20" :auto-clean-list-when-reload="false"
|
|
|
|
|
safe-area-inset-bottom bottom-bg-color="#f8f8f8" :back-to-top-style="backToTopStyle"
|
|
|
|
|
:auto-show-back-to-top="showNewMessageTip" @backToTopClick="onBackToTopClick"
|
|
|
|
|
@scrolltoupper="onScrollToUpper" @query="queryList">
|
2024-07-17 08:45:03 +00:00
|
|
|
|
<template #top>
|
|
|
|
|
<!-- 撑一下顶部导航 -->
|
2024-09-01 09:37:26 +00:00
|
|
|
|
<view :style="{ height: sys_navBar + 'px' }"></view>
|
2024-07-17 08:45:03 +00:00
|
|
|
|
</template>
|
2024-07-16 08:23:49 +00:00
|
|
|
|
<!-- style="transform: scaleY(-1)"必须写,否则会导致列表倒置!!! -->
|
|
|
|
|
<!-- 注意不要直接在chat-item组件标签上设置style,因为在微信小程序中是无效的,请包一层view -->
|
|
|
|
|
<template #cell="{item,index}">
|
|
|
|
|
<view style="transform: scaleY(-1)">
|
2024-07-15 03:53:35 +00:00
|
|
|
|
<!-- 消息渲染 -->
|
2024-07-16 08:23:49 +00:00
|
|
|
|
<MessageListItem :message="item" :message-index="index" :message-list="messageList"></MessageListItem>
|
2024-07-15 03:53:35 +00:00
|
|
|
|
</view>
|
2024-07-16 08:23:49 +00:00
|
|
|
|
</template>
|
|
|
|
|
<!-- 底部聊天输入框 -->
|
|
|
|
|
<template #bottom>
|
|
|
|
|
<slot name="bottom"></slot>
|
|
|
|
|
</template>
|
2024-07-15 03:53:35 +00:00
|
|
|
|
<!-- 查看最新消息 -->
|
2024-07-16 08:23:49 +00:00
|
|
|
|
<template #backToTop>
|
2024-07-15 03:53:35 +00:00
|
|
|
|
<text>有新消息</text>
|
2024-07-16 08:23:49 +00:00
|
|
|
|
</template>
|
|
|
|
|
</z-paging>
|
2024-07-15 03:53:35 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-07-16 08:23:49 +00:00
|
|
|
|
import MessageListItem from '@/pages/chat/components/messageListItem.vue';
|
|
|
|
|
import { reactive, ref } from 'vue';
|
2024-07-15 03:53:35 +00:00
|
|
|
|
import KeFuApi from '@/sheep/api/promotion/kefu';
|
2024-07-16 08:23:49 +00:00
|
|
|
|
import { isEmpty } from '@/sheep/helper/utils';
|
2024-09-01 09:37:26 +00:00
|
|
|
|
import sheep from '@/sheep';
|
|
|
|
|
|
|
|
|
|
const sys_navBar = sheep.$platform.navbar;
|
2024-07-15 03:53:35 +00:00
|
|
|
|
const messageList = ref([]); // 消息列表
|
2024-07-15 10:05:59 +00:00
|
|
|
|
const showNewMessageTip = ref(false); // 显示有新消息提示
|
2024-07-16 08:23:49 +00:00
|
|
|
|
const backToTopStyle = reactive({
|
|
|
|
|
'width': '100px',
|
|
|
|
|
'background-color': '#fff',
|
|
|
|
|
'border-radius': '30px',
|
|
|
|
|
'box-shadow': '0 2px 4px rgba(0, 0, 0, 0.1)',
|
|
|
|
|
'display': 'flex',
|
|
|
|
|
'justifyContent': 'center',
|
|
|
|
|
'alignItems': 'center',
|
|
|
|
|
}); // 返回顶部样式
|
2024-07-15 03:53:35 +00:00
|
|
|
|
const queryParams = reactive({
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
});
|
2024-07-16 08:23:49 +00:00
|
|
|
|
const pagingRef = ref(null); // 虚拟列表
|
|
|
|
|
const queryList = async (pageNo, pageSize) => {
|
|
|
|
|
// 组件加载时会自动触发此方法,因此默认页面加载时会自动触发,无需手动调用
|
|
|
|
|
// 这里的pageNo和pageSize会自动计算好,直接传给服务器即可
|
|
|
|
|
queryParams.pageNo = pageNo;
|
|
|
|
|
queryParams.pageSize = pageSize;
|
|
|
|
|
await getMessageList();
|
|
|
|
|
};
|
2024-07-15 03:53:35 +00:00
|
|
|
|
// 获得消息分页列表
|
|
|
|
|
const getMessageList = async () => {
|
2024-07-16 08:23:49 +00:00
|
|
|
|
const { data } = await KeFuApi.getKefuMessagePage(queryParams);
|
2024-07-15 03:53:35 +00:00
|
|
|
|
if (isEmpty(data.list)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-16 08:23:49 +00:00
|
|
|
|
pagingRef.value.completeByTotal(data.list, data.total);
|
2024-07-15 03:53:35 +00:00
|
|
|
|
};
|
|
|
|
|
/** 刷新消息列表 */
|
2024-07-16 08:23:49 +00:00
|
|
|
|
const refreshMessageList = (message = undefined) => {
|
2024-09-01 09:37:26 +00:00
|
|
|
|
if (message !== undefined) {
|
2024-07-15 03:53:35 +00:00
|
|
|
|
showNewMessageTip.value = true;
|
2024-07-16 08:23:49 +00:00
|
|
|
|
// 追加数据
|
|
|
|
|
pagingRef.value.addChatRecordData([message], false);
|
2024-07-15 03:53:35 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-16 08:23:49 +00:00
|
|
|
|
pagingRef.value.reload();
|
2024-07-15 03:53:35 +00:00
|
|
|
|
};
|
2024-07-16 08:23:49 +00:00
|
|
|
|
/** 滚动到最新消息 */
|
|
|
|
|
const onBackToTopClick = (event) => {
|
|
|
|
|
event(false); // 禁用默认操作
|
|
|
|
|
pagingRef.value.scrollToBottom();
|
2024-07-15 03:53:35 +00:00
|
|
|
|
};
|
2024-07-16 08:23:49 +00:00
|
|
|
|
/** 监听滚动到底部事件(因为 scroll 翻转了顶就是底) */
|
|
|
|
|
const onScrollToUpper = () => {
|
|
|
|
|
// 若已是第一页则不做处理
|
|
|
|
|
if (queryParams.pageNo === 1) {
|
2024-07-15 03:53:35 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-16 08:23:49 +00:00
|
|
|
|
showNewMessageTip.value = false;
|
2024-07-15 03:53:35 +00:00
|
|
|
|
};
|
2024-07-16 08:23:49 +00:00
|
|
|
|
defineExpose({ getMessageList, refreshMessageList });
|
2024-07-15 03:53:35 +00:00
|
|
|
|
</script>
|