Merge pull request 'fix: 增加文件大小限制' (#24) from yink into main
Reviewed-on: https://gitea-inner.fontree.cn/scout666/chat-pc/pulls/24
This commit is contained in:
commit
4cbad14c98
@ -164,9 +164,18 @@ const onSendVideoEvent = async ({ data }) => {
|
||||
const onSendCodeEvent = ({ data, callBack }) => {
|
||||
onSendMessage({ type: 'code', code: data.code, lang: data.lang }, callBack)
|
||||
}
|
||||
|
||||
// 发送文件消息
|
||||
const onSendFileEvent = ({ data }) => {
|
||||
const fn = (e) => {
|
||||
const confirmationMessage = '文件上传中请勿离开';
|
||||
e.returnValue = confirmationMessage; // 兼容旧版本浏览器
|
||||
return confirmationMessage; // 现代浏览器
|
||||
}
|
||||
window.addEventListener('beforeunload', fn);
|
||||
|
||||
if (data.size / (1024 * 1024) > 100) {
|
||||
return window['$message'].warning('只能上传100MB以内的文件!')
|
||||
}
|
||||
const clientUploadId = `file-${Date.now()}-${Math.floor(Math.random() * 1000)}`
|
||||
const tempMessage = {
|
||||
msg_id: clientUploadId,
|
||||
@ -205,6 +214,7 @@ const onSendFileEvent = ({ data }) => {
|
||||
async () => {
|
||||
// 上传完成后,上传任务已经被removeUploadTask方法移除
|
||||
// 不需要再次从records中删除
|
||||
window.removeEventListener('beforeunload', fn);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user