Commit 512e2191 by Sixong.Zhu

添加每条消息时间显示

parent 110d8a6a
Showing with 46 additions and 2 deletions
...@@ -9,7 +9,12 @@ ...@@ -9,7 +9,12 @@
}" }"
@mouseenter="hoverWithdraw" @mouseenter="hoverWithdraw"
> >
<div class="msg-content" :class="{ 'algin-left': !isMyMessage }"> <div
class="msg-content"
:class="{ 'algin-left': !isMyMessage }"
@mouseenter="onHover"
@mouseleave="onLeave"
>
<div <div
class="msg-name no-selection" class="msg-name no-selection"
:class="{ 'algin-left': !isMyMessage }" :class="{ 'algin-left': !isMyMessage }"
...@@ -85,6 +90,10 @@ ...@@ -85,6 +90,10 @@
/> />
</div> </div>
</div> </div>
<span v-if="showTs" class="ts" :class="{ right: isMyMessage }">{{
ts
}}</span>
</div> </div>
<i <i
...@@ -173,6 +182,7 @@ ...@@ -173,6 +182,7 @@
import Xim from "@/customer-service/xim"; import Xim from "@/customer-service/xim";
import { CustomerServiceEvent, MessageEvent } from "../event"; import { CustomerServiceEvent, MessageEvent } from "../event";
import { PayMessageBody } from "../xim/models/chat"; import { PayMessageBody } from "../xim/models/chat";
import { formatTime } from "../utils/time";
const oneDay = 24 * 60 * 60 * 1000; const oneDay = 24 * 60 * 60 * 1000;
...@@ -271,6 +281,12 @@ ...@@ -271,6 +281,12 @@
private defaultMessageHandledStatus = dto.MessageHandled.Default; private defaultMessageHandledStatus = dto.MessageHandled.Default;
private isWithdraw = true; private isWithdraw = true;
private showTs = false;
private showTsTimer = 0;
private get ts() {
return this.data && formatTime(this.data.ts);
}
private get isSystemMessage() { private get isSystemMessage() {
return ( return (
...@@ -622,6 +638,15 @@ ...@@ -622,6 +638,15 @@
}); });
} }
} }
private onHover() {
this.showTsTimer = setTimeout(() => (this.showTs = true), 600);
}
private onLeave() {
this.showTs = false;
clearTimeout(this.showTsTimer);
}
} }
</script> </script>
...@@ -790,6 +815,19 @@ ...@@ -790,6 +815,19 @@
} }
} }
} }
.ts {
position: absolute;
left: 40px;
bottom: 0;
font-size: 12px;
color: #999;
&.right {
right: 40px;
left: unset;
}
}
</style> </style>
<style lang="less"> <style lang="less">
......
...@@ -143,6 +143,11 @@ function formatTime2ShortYearMonthDate(time: Date) { ...@@ -143,6 +143,11 @@ function formatTime2ShortYearMonthDate(time: Date) {
)}/${formatWithTwoNumber(time.getDate())}`; )}/${formatWithTwoNumber(time.getDate())}`;
} }
interface FormatOption {
rule?: TimeFormatRule;
short?: boolean;
}
/** /**
* 格式化时间。 short模式下格式 * 格式化时间。 short模式下格式
* * 刚刚(1分钟内) [在short模式下不生效] * * 刚刚(1分钟内) [在short模式下不生效]
...@@ -157,7 +162,7 @@ function formatTime2ShortYearMonthDate(time: Date) { ...@@ -157,7 +162,7 @@ function formatTime2ShortYearMonthDate(time: Date) {
*/ */
export function formatTime( export function formatTime(
time: number | string, time: number | string,
option = { rule: TimeFormatRule.Hour12, short: false } option: FormatOption = { rule: TimeFormatRule.Hour12, short: false }
) { ) {
if (String(time).indexOf("-")) { if (String(time).indexOf("-")) {
time = String(time).replace(/-/g, "/"); time = String(time).replace(/-/g, "/");
...@@ -216,6 +221,7 @@ export function formatTime( ...@@ -216,6 +221,7 @@ export function formatTime(
if (option.short) { if (option.short) {
return formatTime2ShortYearMonthDate(t); return formatTime2ShortYearMonthDate(t);
} }
return ( return (
formatTime2YearMonthDate(t) + formatTime2YearMonthDate(t) +
" " + " " +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment