
<template>
<div class="lick-container" @keyup.enter="sendMessage">
<div class="chat-content-container">
<div class="header">联通</div>
<div class="body" ref="msgBody">
<div
class="message"
v-for="(message, index) in messageList"
:key="index"
:class="{ self: message.type === 'self' }"
>
<div class="avatar"></div>
<div class="trangle"></div>
<div class="content">{{ message.content }}</div>
</div>
</div>
</div>
<div class="type-container">
<input class="type-input" v-model="keyWord" />
<div class="send-btn" @click="sendMessage">发送</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
keyWord: "",
messageList: [
{ type: "oppsite", content: "测试1" },
{ type: "oppsite", content: "测试2!" },
],
simpWordList: [
"测试...",
"测试...",
"测试...",
"测试...",
"测试...",
"测试...",
"测试...",
],
};
},
methods: {
addReply() {
const { simpWordList } = this;
const length = simpWordList.length;
const index = Math.floor(Math.random() * length);
this.messageList.push({ type: "oppsite", content: simpWordList[index] });
this.$nextTick(() => {
this.$refs.msgBody.scrollTop = this.$refs.msgBody.scrollHeight;
});
},
sendMessage() {
if (this.keyWord === "") {
return;
}
this.messageList.push({ type: "self", content: this.keyWord });
this.addReply();
this.keyWord = "";
},
},
};
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.br-10px {
border-radius: 10px;
}
.lick-container {
height: 100%;
margin: 0 auto;
}
.chat-content-container {
.header {
width: 100%;
height: 79px;
background: #ededed;
border-bottom: 3px solid #e9e9e9;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
}
.body {
width: 100%;
height: calc(100vh - 158px);
overflow: auto;
&::-webkit-scrollbar {
width: 0 !important;
}
background: #ededed;
padding-top: 10px;
.message {
display: flex;
align-items: center;
margin-bottom: 10px;
margin-left: 15px;
&.self {
flex-direction: row-reverse;
margin-left: auto;
margin-right: 15px;
.trangle {
border: none;
border-top: 12.5px solid transparent;
border-left: 12.5px solid rgb(149, 236, 105);
border-bottom: 12.5px solid transparent;
margin-left: 0;
margin-right: 20px;
}
.content {
background: rgb(149, 236, 105);
}
.avatar {
&::before {
content: "B";
top: 50%;
color: #fff;
font-size: 30px;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
}
}
.avatar {
width: 75px;
height: 75px;
position: relative;
background: #25e465;
background-size: cover;
border-radius: 10px;
text-align: center;
box-shadow: 1px 3px 4px 1px rgba(0, 0, 0, 0.5);
&::before {
content: "C";
top: 50%;
color: #fff;
font-size: 30px;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
}
.trangle {
width: 0;
height: 0;
border-right: 12.5px solid #fff;
border-bottom: 12.5px solid transparent;
border-top: 12.5px solid transparent;
margin-left: 20px;
}
.content {
min-height: 75px;
max-width: 505px;
display: flex;
align-items: center;
font-size: 30px;
padding: 20px 20px;
background: #fff;
border-radius: 10px;
}
}
}
}
.type-container {
width: 100%;
height: 79px;
background: #ededed;
border-top: 3px solid #e9e9e9;
display: flex;
align-items: center;
justify-content: space-evenly;
.type-input {
border: none;
width: 75%;
height: 59px;
font-size: 30px;
border-radius: 10px;
outline: none;
text-indent: 30px;
}
.send-btn {
background: rgb(80, 236, 105);
width: 15%;
height: 59px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
color: #fff;
cursor: pointer;
}
}
</style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探