融合PK头像头像功能
This commit is contained in:
346
src/views/pk-mini/Message.vue
Normal file
346
src/views/pk-mini/Message.vue
Normal file
@@ -0,0 +1,346 @@
|
||||
<template>
|
||||
<!-- 消息页面 -->
|
||||
<div class="message-page">
|
||||
<el-splitter class="message-splitter">
|
||||
<!-- 会话列表 -->
|
||||
<el-splitter-panel :size="25" :min="20" :max="35">
|
||||
<div class="conversation-list">
|
||||
<div
|
||||
v-for="(item, index) in chatList"
|
||||
:key="index"
|
||||
class="conversation-item"
|
||||
:class="{ active: selectedChat === item }"
|
||||
@click="selectChat(item)"
|
||||
>
|
||||
<el-badge :value="item.unread > 0 ? item.unread : ''" :max="99">
|
||||
<div class="conv-avatar">
|
||||
<img :src="item.data?.avatar || defaultAvatar" alt="" />
|
||||
</div>
|
||||
</el-badge>
|
||||
<div class="conv-info">
|
||||
<div class="conv-header">
|
||||
<span class="conv-name">{{ item.data?.nickname || '用户' }}</span>
|
||||
<span class="conv-time">{{ formatTime(item.lastMessage?.timestamp) }}</span>
|
||||
</div>
|
||||
<div class="conv-preview">{{ item.lastMessage?.payload?.text || '' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="chatList.length === 0" class="empty-tip">暂无会话</div>
|
||||
</div>
|
||||
</el-splitter-panel>
|
||||
|
||||
<!-- 消息列表 -->
|
||||
<el-splitter-panel>
|
||||
<div v-if="selectedChat" class="chat-container">
|
||||
<div class="chat-messages" ref="chatMessagesRef">
|
||||
<div
|
||||
v-for="(msg, index) in messagesList"
|
||||
:key="index"
|
||||
class="message-item"
|
||||
:class="{ mine: msg.senderId == currentUser.id }"
|
||||
>
|
||||
<div class="message-avatar">
|
||||
<img :src="msg.senderId == currentUser.id ? currentUser.headerIcon : selectedChat.data?.avatar" alt="" />
|
||||
</div>
|
||||
<div class="message-bubble">
|
||||
<div v-if="msg.type === 'text'" class="text-message">{{ msg.payload.text }}</div>
|
||||
<PictureMessage v-else-if="msg.type === 'image'" :item="msg" />
|
||||
<PKMessage v-else-if="msg.type === 'pk'" :item="msg" />
|
||||
<VoiceMessage v-else-if="msg.type === 'audio'" :item="msg.payload.url" :size="msg.payload.duration" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="chat-input-area">
|
||||
<div class="input-toolbar">
|
||||
<div class="toolbar-btn" @click="handleSendImage">
|
||||
<span class="material-icons-round">image</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-box">
|
||||
<textarea
|
||||
v-model="inputText"
|
||||
placeholder="输入消息..."
|
||||
@keydown.enter.prevent="sendMessage"
|
||||
></textarea>
|
||||
<el-button type="primary" @click="sendMessage">发送</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="chat-placeholder">
|
||||
<span class="material-icons-round placeholder-icon">chat_bubble_outline</span>
|
||||
<p>选择左侧会话开始聊天</p>
|
||||
</div>
|
||||
</el-splitter-panel>
|
||||
</el-splitter>
|
||||
|
||||
<!-- 隐藏的文件输入 -->
|
||||
<input
|
||||
ref="fileInputRef"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
style="display: none"
|
||||
@change="handleFileSelect"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getMainUserData } from '@/utils/pk-mini/storage'
|
||||
import { TimestamptolocalTime } from '@/utils/pk-mini/timeConversion'
|
||||
// GoEasy 暂时禁用(订阅未续费)
|
||||
// import {
|
||||
// goEasyGetConversations,
|
||||
// goEasyGetMessages,
|
||||
// goEasySendMessage,
|
||||
// goEasySendImageMessage,
|
||||
// goEasyMessageRead,
|
||||
// getPkGoEasy
|
||||
// } from '@/utils/pk-mini/goeasy'
|
||||
// import GoEasy from 'goeasy'
|
||||
import PictureMessage from '@/components/pk-mini/chat/PictureMessage.vue'
|
||||
import PKMessage from '@/components/pk-mini/chat/PKMessage.vue'
|
||||
import VoiceMessage from '@/components/pk-mini/chat/VoiceMessage.vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const defaultAvatar = 'https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/default-avatar.png'
|
||||
const chatList = ref([])
|
||||
const selectedChat = ref(null)
|
||||
const messagesList = ref([])
|
||||
const inputText = ref('')
|
||||
const currentUser = ref({})
|
||||
const chatMessagesRef = ref(null)
|
||||
const fileInputRef = ref(null)
|
||||
|
||||
const formatTime = TimestamptolocalTime
|
||||
|
||||
async function loadConversations() {
|
||||
// GoEasy 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
}
|
||||
|
||||
async function selectChat(item) {
|
||||
// GoEasy 暂时禁用
|
||||
}
|
||||
|
||||
function scrollToBottom() {
|
||||
if (chatMessagesRef.value) {
|
||||
chatMessagesRef.value.scrollTop = chatMessagesRef.value.scrollHeight
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
// GoEasy 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
}
|
||||
|
||||
function handleSendImage() {
|
||||
// GoEasy 暂时禁用
|
||||
ElMessage.warning('消息功能暂时不可用(GoEasy 订阅未续费)')
|
||||
}
|
||||
|
||||
async function handleFileSelect(event) {
|
||||
event.target.value = ''
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
currentUser.value = getMainUserData() || {}
|
||||
// GoEasy 暂时禁用,不加载会话
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.message-page {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.message-splitter {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.conversation-list {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.conversation-item {
|
||||
display: flex;
|
||||
padding: 15px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.conversation-item:hover, .conversation-item.active {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.conv-avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.conv-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.conv-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.conv-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.conv-name {
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.conv-time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.conv-preview {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.chat-container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.chat-messages {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.message-item {
|
||||
display: flex;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.message-item.mine {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.message-avatar {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
margin: 0 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.message-avatar img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
max-width: 60%;
|
||||
}
|
||||
|
||||
.text-message {
|
||||
padding: 12px 16px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12px;
|
||||
font-size: 15px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.message-item.mine .text-message {
|
||||
background: #7bbd0093;
|
||||
}
|
||||
|
||||
.chat-input-area {
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.input-toolbar {
|
||||
display: flex;
|
||||
padding: 10px 15px;
|
||||
background: #e4f9f9;
|
||||
}
|
||||
|
||||
.toolbar-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.toolbar-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.toolbar-btn .material-icons-round {
|
||||
color: #03aba8;
|
||||
}
|
||||
|
||||
.input-box {
|
||||
display: flex;
|
||||
padding: 10px 15px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.input-box textarea {
|
||||
flex: 1;
|
||||
border: none;
|
||||
outline: none;
|
||||
resize: none;
|
||||
height: 50px;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.chat-placeholder {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #03aba8;
|
||||
}
|
||||
|
||||
.placeholder-icon {
|
||||
font-size: 80px;
|
||||
opacity: 0.3;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
padding: 50px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user