perf: 优化用户空间和配额计算

This commit is contained in:
jmal 2025-07-18 17:56:01 +08:00
parent 2e10b87b0d
commit bb24e36294
3 changed files with 23 additions and 21 deletions

View File

@ -406,15 +406,15 @@ export default {
if (this.takeUpSpace === 0) {
this.takeUpSpace = this.userInfo.takeUpSpace
}
const quota = this.userInfo.quota
const space = this.takeUpSpace/1024/1024/1024
if(space && quota > 0){
const percentage = Number((space/quota * 100).toFixed(5))
const spaceBytes = this.takeUpSpace
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024
if(spaceBytes && quotaBytes > 0){
const percentage = Number((spaceBytes/quotaBytes * 100).toFixed(5))
this.percentage = percentage > 100 ? 100 : percentage
if(this.isCollapse){
return `${formatSize(this.takeUpSpace)}`
} else {
return `${formatSize(this.takeUpSpace)}/${quota}GB`
return `${formatSize(this.takeUpSpace)}/${formatSize(quotaBytes)}`
}
}
}

View File

@ -127,17 +127,18 @@ export function formatTime(agoTime) {
* @param {*} size
*/
export function formatSize(size) {
if (size === 0) {
return ''
} else if (size < 1024) {
return size + 'B'
} else if (size < 1024 * 1024) {
return (size/1024).toFixed(1) + 'k'
} else if (size < 1024 * 1024 * 1024) {
return (size/(1024 * 1024)).toFixed(1) + 'M'
} else {
return (size/(1024 * 1024 * 1024)).toFixed(1) + 'G'
if (size === 0 || !size) return '0B';
const units = ['B', 'K', 'M', 'G', 'T'];
let index = 0;
let result = size;
while (result >= 1024 && index < units.length - 1) {
result /= 1024;
index++;
}
return result.toFixed(1) + units[index];
}
/**

View File

@ -241,12 +241,13 @@
}
},
progressFormat() {
const space = this.userInfo.takeUpSpace/1024/1024/1024
const quota = this.userInfo.quota
if(space && quota > 0){
const percentage = Number((space/quota * 100).toFixed(1))
this.percentage = percentage > 100 ? 100 : percentage
return `${this.percentage}% (${formatSize(this.userInfo.takeUpSpace)}/${quota}GB)`;
const spaceBytes = this.userInfo.takeUpSpace;
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024;
if (spaceBytes && quotaBytes > 0) {
const percentage = Number((spaceBytes / quotaBytes * 100).toFixed(1));
this.percentage = percentage > 100 ? 100 : percentage;
return `${this.percentage}% (${formatSize(spaceBytes)}/${formatSize(quotaBytes)})`;
}
},
// 设置formData