Files
chatai/src/components/chatContent.vue

202 lines
4.2 KiB
Vue
Raw Normal View History

2023-05-12 15:53:39 +08:00
<template>
2023-06-01 17:12:10 +08:00
<section class="chatContent">
2023-05-12 15:53:39 +08:00
<div class="chat-wrapper" v-for="item in list" :key="item.id">
2023-05-12 17:32:54 +08:00
<div class="chat-friend" v-if="item.uid !== 'me'">
2023-05-12 15:53:39 +08:00
<div class="chat-text" v-if="item.chatType == 0">
2023-05-12 18:04:58 +08:00
<icon-copy @click="copy(item.msg, '已复制')"/>
2023-05-18 15:20:29 +08:00
<v-md-preview :text="item.msg.trim()"/>
2023-05-12 15:53:39 +08:00
</div>
<div class="chat-img" v-if="item.chatType == 1">
<img :src="item.msg" alt="表情" v-if="item.extend.imgType == 1" style="width: 100px; height: 100px"/>
2023-05-12 18:04:58 +08:00
<el-image style="border-radius: 10px" :src="item.msg" :preview-src-list="srcImgList" v-else/>
2023-05-12 15:53:39 +08:00
</div>
<div class="info-time">
2023-05-12 18:04:58 +08:00
<img :src="item.avatar" alt=""/>
2023-05-12 15:53:39 +08:00
<span>{{ item.name }}</span>
<span>{{ item.time }}</span>
</div>
</div>
<div class="chat-me" v-else>
<div class="chat-text" v-if="item.chatType == 0">
2023-05-15 17:05:36 +08:00
<icon-copy @click="copy(item.msg, '已复制')"/>
2023-05-12 17:32:54 +08:00
<span v-text="item.msg"/>
2023-05-12 15:53:39 +08:00
</div>
<div class="info-time">
<span>{{ item.name }}</span>
<span>{{ item.time }}</span>
2023-05-12 18:04:58 +08:00
<img :src="item.avatar" alt=""/>
2023-05-12 15:53:39 +08:00
</div>
</div>
</div>
</section>
</template>
<script>
2023-05-12 17:32:54 +08:00
import IconCopy from "../icons/iconCopy";
2023-05-12 18:12:21 +08:00
import {copyToClipboard} from "../utils/tools";
2023-05-12 17:32:54 +08:00
2023-05-12 15:53:39 +08:00
export default {
name: "chatContent",
2023-05-12 17:32:54 +08:00
components: {IconCopy},
props: {
list: {default: () => []}
2023-05-12 15:53:39 +08:00
},
2023-06-01 17:12:10 +08:00
watch: {
list: {
deep: true, handler() {
this.scrollBottom()
}
2023-05-18 15:20:29 +08:00
}
},
2023-05-12 15:53:39 +08:00
methods: {
2023-05-18 15:38:25 +08:00
scrollBottom() {
this.$el.scrollTop = this.$el.scrollHeight - this.$el.clientHeight
},
2023-05-12 18:04:58 +08:00
copy(msg) {
if (copyToClipboard(msg)) {
this.$message.success("已复制")
}
}
2023-05-12 15:53:39 +08:00
}
}
</script>
<style lang="scss" scoped>
.chatContent {
background: #323644;
border-radius: 4px;
padding: 16px;
box-sizing: border-box;
overflow-y: auto;
2023-05-12 17:32:54 +08:00
&::-webkit-scrollbar {
width: 3px;
/* 设置滚动条宽度 */
}
&::-webkit-scrollbar-thumb {
background-color: rgb(66, 70, 86);
/* 设置滚动条滑块的背景色 */
border-radius: 50%;
/* 设置滑块的圆角 */
}
.chat-friend {
width: 100%;
float: left;
margin-bottom: 20px;
position: relative;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-start;
.chat-text {
float: left;
padding: 15px;
max-width: max(650px, 90%);
border-radius: 4px;
background-color: #fff;
2023-05-18 15:20:29 +08:00
color: initial;
2023-05-12 17:32:54 +08:00
}
.chat-img {
img {
max-width: 300px;
max-height: 200px;
border-radius: 4px;
}
}
.info-time {
margin: 10px 0;
color: #fff;
font-size: 14px;
display: flex;
justify-content: flex-start;
img {
width: 30px;
height: 30px;
border-radius: 50%;
vertical-align: middle;
margin-right: 10px;
}
span {
line-height: 30px;
}
span:last-child {
color: rgb(101, 104, 115);
margin-left: 10px;
vertical-align: middle;
}
}
}
.chat-me {
width: 100%;
float: right;
margin-bottom: 20px;
position: relative;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-end;
.chat-text {
float: right;
max-width: 90%;
padding: 15px;
border-radius: 4px;
background-color: #95ec69;
color: #000;
word-break: break-all;
}
.chat-img {
img {
max-width: 300px;
max-height: 200px;
border-radius: 4px;
}
}
.info-time {
margin: 10px 0;
color: #fff;
font-size: 14px;
display: flex;
justify-content: flex-end;
img {
width: 30px;
height: 30px;
border-radius: 50%;
vertical-align: middle;
margin-left: 10px;
}
span {
line-height: 30px;
}
span:first-child {
color: rgb(101, 104, 115);
margin-right: 10px;
vertical-align: middle;
}
}
}
2023-05-15 01:24:18 +08:00
2023-05-18 15:20:29 +08:00
:deep(.github-markdown-body) {
2023-05-15 01:24:18 +08:00
padding: 2px 0 !important;
2023-05-18 15:20:29 +08:00
p {
margin-bottom: 0;
}
2023-05-15 01:24:18 +08:00
}
2023-05-12 15:53:39 +08:00
}
</style>