mirror of
https://gitee.com/lijingbo-2021/open-anylink-web.git
synced 2025-12-30 11:02:25 +00:00
如果是连续时间,则中间位置只显示第一个时间
This commit is contained in:
@@ -5,7 +5,7 @@ import { userStore } from '@/stores'
|
||||
import { messageSysShowTime, messageBoxShowTime } from '@/utils/common'
|
||||
import AvatarIcon from './AvatarIcon.vue'
|
||||
|
||||
const props = defineProps(['obj'])
|
||||
const props = defineProps(['obj', 'lastMsgTime'])
|
||||
|
||||
const userData = userStore()
|
||||
const isShowUserCard = ref(false)
|
||||
@@ -14,14 +14,27 @@ const isSelf = computed(() => {
|
||||
return userData.user.account === props.obj.user.account
|
||||
})
|
||||
|
||||
const showTime = computed(() => {
|
||||
const now = new Date()
|
||||
const oneDayAgo = new Date(now.getTime() - 4 * 24 * 60 * 60 * 1000)
|
||||
return messageSysShowTime(oneDayAgo)
|
||||
const sysShowTime = computed(() => {
|
||||
const testTime = new Date(props.obj.msgTime - 0 * 24 * 60 * 60 * 1000)
|
||||
return messageSysShowTime(testTime)
|
||||
})
|
||||
|
||||
// 判断是否是连续的会话,与上个会话时间差小于1分钟
|
||||
const isContinuousSession = computed(() => {
|
||||
if (!props.lastMsgTime) {
|
||||
return false
|
||||
}
|
||||
|
||||
const diff = props.obj.msgTime.getTime() - props.lastMsgTime.getTime()
|
||||
if (diff < 1 * 60 * 1000) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
const msgTime = computed(() => {
|
||||
return messageBoxShowTime(props.obj.time)
|
||||
return messageBoxShowTime(props.obj.msgTime)
|
||||
})
|
||||
|
||||
const handleUserCard = (flag) => {
|
||||
@@ -35,7 +48,7 @@ const onShowUserCard = () => {
|
||||
|
||||
<template>
|
||||
<div v-if="props.obj.type === msgType.USER_MSG" class="user-message">
|
||||
<span class="datetime">{{ showTime }}</span>
|
||||
<span v-if="!isContinuousSession" class="datetime">{{ sysShowTime }}</span>
|
||||
<div class="message-container-wrapper">
|
||||
<el-container class="el-container-right" v-if="isSelf">
|
||||
<el-main class="el-main-right">
|
||||
|
||||
@@ -84,6 +84,16 @@ const showId = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
const getLastMsgTime = (index) => {
|
||||
if (index > 0) {
|
||||
console.log(testdata.value[index - 1].content);
|
||||
return testdata.value[index - 1].msgTime;
|
||||
} else {
|
||||
console.log('null');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const onAsideDragUpdate = ({ width }) => {
|
||||
asideWidth.value = width
|
||||
settingData.setSessionListDrag({
|
||||
@@ -116,26 +126,26 @@ const onLoadMore = () => {
|
||||
}
|
||||
|
||||
const testdata = ref([
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你好呀' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我很好' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你是谁啊?' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我是bob呀' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你好呀' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我很好' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你是谁啊?' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我是bob呀' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你好呀' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我很好' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你是谁啊?' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我是bob呀' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你好呀' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我很好' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你是谁啊?' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我是bob呀' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你好呀' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我很好' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, time: new Date(), content: '你是谁啊?' },
|
||||
{user: userData.user, type: msgType.USER_MSG, time: new Date(), content: '我是bob呀' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '1' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '2' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '3' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '4' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '5' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '6' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '7' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '8' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '9' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '10' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '11' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '12' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '13' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '14' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '15' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '16' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '17' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '18' },
|
||||
{user: {account:'a00001', nickName: '甘道夫', avatarThumb: ''}, type: msgType.USER_MSG, msgTime: new Date(), content: '19' },
|
||||
{user: userData.user, type: msgType.USER_MSG, msgTime: new Date(), content: '20' },
|
||||
])
|
||||
|
||||
</script>
|
||||
@@ -208,7 +218,12 @@ const testdata = ref([
|
||||
</div>
|
||||
<div class="message-main">
|
||||
<span class="no-more-message">当前无更多消息</span>
|
||||
<MessageItem v-for="(item, index) in testdata" :key="index" :obj="item"></MessageItem>
|
||||
<MessageItem
|
||||
v-for="(item, index) in testdata"
|
||||
:key="index"
|
||||
:obj="item"
|
||||
:lastMsgTime="getLastMsgTime(index)"
|
||||
></MessageItem>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-box bdr-t" :style="{ height: inputBoxHeight + 'px' }">
|
||||
|
||||
Reference in New Issue
Block a user