perf: 优化用户空间和配额计算
This commit is contained in:
parent
2e10b87b0d
commit
bb24e36294
@ -406,15 +406,15 @@ export default {
|
|||||||
if (this.takeUpSpace === 0) {
|
if (this.takeUpSpace === 0) {
|
||||||
this.takeUpSpace = this.userInfo.takeUpSpace
|
this.takeUpSpace = this.userInfo.takeUpSpace
|
||||||
}
|
}
|
||||||
const quota = this.userInfo.quota
|
const spaceBytes = this.takeUpSpace
|
||||||
const space = this.takeUpSpace/1024/1024/1024
|
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024
|
||||||
if(space && quota > 0){
|
if(spaceBytes && quotaBytes > 0){
|
||||||
const percentage = Number((space/quota * 100).toFixed(5))
|
const percentage = Number((spaceBytes/quotaBytes * 100).toFixed(5))
|
||||||
this.percentage = percentage > 100 ? 100 : percentage
|
this.percentage = percentage > 100 ? 100 : percentage
|
||||||
if(this.isCollapse){
|
if(this.isCollapse){
|
||||||
return `${formatSize(this.takeUpSpace)}`
|
return `${formatSize(this.takeUpSpace)}`
|
||||||
} else {
|
} else {
|
||||||
return `${formatSize(this.takeUpSpace)}/${quota}GB`
|
return `${formatSize(this.takeUpSpace)}/${formatSize(quotaBytes)}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,17 +127,18 @@ export function formatTime(agoTime) {
|
|||||||
* @param {*} size
|
* @param {*} size
|
||||||
*/
|
*/
|
||||||
export function formatSize(size) {
|
export function formatSize(size) {
|
||||||
if (size === 0) {
|
if (size === 0 || !size) return '0B';
|
||||||
return ''
|
|
||||||
} else if (size < 1024) {
|
const units = ['B', 'K', 'M', 'G', 'T'];
|
||||||
return size + 'B'
|
let index = 0;
|
||||||
} else if (size < 1024 * 1024) {
|
let result = size;
|
||||||
return (size/1024).toFixed(1) + 'k'
|
|
||||||
} else if (size < 1024 * 1024 * 1024) {
|
while (result >= 1024 && index < units.length - 1) {
|
||||||
return (size/(1024 * 1024)).toFixed(1) + 'M'
|
result /= 1024;
|
||||||
} else {
|
index++;
|
||||||
return (size/(1024 * 1024 * 1024)).toFixed(1) + 'G'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.toFixed(1) + units[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -241,12 +241,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
progressFormat() {
|
progressFormat() {
|
||||||
const space = this.userInfo.takeUpSpace/1024/1024/1024
|
const spaceBytes = this.userInfo.takeUpSpace;
|
||||||
const quota = this.userInfo.quota
|
const quotaBytes = this.userInfo.quota * 1024 * 1024 * 1024;
|
||||||
if(space && quota > 0){
|
|
||||||
const percentage = Number((space/quota * 100).toFixed(1))
|
if (spaceBytes && quotaBytes > 0) {
|
||||||
this.percentage = percentage > 100 ? 100 : percentage
|
const percentage = Number((spaceBytes / quotaBytes * 100).toFixed(1));
|
||||||
return `${this.percentage}% (${formatSize(this.userInfo.takeUpSpace)}/${quota}GB)`;
|
this.percentage = percentage > 100 ? 100 : percentage;
|
||||||
|
return `${this.percentage}% (${formatSize(spaceBytes)}/${formatSize(quotaBytes)})`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 设置formData
|
// 设置formData
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user