在线客服页面:
<template>
<view class="container">
<view class="chatroom">
<view class="message" v-for="(message, index) in messages" :key="index">
<view v-if="message.type == 'customer'" class="customer-message">{{ message.content }}</view>
<view v-else class="agent-message">{{ message.content }}</view>
</view>
</view>
<view class="input-container">
<input class="input-message" placeholder="请输入您的问题" @confirm="sendMessage" v-model="messageInput"></input>
<view class="send-button" @click="sendMessage">发送</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
messages: [],
messageInput: ""
};
},
methods: {
sendMessage() {
if (this.messageInput == "") {
return;
}
this.messages.push({
type: "customer",
content: this.messageInput
});
this.messageInput = "";
// 模拟客服回复
setTimeout(() => {
this.messages.push({
type: "agent",
content: "您好,有什么可以帮助您的呢?"
});
}, 1000);
}
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
height: 100vh;
padding: 20px;
}
.chatroom {
flex-grow: 1;
overflow-y: auto;
}
.message {
margin-bottom: 10px;
}
.customer-message {
background-color: #eee;
padding: 6px 10px;
border-radius: 10px;
max-width: 60%;
align-self: flex-start;
}
.agent-message {
background-color: #007aff;
color: #fff;
padding: 6px 10px;
border-radius: 10px;
max-width: 60%;
align-self: flex-end;
}
.input-container {
display: flex;
margin-top: 20px;
}
.input-message {
flex-grow: 1;
padding: 10px;
border-radius: 10px;
border: 1px solid #eee;
}
.send-button {
background-color: #007aff;
color: #fff;
padding: 10px;
border-radius: 10px;
margin-left: 10px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
</style>
这是一个简单的在线客服页面,由一个聊天窗口和一个输入框组成。用户输入问题后,点击发送按钮或者按下回车键,问题将会发送给客服。客服在一定时间(这里是1秒)后会模拟回复一条消息,这条消息会显示在聊天窗口中。