2016-08-17 06:01:20 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class QuotaUserStore {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
this.quota = ko.observable(0);
|
|
|
|
this.usage = ko.observable(0);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.percentage = ko.computed(() => {
|
2019-07-05 03:19:24 +08:00
|
|
|
const quota = this.quota(),
|
2016-08-17 06:01:20 +08:00
|
|
|
usage = this.usage();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
return 0 < quota ? Math.ceil((usage / quota) * 100) : 0;
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {number} quota
|
|
|
|
* @param {number} usage
|
|
|
|
*/
|
|
|
|
populateData(quota, usage) {
|
2020-08-14 04:58:41 +08:00
|
|
|
this.quota(quota * 1024);
|
|
|
|
this.usage(usage * 1024);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-09-13 04:50:21 +08:00
|
|
|
export default new QuotaUserStore();
|