mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-16 14:12:51 +00:00
81 lines
2.1 KiB
Vue
81 lines
2.1 KiB
Vue
<template>
|
|
<div class="message-view">
|
|
|
|
<div v-if="msgData.type == 'text'" class="message-content" v-html="textMsg(msgData.msg.text)"></div>
|
|
<div v-else class="message-content message-unknown">{{$L("未知的消息类型")}}</div>
|
|
|
|
<div v-if="msgData.created_at" class="message-foot">
|
|
<div class="time">{{formatTime(msgData.created_at)}}</div>
|
|
<Icon v-if="msgData.read" class="done-all" type="md-done-all" />
|
|
<Icon v-else class="done" type="md-checkmark" />
|
|
</div>
|
|
<div v-else class="message-foot"><Loading/></div>
|
|
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import {mapState} from "vuex";
|
|
|
|
export default {
|
|
name: "MessageView",
|
|
props: {
|
|
msgData: {
|
|
type: Object,
|
|
default: () => {
|
|
return {};
|
|
}
|
|
},
|
|
},
|
|
|
|
mounted() {
|
|
this.readMarking()
|
|
},
|
|
|
|
computed: {
|
|
...mapState(['userId']),
|
|
},
|
|
|
|
watch: {
|
|
msgData() {
|
|
this.readMarking()
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
readMarking() {
|
|
if (this.msgData.read === 0 && this.msgData.userid != this.userId) {
|
|
this.$store.commit('wsSend', {
|
|
type: 'readMsg',
|
|
data: {
|
|
id: this.msgData.id
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
formatTime(date) {
|
|
let time = Math.round(new Date(date).getTime() / 1000),
|
|
string = '';
|
|
if ($A.formatDate('Ymd') === $A.formatDate('Ymd', time)) {
|
|
string = $A.formatDate('H:i', time)
|
|
} else if ($A.formatDate('Y') === $A.formatDate('Y', time)) {
|
|
string = $A.formatDate('m-d', time)
|
|
} else {
|
|
string = $A.formatDate('Y-m-d', time)
|
|
}
|
|
return string || '';
|
|
},
|
|
|
|
textMsg(text) {
|
|
if (!text) {
|
|
return ""
|
|
}
|
|
text = text.trim().replace(/(\n\x20*){3,}/g, "<br/><br/>");
|
|
text = text.trim().replace(/\n/g, "<br/>");
|
|
return text;
|
|
}
|
|
}
|
|
}
|
|
</script>
|