|
@@ -1,11 +1,11 @@
|
|
<template>
|
|
<template>
|
|
<el-container v-if="showKeFuMessageList" class="kefu">
|
|
<el-container v-if="showKeFuMessageList" class="kefu">
|
|
- <el-header>
|
|
|
|
|
|
+ <el-header class="kefu-header">
|
|
<div class="kefu-title">{{ conversation.userNickname }}</div>
|
|
<div class="kefu-title">{{ conversation.userNickname }}</div>
|
|
</el-header>
|
|
</el-header>
|
|
<el-main class="kefu-content overflow-visible">
|
|
<el-main class="kefu-content overflow-visible">
|
|
- <el-scrollbar ref="scrollbarRef" always height="calc(100vh - 495px)" @scroll="handleScroll">
|
|
|
|
- <div v-if="refreshContent" ref="innerRef" class="w-[100%] pb-3px">
|
|
|
|
|
|
+ <el-scrollbar ref="scrollbarRef" always @scroll="handleScroll">
|
|
|
|
+ <div v-if="refreshContent" ref="innerRef" class="w-[100%] px-10px">
|
|
<!-- 消息列表 -->
|
|
<!-- 消息列表 -->
|
|
<div v-for="(item, index) in getMessageList0" :key="item.id" class="w-[100%]">
|
|
<div v-for="(item, index) in getMessageList0" :key="item.id" class="w-[100%]">
|
|
<div class="flex justify-center items-center mb-20px">
|
|
<div class="flex justify-center items-center mb-20px">
|
|
@@ -43,7 +43,9 @@
|
|
class="w-60px h-60px"
|
|
class="w-60px h-60px"
|
|
/>
|
|
/>
|
|
<div
|
|
<div
|
|
- :class="{ 'kefu-message': KeFuMessageContentTypeEnum.TEXT === item.contentType }"
|
|
|
|
|
|
+ :class="{
|
|
|
|
+ 'kefu-message': KeFuMessageContentTypeEnum.TEXT === item.contentType
|
|
|
|
+ }"
|
|
class="p-10px"
|
|
class="p-10px"
|
|
>
|
|
>
|
|
<!-- 文本消息 -->
|
|
<!-- 文本消息 -->
|
|
@@ -71,10 +73,10 @@
|
|
<MessageItem :message="item">
|
|
<MessageItem :message="item">
|
|
<ProductItem
|
|
<ProductItem
|
|
v-if="KeFuMessageContentTypeEnum.PRODUCT === item.contentType"
|
|
v-if="KeFuMessageContentTypeEnum.PRODUCT === item.contentType"
|
|
- :spuId="getMessageContent(item).spuId"
|
|
|
|
:picUrl="getMessageContent(item).picUrl"
|
|
:picUrl="getMessageContent(item).picUrl"
|
|
:price="getMessageContent(item).price"
|
|
:price="getMessageContent(item).price"
|
|
:skuText="getMessageContent(item).introduction"
|
|
:skuText="getMessageContent(item).introduction"
|
|
|
|
+ :spuId="getMessageContent(item).spuId"
|
|
:title="getMessageContent(item).spuName"
|
|
:title="getMessageContent(item).spuName"
|
|
:titleWidth="400"
|
|
:titleWidth="400"
|
|
class="max-w-70%"
|
|
class="max-w-70%"
|
|
@@ -108,23 +110,29 @@
|
|
<Icon class="ml-5px" icon="ep:bottom" />
|
|
<Icon class="ml-5px" icon="ep:bottom" />
|
|
</div>
|
|
</div>
|
|
</el-main>
|
|
</el-main>
|
|
- <el-footer height="230px">
|
|
|
|
- <div class="h-[100%]">
|
|
|
|
- <div class="chat-tools flex items-center">
|
|
|
|
- <EmojiSelectPopover @select-emoji="handleEmojiSelect" />
|
|
|
|
- <PictureSelectUpload
|
|
|
|
- class="ml-15px mt-3px cursor-pointer"
|
|
|
|
- @send-picture="handleSendPicture"
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- <el-input v-model="message" :rows="6" style="border-style: none" type="textarea" />
|
|
|
|
- <div class="h-45px flex justify-end">
|
|
|
|
- <el-button class="mt-10px" type="primary" @click="handleSendMessage">发送</el-button>
|
|
|
|
- </div>
|
|
|
|
|
|
+ <el-footer class="kefu-footer">
|
|
|
|
+ <div class="chat-tools flex items-center">
|
|
|
|
+ <EmojiSelectPopover @select-emoji="handleEmojiSelect" />
|
|
|
|
+ <PictureSelectUpload
|
|
|
|
+ class="ml-15px mt-3px cursor-pointer"
|
|
|
|
+ @send-picture="handleSendPicture"
|
|
|
|
+ />
|
|
</div>
|
|
</div>
|
|
|
|
+ <el-input
|
|
|
|
+ v-model="message"
|
|
|
|
+ :rows="6"
|
|
|
|
+ placeholder="输入消息,Enter发送,Shift+Enter换行"
|
|
|
|
+ style="border-style: none"
|
|
|
|
+ type="textarea"
|
|
|
|
+ @keyup.enter.prevent="handleSendMessage"
|
|
|
|
+ />
|
|
</el-footer>
|
|
</el-footer>
|
|
</el-container>
|
|
</el-container>
|
|
- <el-empty v-else description="请选择左侧的一个会话后开始" />
|
|
|
|
|
|
+ <el-container v-else class="kefu">
|
|
|
|
+ <el-main>
|
|
|
|
+ <el-empty description="请选择左侧的一个会话后开始" />
|
|
|
|
+ </el-main>
|
|
|
|
+ </el-container>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
@@ -156,9 +164,8 @@ const messageList = ref<KeFuMessageRespVO[]>([]) // 消息列表
|
|
const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 用户会话
|
|
const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 用户会话
|
|
const showNewMessageTip = ref(false) // 显示有新消息提示
|
|
const showNewMessageTip = ref(false) // 显示有新消息提示
|
|
const queryParams = reactive({
|
|
const queryParams = reactive({
|
|
- pageNo: 1,
|
|
|
|
- pageSize: 10,
|
|
|
|
- conversationId: 0
|
|
|
|
|
|
+ conversationId: 0,
|
|
|
|
+ createTime: undefined
|
|
})
|
|
})
|
|
const total = ref(0) // 消息总条数
|
|
const total = ref(0) // 消息总条数
|
|
const refreshContent = ref(false) // 内容刷新,主要解决会话消息页面高度不一致导致的滚动功能精度失效
|
|
const refreshContent = ref(false) // 内容刷新,主要解决会话消息页面高度不一致导致的滚动功能精度失效
|
|
@@ -167,14 +174,20 @@ const refreshContent = ref(false) // 内容刷新,主要解决会话消息页面
|
|
const getMessageContent = computed(() => (item: any) => jsonParse(item.content))
|
|
const getMessageContent = computed(() => (item: any) => jsonParse(item.content))
|
|
/** 获得消息列表 */
|
|
/** 获得消息列表 */
|
|
const getMessageList = async () => {
|
|
const getMessageList = async () => {
|
|
- const res = await KeFuMessageApi.getKeFuMessagePage(queryParams)
|
|
|
|
- total.value = res.total
|
|
|
|
|
|
+ const res = await KeFuMessageApi.getKeFuMessageList(queryParams)
|
|
|
|
+ if (isEmpty(res)) {
|
|
|
|
+ // 当返回的是空列表说明没有消息或者已经查询完了历史消息
|
|
|
|
+ skipGetMessageList.value = true
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ queryParams.createTime = formatDate(res.at(-1).createTime) as any
|
|
|
|
+
|
|
// 情况一:加载最新消息
|
|
// 情况一:加载最新消息
|
|
- if (queryParams.pageNo === 1) {
|
|
|
|
- messageList.value = res.list
|
|
|
|
|
|
+ if (!queryParams.createTime) {
|
|
|
|
+ messageList.value = res
|
|
} else {
|
|
} else {
|
|
// 情况二:加载历史消息
|
|
// 情况二:加载历史消息
|
|
- for (const item of res.list) {
|
|
|
|
|
|
+ for (const item of res) {
|
|
pushMessage(item)
|
|
pushMessage(item)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -208,8 +221,7 @@ const refreshMessageList = async (message?: any) => {
|
|
}
|
|
}
|
|
pushMessage(message)
|
|
pushMessage(message)
|
|
} else {
|
|
} else {
|
|
- // TODO @puhui999:不基于 page 做。而是流式分页;通过 createTime 排序查询;
|
|
|
|
- queryParams.pageNo = 1
|
|
|
|
|
|
+ queryParams.createTime = undefined
|
|
await getMessageList()
|
|
await getMessageList()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -226,7 +238,6 @@ const refreshMessageList = async (message?: any) => {
|
|
// TODO @puhui999:可优化:可以考虑本地做每个会话的消息 list 缓存;然后点击切换时,读取缓存;然后异步获取新消息,merge 下;
|
|
// TODO @puhui999:可优化:可以考虑本地做每个会话的消息 list 缓存;然后点击切换时,读取缓存;然后异步获取新消息,merge 下;
|
|
const getNewMessageList = async (val: KeFuConversationRespVO) => {
|
|
const getNewMessageList = async (val: KeFuConversationRespVO) => {
|
|
// 会话切换,重置相关参数
|
|
// 会话切换,重置相关参数
|
|
- queryParams.pageNo = 1
|
|
|
|
messageList.value = []
|
|
messageList.value = []
|
|
total.value = 0
|
|
total.value = 0
|
|
loadHistory.value = false
|
|
loadHistory.value = false
|
|
@@ -234,16 +245,14 @@ const getNewMessageList = async (val: KeFuConversationRespVO) => {
|
|
// 设置会话相关属性
|
|
// 设置会话相关属性
|
|
conversation.value = val
|
|
conversation.value = val
|
|
queryParams.conversationId = val.id
|
|
queryParams.conversationId = val.id
|
|
|
|
+ queryParams.createTime = undefined
|
|
// 获取消息
|
|
// 获取消息
|
|
await refreshMessageList()
|
|
await refreshMessageList()
|
|
}
|
|
}
|
|
defineExpose({ getNewMessageList, refreshMessageList })
|
|
defineExpose({ getNewMessageList, refreshMessageList })
|
|
|
|
|
|
const showKeFuMessageList = computed(() => !isEmpty(conversation.value)) // 是否显示聊天区域
|
|
const showKeFuMessageList = computed(() => !isEmpty(conversation.value)) // 是否显示聊天区域
|
|
-const skipGetMessageList = computed(() => {
|
|
|
|
- // 已加载到最后一页的话则不触发新的消息获取
|
|
|
|
- return total.value > 0 && Math.ceil(total.value / queryParams.pageSize) === queryParams.pageNo
|
|
|
|
-}) // 跳过消息获取
|
|
|
|
|
|
+const skipGetMessageList = ref(false) // 跳过消息获取
|
|
|
|
|
|
/** 处理表情选择 */
|
|
/** 处理表情选择 */
|
|
const handleEmojiSelect = (item: Emoji) => {
|
|
const handleEmojiSelect = (item: Emoji) => {
|
|
@@ -262,7 +271,11 @@ const handleSendPicture = async (picUrl: string) => {
|
|
}
|
|
}
|
|
|
|
|
|
/** 发送文本消息 */
|
|
/** 发送文本消息 */
|
|
-const handleSendMessage = async () => {
|
|
|
|
|
|
+const handleSendMessage = async (event: any) => {
|
|
|
|
+ // shift 不发送
|
|
|
|
+ if (event.shiftKey) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// 1. 校验消息是否为空
|
|
// 1. 校验消息是否为空
|
|
if (isEmpty(unref(message.value))) {
|
|
if (isEmpty(unref(message.value))) {
|
|
messageTool.notifyWarning('请输入消息后再发送哦!')
|
|
messageTool.notifyWarning('请输入消息后再发送哦!')
|
|
@@ -333,8 +346,6 @@ const handleOldMessage = async () => {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
loadHistory.value = true
|
|
loadHistory.value = true
|
|
- // 加载消息列表
|
|
|
|
- queryParams.pageNo += 1
|
|
|
|
await getMessageList()
|
|
await getMessageList()
|
|
// 等页面加载完后,获得上一页最后一条消息的位置,控制滚动到它所在位置
|
|
// 等页面加载完后,获得上一页最后一条消息的位置,控制滚动到它所在位置
|
|
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight - oldPageHeight)
|
|
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight - oldPageHeight)
|
|
@@ -357,14 +368,29 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
.kefu {
|
|
.kefu {
|
|
- &-title {
|
|
|
|
- border-bottom: #e4e0e0 solid 1px;
|
|
|
|
- height: 60px;
|
|
|
|
- line-height: 60px;
|
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
+ width: calc(100% - 300px - 260px);
|
|
|
|
+ border-left: var(--el-border-color) solid 1px;
|
|
|
|
+
|
|
|
|
+ .kefu-header {
|
|
|
|
+ background: #fbfbfb;
|
|
|
|
+ box-shadow: 0 0 0 0 #dcdfe6;
|
|
|
|
+ display: flex;
|
|
|
|
+ align-items: center;
|
|
|
|
+ justify-content: space-between;
|
|
|
|
+
|
|
|
|
+ &-title {
|
|
|
|
+ font-size: 18px;
|
|
|
|
+ font-weight: bold;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
&-content {
|
|
&-content {
|
|
|
|
+ margin: 0;
|
|
|
|
+ padding: 0;
|
|
position: relative;
|
|
position: relative;
|
|
|
|
+ height: 100%;
|
|
|
|
+ width: 100%;
|
|
|
|
|
|
.newMessageTip {
|
|
.newMessageTip {
|
|
position: absolute;
|
|
position: absolute;
|
|
@@ -381,21 +407,12 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
|
|
justify-content: flex-start;
|
|
justify-content: flex-start;
|
|
|
|
|
|
.kefu-message {
|
|
.kefu-message {
|
|
- margin-left: 20px;
|
|
|
|
- position: relative;
|
|
|
|
-
|
|
|
|
- &::before {
|
|
|
|
- content: '';
|
|
|
|
- width: 10px;
|
|
|
|
- height: 10px;
|
|
|
|
- left: -19px;
|
|
|
|
- top: calc(50% - 10px);
|
|
|
|
- position: absolute;
|
|
|
|
- border-left: 5px solid transparent;
|
|
|
|
- border-bottom: 5px solid transparent;
|
|
|
|
- border-top: 5px solid transparent;
|
|
|
|
- border-right: 5px solid var(--app-content-bg-color);
|
|
|
|
- }
|
|
|
|
|
|
+ background-color: rgb(245, 245, 245);
|
|
|
|
+ margin-left: 10px;
|
|
|
|
+ margin-top: 18px;
|
|
|
|
+ border-top-right-radius: 10px;
|
|
|
|
+ border-bottom-right-radius: 10px;
|
|
|
|
+ border-bottom-left-radius: 10px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -403,37 +420,25 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
|
|
justify-content: flex-end;
|
|
justify-content: flex-end;
|
|
|
|
|
|
.kefu-message {
|
|
.kefu-message {
|
|
- margin-right: 20px;
|
|
|
|
- position: relative;
|
|
|
|
-
|
|
|
|
- &::after {
|
|
|
|
- content: '';
|
|
|
|
- width: 10px;
|
|
|
|
- height: 10px;
|
|
|
|
- right: -19px;
|
|
|
|
- top: calc(50% - 10px);
|
|
|
|
- position: absolute;
|
|
|
|
- border-left: 5px solid var(--app-content-bg-color);
|
|
|
|
- border-bottom: 5px solid transparent;
|
|
|
|
- border-top: 5px solid transparent;
|
|
|
|
- border-right: 5px solid transparent;
|
|
|
|
- }
|
|
|
|
|
|
+ background-color: rgb(206, 223, 255);
|
|
|
|
+ margin-right: 10px;
|
|
|
|
+ margin-top: 18px;
|
|
|
|
+ border-top-left-radius: 10px;
|
|
|
|
+ border-bottom-right-radius: 10px;
|
|
|
|
+ border-bottom-left-radius: 10px;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 消息气泡
|
|
// 消息气泡
|
|
.kefu-message {
|
|
.kefu-message {
|
|
- color: #a9a9a9;
|
|
|
|
- border-radius: 5px;
|
|
|
|
- box-shadow: 3px 3px 5px rgba(220, 220, 220, 0.1);
|
|
|
|
|
|
+ color: #414141;
|
|
|
|
+ font-weight: 500;
|
|
padding: 5px 10px;
|
|
padding: 5px 10px;
|
|
width: auto;
|
|
width: auto;
|
|
max-width: 50%;
|
|
max-width: 50%;
|
|
text-align: left;
|
|
text-align: left;
|
|
display: inline-block !important;
|
|
display: inline-block !important;
|
|
- position: relative;
|
|
|
|
word-break: break-all;
|
|
word-break: break-all;
|
|
- background-color: var(--app-content-bg-color);
|
|
|
|
transition: all 0.2s;
|
|
transition: all 0.2s;
|
|
|
|
|
|
&:hover {
|
|
&:hover {
|
|
@@ -447,21 +452,36 @@ const showTime = computed(() => (item: KeFuMessageRespVO, index: number) => {
|
|
border-radius: 12rpx;
|
|
border-radius: 12rpx;
|
|
padding: 8rpx 16rpx;
|
|
padding: 8rpx 16rpx;
|
|
margin-bottom: 16rpx;
|
|
margin-bottom: 16rpx;
|
|
- //background-color: #e8e8e8;
|
|
|
|
color: #999;
|
|
color: #999;
|
|
font-size: 24rpx;
|
|
font-size: 24rpx;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- .chat-tools {
|
|
|
|
- width: 100%;
|
|
|
|
- border: var(--el-border-color) solid 1px;
|
|
|
|
- border-radius: 10px;
|
|
|
|
- height: 44px;
|
|
|
|
|
|
+ .kefu-footer {
|
|
|
|
+ display: flex;
|
|
|
|
+ flex-direction: column;
|
|
|
|
+ height: auto;
|
|
|
|
+ margin: 0;
|
|
|
|
+ padding: 0;
|
|
|
|
+ border-top: var(--el-border-color) solid 1px;
|
|
|
|
+
|
|
|
|
+ .chat-tools {
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 44px;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
::v-deep(textarea) {
|
|
::v-deep(textarea) {
|
|
resize: none;
|
|
resize: none;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ :deep(.el-input__wrapper) {
|
|
|
|
+ box-shadow: none !important;
|
|
|
|
+ border-radius: 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ::v-deep(.el-textarea__inner) {
|
|
|
|
+ box-shadow: none !important;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|