图片发送、视频发送(写死的)

This commit is contained in:
2025-06-26 17:02:03 +08:00
parent 3902738d7f
commit ca9d71145d
2 changed files with 565 additions and 600 deletions

View File

@@ -10,6 +10,7 @@
<!-- 添加 Vue.js CDN -->
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script>
<style>
/* 原有样式保持不变 */
:root {
--bg-dark: #121212;
--bg-darker: #0a0a0a;
@@ -463,10 +464,54 @@
50% { transform: scale(1.1); box-shadow: 0 0 10px var(--accent); }
100% { transform: scale(1); }
}
/* 新增样式:媒体消息样式 */
.media-message {
max-width: 300px;
margin: 5px 0;
border-radius: 8px;
overflow: hidden;
}
.media-message img {
max-width: 100%;
max-height: 300px;
display: block;
border-radius: 8px;
}
.media-message video {
max-width: 100%;
max-height: 300px;
display: block;
border-radius: 8px;
}
.upload-indicator {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 16px;
background: rgba(30, 30, 30, 0.8);
border-radius: 20px;
position: fixed;
top: 70px;
left: 50%;
transform: translateX(-50%);
z-index: 100;
backdrop-filter: blur(10px);
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<div id="app">
<!-- 上传状态指示器 -->
<div class="upload-indicator" v-if="uploadStatus.show">
<i :class="uploadStatus.icon" :style="{ color: uploadStatus.color }"></i>
<span>@{{ uploadStatus.message }}</span>
</div>
<!-- 连接状态提示 -->
<div class="connection-status">
<div class="status-indicator" :class="connectionStatus"></div>
@@ -532,7 +577,20 @@
<div class="message-body">
<div class="message-name">@{{ msg.name }}</div>
<div class="message-bubble">
<div class="message-content">@{{ msg.text }}</div>
<!-- 文本消息 -->
<div class="message-content" v-if="msg.messageType === 'text'">
@{{ msg.text }}
</div>
<!-- 图片消息 -->
<div class="media-message" v-else-if="msg.messageType === 'image'">
<img :src="msg.text" alt="Image">
</div>
<!-- 视频消息 -->
<div class="media-message" v-else-if="msg.messageType === 'video'">
<video :src="msg.text" controls></video>
</div>
</div>
<div class="message-info">
<span class="timestamp">@{{ formatTime(msg.timestamp) }}</span>
@@ -581,20 +639,20 @@
<script>
// 常见的emoji
const EMOJIS = [
'😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣',
'😊', '😇', '🙂', '🙃', '😉', '😌', '😍', '🥰',
'😘', '😗', '😋', '😛', '😜', '🤪', '😝', '🤑',
'🤗', '🤭', '🤫', '🤔', '🤐', '🤨', '😐', '😑',
'😶', '😏', '😒', '🙄', '😬', '🤥', '😲', '😮',
'😦', '😧', '😳', '😵', '😖', '😫', '😩', '🥺',
'😢', '😭', '😤', '😠', '😡', '🤬', '🤯', '😳',
'🥵', '🥶', '😨', '😰', '😥', '😓', '🤗', '🤔',
'🫣', '🤭', '🤫', '🫢', '🫠', '😶‍🌫️', '😐', '😑',
'🙈', '🙉', '🙊', '❤️', '💛', '💚', '💙', '💜',
'💔', '💋', '💯', '💢', '💥', '💫', '💦', '💨',
'👍', '👎', '👌', '✌️', '🤞', '🤟', '🤘', '🤙',
'👋', '🤚', '🖐️', '✋', '🖖', '👏', '🙌', '👐',
'🤲', '🤝', '🙏', '💪', '🦾', '🦿', '🦵', '🦶'
'😀😀', '😃😃', '😄😄', '😁😁', '😆😆', '😅😅', '😂', '🤣🤣',
'😊😊', '😇😇', '🙂🙂', '🙃🙃', '😉😉', '😌😌', '😍😍', '🥰🥰',
'😘😘', '😗😗', '😋😋', '😛😛', '😜😜', '🤪🤪', '😝😝', '🤑🤑',
'🤗🤗', '🤭🤭', '🤫🤫', '🤔🤔', '🤐🤐', '🤨🤨', '😐😐', '😑😑',
'😶😶', '😏😏', '😒😒', '🙄🙄', '😬😬', '🤥🤥', '😲😲', '😮😮',
'😦😦', '😧😧', '😳😳', '😵😵', '😖😖', '😫😫', '😩😩', '🥺🥺',
'😢😢', '😭😭', '😤😤', '😠😠', '😡😡', '🤬🤬', '🤯🤯', '😳😳',
'🥵🥵', '🥶🥶', '😨😨', '😰😰', '😥😥', '😓😓', '🤗🤗', '🤔🤔',
'🫣🫣🫣', '🤭🤭', '🤫🤫', '🫢🫢🫢', '🫠🫠🫠', '😶😶‍🌫🌫', '😐😐', '😑😑',
'🙈🙈', '🙉🙉', '🙊🙊', '❤️', '💛💛', '💚💚', '💙💙', '💜💜',
'💔💔', '💋💋', '💯💯', '💢💢', '💥💥', '💫💫', '💦💦', '💨💨',
'👍', '👎👎', '👌👌', '✌', '🤞🤞', '🤟🤟', '🤘🤘', '🤙🤙',
'👋👋', '🤚🤚', '🖐🖐🖐', '✋', '🖖🖖🖖', '👏👏', '🙌🙌', '👐👐',
'🤲🤲', '🤝🤝', '🙏🙏', '💪💪', '🦾🦾🦾', '🦿🦿🦿', '🦵🦵🦵', '🦶🦶🦶'
];
// 头像颜色
@@ -603,6 +661,10 @@
'#60a5fa', '#c084fc', '#fb923c', '#34d399'
];
// 模拟上传的媒体URL
const MOCK_IMAGE_URL = 'http://d-jy.nailaoyun.cn/storage/image//20250509/e2e107d3776542eea1c454d84e9bff0c.png';
const MOCK_VIDEO_URL = 'http://d-jy.nailaoyun.cn/storage/video//20250327/2cc1abf9bd69410ce7c69660daf54260.mp4';
new Vue({
el: '#app',
data: {
@@ -623,7 +685,13 @@
socket: null,
statusText: '未连接',
connectionStatus: '',
serverUrl: "{{ config('gateway.ws_address') }}"
serverUrl: "{{ config('gateway.ws_address') }}",
uploadStatus: {
show: false,
message: '',
icon: '',
color: '#ffffff'
}
},
created() {
this.token = sessionStorage.getItem('token');
@@ -648,8 +716,6 @@
this.currentUser.name = userData.name;
// 为用户生成头像颜色
// const colorIndex = Math.floor(Math.random() * AVATAR_COLORS.length);
// this.currentUser.avatarColor = AVATAR_COLORS[colorIndex];
this.currentUser.avatarColor = userData.avatarColor;
},
connectWebSocket() {
@@ -702,7 +768,8 @@
avatarColor: message.avatarColor,
text: message.content,
timestamp: new Date(message.timestamp),
type: message.userId === this.currentUser.id ? 'sent' : 'received'
type: message.userId === this.currentUser.id ? 'sent' : 'received',
messageType: 'text' // 默认文本类型
});
break;
case 'user_list':
@@ -734,7 +801,8 @@
userName: this.currentUser.name,
avatarColor: this.currentUser.avatarColor,
content: text,
timestamp: Date.now()
timestamp: Date.now(),
messageType: 'text' // 文本消息
};
let token = sessionStorage.getItem('token');
@@ -762,7 +830,8 @@
avatarColor: this.currentUser.avatarColor,
text: text,
timestamp: new Date(),
type: 'sent'
type: 'sent',
messageType: 'text'
});
// 清空输入框
this.messageInput = '';
@@ -880,19 +949,77 @@
name: item.nick_name,
avatarColor: item.avatar,
text: item.content,
// timestamp: new Date(item.timestamp),
timestamp: item.timestamp,
type: item.type
type: item.type,
messageType: 'text' // 默认为文本类型
});
});
}
})
},
showImageUpload() {
this.addSystemMessage("图片上传功能(实际应用中需要实现上传功能)");
// 显示图片上传状态
showUploadStatus(message, icon, color) {
this.uploadStatus = {
show: true,
message: message,
icon: icon,
color: color
};
// 3秒后自动隐藏
setTimeout(() => {
this.uploadStatus.show = false;
}, 3000);
},
// 模拟图片上传功能
showImageUpload() {
// 显示上传状态
this.showUploadStatus('图片上传中...', 'fas fa-spinner fa-spin', '#4ade80');
// 模拟上传过程
setTimeout(() => {
// 上传成功
this.showUploadStatus('图片上传成功', 'fas fa-check-circle', '#4ade80');
// 添加到消息列表
this.addMessage({
userId: this.currentUser.id,
name: this.currentUser.name,
avatarColor: this.currentUser.avatarColor,
text: MOCK_IMAGE_URL,
timestamp: new Date(),
type: 'sent',
messageType: 'image' // 图片类型
});
// 实际开发中应通过API发送到服务器
}, 2000);
},
// 模拟视频上传功能
showAttachmentUpload() {
this.addSystemMessage("附件上传功能(实际应用中需要实现上传功能)");
// 显示上传状态
this.showUploadStatus('视频上传中...', 'fas fa-spinner fa-spin', '#60a5fa');
// 模拟上传过程
setTimeout(() => {
// 上传成功
this.showUploadStatus('视频上传成功', 'fas fa-check-circle', '#60a5fa');
// 添加到消息列表
this.addMessage({
userId: this.currentUser.id,
name: this.currentUser.name,
avatarColor: this.currentUser.avatarColor,
text: MOCK_VIDEO_URL,
timestamp: new Date(),
type: 'sent',
messageType: 'video' // 视频类型
});
// 实际开发中应通过API发送到服务器
}, 2000);
}
}
});

File diff suppressed because it is too large Load Diff