You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
8.6 KiB

3 years ago
<template>
<div class="chat-msg-item">
<div class="chat-msg-tip" v-show="msgInfo.type==$enums.MESSAGE_TYPE.RECALL">{{msgInfo.content}}</div>
2 years ago
<div class="chat-msg-tip" v-show="msgInfo.type==$enums.MESSAGE_TYPE.TIP_TIME">{{$date.toTimeText(msgInfo.sendTime)}}</div>
<div class="chat-msg-normal" v-show="msgInfo.type>=0 && msgInfo.type<10" :class="{'chat-msg-mine':mine}">
3 years ago
<div class="head-image">
2 years ago
<head-image :name="showName" :size="40" :url="headImage" :id="msgInfo.sendId"></head-image>
3 years ago
</div>
<div class="chat-msg-content">
2 years ago
<div v-show="mode==1 && msgInfo.groupId && !msgInfo.selfSend" class="chat-msg-top">
<span>{{showName}}</span>
</div>
<div v-show="mode==2" class="chat-msg-top">
3 years ago
<span>{{showName}}</span>
2 years ago
<span>{{$date.toTimeText(msgInfo.sendTime)}}</span>
3 years ago
</div>
<div class="chat-msg-bottom" @contextmenu.prevent="showRightMenu($event)">
<span class="chat-msg-text" v-if="msgInfo.type==$enums.MESSAGE_TYPE.TEXT"
v-html="$emo.transform(msgInfo.content)"></span>
<div class="chat-msg-image" v-if="msgInfo.type==$enums.MESSAGE_TYPE.IMAGE">
<div class="img-load-box" v-loading="loading" element-loading-text="上传中.."
element-loading-background="rgba(0, 0, 0, 0.4)">
<img class="send-image" :src="JSON.parse(msgInfo.content).thumbUrl"
@click="showFullImageBox()" />
3 years ago
</div>
<span title="发送失败" v-show="loadFail" @click="handleSendFail"
class="send-fail el-icon-warning"></span>
3 years ago
</div>
<div class="chat-msg-file" v-if="msgInfo.type==$enums.MESSAGE_TYPE.FILE">
3 years ago
<div class="chat-file-box" v-loading="loading">
<div class="chat-file-info">
<el-link class="chat-file-name" :underline="true" target="_blank" type="primary"
:href="data.url">{{data.name}}</el-link>
3 years ago
<div class="chat-file-size">{{fileSize}}</div>
</div>
<div class="chat-file-icon">
<span type="primary" class="el-icon-document"></span>
</div>
</div>
<span title="发送失败" v-show="loadFail" @click="handleSendFail"
class="send-fail el-icon-warning"></span>
3 years ago
</div>
<div class="chat-msg-voice" v-if="msgInfo.type==$enums.MESSAGE_TYPE.AUDIO"
@click="handlePlayVoice()">
3 years ago
<audio controls :src="JSON.parse(msgInfo.content).url"></audio>
</div>
</div>
</div>
3 years ago
</div>
<right-menu v-show="menu && rightMenu.show" :pos="rightMenu.pos" :items="menuItems"
@close="rightMenu.show=false" @select="handleSelectMenu"></right-menu>
3 years ago
</div>
</template>
<script>
import HeadImage from "../common/HeadImage.vue";
import RightMenu from '../common/RightMenu.vue';
export default {
name: "messageItem",
components: {
HeadImage,
RightMenu
},
props: {
2 years ago
mode:{
type: Number,
default :1
},
3 years ago
mine: {
type: Boolean,
required: true
},
headImage: {
type: String,
required: true
},
showName: {
type: String,
required: true
},
msgInfo: {
type: Object,
required: true
},
menu: {
3 years ago
type: Boolean,
default: true
}
},
data() {
return {
audioPlayState: 'STOP',
rightMenu: {
show: false,
pos: {
x: 0,
y: 0
}
}
}
},
methods: {
handleSendFail() {
this.$message.error("该文件已发送失败,目前不支持自动重新发送,建议手动重新发送")
},
showFullImageBox() {
let imageUrl = JSON.parse(this.msgInfo.content).originUrl;
if (imageUrl) {
this.$store.commit('showFullImageBox', imageUrl);
}
},
handlePlayVoice() {
if (!this.audio) {
this.audio = new Audio();
}
this.audio.src = JSON.parse(this.msgInfo.content).url;
this.audio.play();
this.handlePlayVoice = 'RUNNING';
},
showRightMenu(e) {
this.rightMenu.pos = {
x: e.x,
y: e.y
};
this.rightMenu.show = "true";
},
handleSelectMenu(item) {
this.$emit(item.key.toLowerCase(), this.msgInfo);
}
},
computed: {
loading() {
return this.msgInfo.loadStatus && this.msgInfo.loadStatus === "loading";
},
loadFail() {
return this.msgInfo.loadStatus && this.msgInfo.loadStatus === "fail";
},
data() {
return JSON.parse(this.msgInfo.content)
},
fileSize() {
let size = this.data.size;
if (size > 1024 * 1024) {
return Math.round(size / 1024 / 1024) + "M";
}
if (size > 1024) {
return Math.round(size / 1024) + "KB";
}
return size + "B";
},
menuItems() {
let items = [];
items.push({
key: 'DELETE',
name: '删除',
icon: 'el-icon-delete'
});
if (this.msgInfo.selfSend && this.msgInfo.id > 0) {
items.push({
key: 'RECALL',
name: '撤回',
icon: 'el-icon-refresh-left'
});
}
return items;
}
},
mounted() {
2 years ago
console.log(this.msgInfo);
3 years ago
}
}
</script>
2 years ago
<style scoped lang="scss">
3 years ago
.chat-msg-item {
.chat-msg-tip {
line-height: 50px;
2 years ago
font-size: 14px;
3 years ago
}
.chat-msg-normal {
position: relative;
font-size: 0;
padding-left: 60px;
2 years ago
min-height: 50px;
margin-top: 10px;
3 years ago
.head-image {
position: absolute;
width: 40px;
height: 40px;
top: 0;
left: 0;
}
.chat-msg-content {
text-align: left;
2 years ago
3 years ago
.chat-msg-top {
display: flex;
flex-wrap: nowrap;
color: #333;
font-size: 14px;
line-height: 20px;
span {
margin-right: 12px;
}
}
.chat-msg-bottom {
display: inline-block;
padding-right: 80px;
3 years ago
.chat-msg-text {
display: block;
3 years ago
position: relative;
2 years ago
line-height: 30px;
margin-top: 3px;
padding: 7px;
2 years ago
background-color: rgb(235,235,245);
border-radius: 10px;
color: black;
display: block;
2 years ago
font-size: 16px;
text-align: left;
white-space: pre-wrap;
word-break: break-all;
2 years ago
box-shadow: 2px 2px 2px #c0c0f0;
3 years ago
&:after {
content: "";
position: absolute;
left: -10px;
top: 13px;
width: 0;
height: 0;
border-style: solid dashed dashed;
2 years ago
border-color: rgb(235,235,245) transparent transparent;
3 years ago
overflow: hidden;
2 years ago
border-width: 10px;
3 years ago
}
}
.chat-msg-image {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
align-items: center;
.send-image {
2 years ago
min-width: 200px;
min-height: 150px;
max-width: 400px;
max-height: 300px;
3 years ago
border: #dddddd solid 1px;
2 years ago
border: 5px solid #ccc;
2 years ago
border-radius: 6px;
3 years ago
cursor: pointer;
}
2 years ago
c
3 years ago
.send-fail {
color: #e60c0c;
font-size: 30px;
cursor: pointer;
margin: 0 20px;
}
}
.chat-msg-file {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
align-items: center;
cursor: pointer;
.chat-file-box {
display: flex;
flex-wrap: nowrap;
align-items: center;
min-height: 80px;
2 years ago
box-shadow: 5px 5px 2px #c0c0c0;
3 years ago
border: #dddddd solid 1px;
2 years ago
border-radius: 6px;
3 years ago
background-color: #eeeeee;
padding: 10px 15px;
.chat-file-info {
flex: 1;
height: 100%;
text-align: left;
font-size: 14px;
.chat-file-name {
2 years ago
display: inline-block;
min-width: 150px;
max-width: 300px;
3 years ago
font-size: 16px;
font-weight: 600;
margin-bottom: 15px;
2 years ago
white-space: pre-wrap;
word-break: break-all;
3 years ago
}
}
.chat-file-icon {
font-size: 50px;
color: #d42e07;
}
}
.send-fail {
color: #e60c0c;
font-size: 30px;
cursor: pointer;
margin: 0 20px;
}
}
.chat-msg-voice {
font-size: 14px;
cursor: pointer;
audio {
height: 45px;
padding: 5px 0;
}
}
}
}
&.chat-msg-mine {
text-align: right;
padding-left: 0;
padding-right: 60px;
.head-image {
left: auto;
right: 0;
}
.chat-msg-content {
text-align: right;
3 years ago
.chat-msg-top {
flex-direction: row-reverse;
span {
margin-left: 12px;
margin-right: 0;
}
}
.chat-msg-bottom {
padding-left: 80px;
padding-right: 0;
3 years ago
.chat-msg-text {
margin-left: 10px;
2 years ago
background-color: rgb(88, 127, 240);
3 years ago
color: #fff;
vertical-align: top;
2 years ago
box-shadow: 2px 2px 1px #ccc;
3 years ago
&:after {
left: auto;
right: -10px;
2 years ago
border-top-color: rgb(88, 127, 240);
3 years ago
}
}
.chat-msg-image {
flex-direction: row-reverse;
}
.chat-msg-file {
flex-direction: row-reverse;
}
}
}
}
}
}
</style>