动态更新容量进度条

This commit is contained in:
Wisp X
2022-01-14 16:26:07 +08:00
parent 8e4d9f23ad
commit b38957d374
6 changed files with 55 additions and 5 deletions

19
resources/js/app.js vendored
View File

@@ -15,6 +15,25 @@ window.utils = {
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
},
/**
* 更新进度条
* @param size 增加的字节(kb)
* @param total 总共有多少字节(kb)
*/
setCapacityProgress(size, total) {
let $progress = $('#capacity-progress');
if ($progress.length) {
let used = parseFloat($progress.find('progress').val()) + size;
$progress.find('progress').val(used);
$progress.find('span.used').text(utils.formatSize(used * 1024));
if (total !== undefined && typeof total === 'number') {
total = parseFloat($progress.find('progress').attr('max')) + total;
$progress.find('progress').attr('max', total);
$progress.find('span.total').text(utils.formatSize(total * 1024));
}
}
},
guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);

View File

@@ -197,6 +197,7 @@
$('#links [data-tab="' + key + '"]').append('<p class="whitespace-nowrap select-all mt-1 bg-gray-50 hover:bg-gray-200 text-gray-600 rounded px-2 py-1 cursor-pointer overflow-scroll scrollbar-none">' + links[key].toString() + '</p>')
}
$links.show();
utils.setCapacityProgress(response.data.size);
} else {
setStatus(data, UPLOAD_ERROR, "上传失败, " + response.message);
// 重新显示上传按钮

View File

@@ -658,7 +658,12 @@
data: selected,
}).then(response => {
if (response.data.status) {
ds.getSelection().map(item => $(item).remove());
let size = 0;
ds.getSelection().map(item => {
size += $(item).data('json').size;
$(item).remove();
});
utils.setCapacityProgress(-size);
$headerTitle.text('我的图片');
$photos.justifiedGallery(gridConfigs).removeClass('reset');
toastr.success(response.data.message);

View File

@@ -71,10 +71,14 @@
</div>
</div>
<div class="flex flex-col space-y-2 mb-5 px-5 w-full mt-10">
<div id="capacity-progress" class="flex flex-col space-y-2 mb-5 px-5 w-full mt-10">
<p class="text-gray-700 text-sm">容量使用</p>
<progress class="w-full h-1.5 bg-gary-300" value="90" max="100"></progress>
<p class="text-gray-700 text-sm truncate" title="0.00 Bytes / 1.00 GB">0.00 Bytes / 1.00 GB</p>
<progress class="w-full h-1.5 bg-gary-300" value="{{ Auth::user()->images->sum('size') }}" max="{{ Auth::user()->capacity }}"></progress>
<p class="text-gray-700 text-sm truncate">
<span class="used">{{ \App\Utils::formatSize(Auth::user()->images->sum('size') * 1024) }}</span>
/
<span class="total">{{ \App\Utils::formatSize(Auth::user()->capacity * 1024) }}</span>
</p>
</div>
</div>
</nav>