【m】布局修改完成确认

This commit is contained in:
zhangzheng
2026-03-03 18:06:20 +08:00
parent a0ab9b44f1
commit b0b88dc88d
6 changed files with 135 additions and 3 deletions

View File

@@ -180,6 +180,61 @@ function bindDomEvents() {
}
};
// 打开图片选择器
window.openImagePicker = function() {
document.getElementById('imageInput').click();
};
// 处理图片上传
window.handleImageUpload = function(event) {
const file = event.target.files[0];
if (file) {
// 检查文件类型
if (!file.type.startsWith('image/')) {
showNotification('请选择图片文件', 3000);
return;
}
// 检查文件大小限制为5MB
if (file.size > 5 * 1024 * 1024) {
showNotification('图片文件不能超过5MB', 3000);
return;
}
// 读取图片文件
const reader = new FileReader();
reader.onload = function(e) {
const imageUrl = e.target.result;
sendImageMessage(imageUrl, file.name);
};
reader.readAsDataURL(file);
// 重置文件输入
event.target.value = '';
}
};
// 发送图片消息
function sendImageMessage(imageUrl, fileName) {
const state = store.getState();
const newMessage = {
id: generateId(),
senderId: state.session.localUser.id,
senderName: state.session.localUser.name,
senderAvatar: state.session.localUser.avatar,
content: imageUrl,
fileName: fileName,
type: 'file',
timestamp: new Date().toISOString(),
isSelf: true
};
store.addMessage(newMessage);
// 发送消息到服务器
// wsManager.send('send-message', newMessage);
}
// 键盘快捷键
document.addEventListener('keydown', (event) => {
// 空格键静音