Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

剪贴板:超时时间随请求体增大 #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pages/aosc-os/AoscIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const docList = reactive([
url: '/'
} */
]);

</script>

<template>
Expand Down
20 changes: 1 addition & 19 deletions src/pages/paste/PasteIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const submit = async () => {
ElMessage.error({
showClose: true,
duration: 10000,
message: `剪贴板大小超出了 10MiB 限制:文本占用了 ${formdataSize}B (${BToMB(formdataSize)}MiB)、附件占用了 ${toailFileSize}B (${BToMB(toailFileSize)}MiB)`
message: `剪贴板大小超出了 10MiB 限制:文本占用了 ${formdataSize}B (${BToMB(formdataSize,3)}MiB)、附件占用了 ${toailFileSize}B (${BToMB(toailFileSize,3)}MiB)`
});
}
submiting.value = true;
Expand Down Expand Up @@ -86,24 +86,6 @@ const editorOptions = ref({
}
});

// const showSize = (() => {
// let isShow = true;
// return () => {
// if (isShow) {
// isShow = false;
// const formdataSize = getFormDataSize();
// ElMessage.error({
// showClose: true,
// duration: 0,
// message: `当前文本占用了${formdataSize}B (${BToMB(formdataSize)}MB)`,
// onClose: () => {
// isShow = true;
// }
// });
// }
// };
// })();

const handleChange = (uploadFile, uploadFiles) => {
const formdataSize = getFormDataSize();
const toailSize = uploadFiles.reduce((size, file) => size + file.size, 0);
Expand Down
30 changes: 25 additions & 5 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,27 @@ export const requestGetJson = (() => {
};
})();

const calculateFormDataSize = (formData) => {
let totalSize = 0;

for (const [_key, value] of formData.entries()) {
if (typeof value === 'string') {
// 计算字符串的字节大小
totalSize += new TextEncoder().encode(value).length;
} else if (value instanceof File) {
// 对于文件,直接使用其 size 属性
totalSize += value.size;
}
// 你可以根据需要处理其他类型
}

return BToMB(totalSize);
};

export const requestPostJson = (() => {
let keys = {};
let promise = {};
return (url, data, params, key) => {
return (url, formdata, params, key) => {
if (!key) {
key = url;
}
Expand All @@ -73,9 +90,10 @@ export const requestPostJson = (() => {
promise[key] = axios({
url,
method: 'post',
data,
data: formdata,
params,
timeout: 5000
// 1MB等6秒 单位ms
timeout: Math.ceil(calculateFormDataSize(formdata)) * 6000
})
.then((resolve) => {
return [resolve, null];
Expand Down Expand Up @@ -109,8 +127,10 @@ export const setBackgroundColor = (color) => {
return 'bg-[' + color + ']';
};

export const BToMB = (byteSize, fixed = 3) => {
return (byteSize / 1024 / 1024).toFixed(fixed);
export const BToMB = (byteSize, fixed) => {
const Bsize = byteSize / 1024 / 1024;

return fixed ? Bsize.toFixed(fixed) : Bsize;
};

export const deObserver = (observers) => {
Expand Down