feat: make zero download quota block downloads and use -1 for unlimited
This commit is contained in:
@@ -3335,10 +3335,10 @@
|
||||
</div>
|
||||
</td>
|
||||
<td style="padding: 10px; text-align: center; font-size: 12px;">
|
||||
<div v-if="u.download_traffic_quota > 0">
|
||||
<div v-if="u.download_traffic_quota >= 0">
|
||||
<div>{{ formatBytes(u.download_traffic_used || 0) }} / {{ formatBytes(u.download_traffic_quota) }}</div>
|
||||
<div style="font-size: 11px; color: var(--text-muted);">
|
||||
{{ getAdminUserDownloadQuotaPercentage(u) }}%
|
||||
{{ u.download_traffic_quota === 0 ? '已禁用下载' : (getAdminUserDownloadQuotaPercentage(u) + '%') }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
@@ -3709,7 +3709,7 @@
|
||||
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
|
||||
<label style="display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary);">
|
||||
<input type="checkbox" v-model="editStorageForm.download_quota_unlimited">
|
||||
不限流量
|
||||
不限流量(-1)
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="!editStorageForm.download_quota_unlimited" style="display: flex; gap: 10px;">
|
||||
@@ -3717,7 +3717,7 @@
|
||||
type="number"
|
||||
class="form-input"
|
||||
v-model.number="editStorageForm.download_traffic_quota_value"
|
||||
min="1"
|
||||
min="0"
|
||||
max="10240"
|
||||
step="1"
|
||||
style="flex: 1;">
|
||||
@@ -3746,7 +3746,7 @@
|
||||
</div>
|
||||
|
||||
<small style="color: var(--text-secondary); font-size: 12px; margin-top: 5px; display: block;">
|
||||
下载流量支持直接设置、增减操作,范围: 不限 或 1MB - 10TB
|
||||
下载流量支持直接设置、增减操作,范围: 0B - 10TB;勾选“不限流量(-1)”表示不限制
|
||||
</small>
|
||||
</div>
|
||||
|
||||
@@ -3754,7 +3754,7 @@
|
||||
<label class="form-label">下载流量到期时间(可选)</label>
|
||||
<input type="datetime-local" class="form-input" v-model="editStorageForm.download_quota_expires_at">
|
||||
<small style="color: var(--text-secondary); font-size: 12px; margin-top: 5px; display: block;">
|
||||
到期后自动恢复为不限流量并清零已用流量;留空表示永不过期
|
||||
到期后自动恢复为 0 并清零已用流量;留空表示永不过期
|
||||
</small>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ createApp({
|
||||
oss_quota_unlimited: false, // 兼容旧数据字段(当前固定为有限配额)
|
||||
download_traffic_quota_value: 1, // 下载流量配额数值
|
||||
download_quota_unit: 'GB', // 下载流量单位:MB / GB / TB
|
||||
download_quota_unlimited: true, // 下载流量:true=不限
|
||||
download_quota_unlimited: false, // 下载流量:true=不限(后端值为 -1)
|
||||
download_traffic_used: 0, // 下载流量已使用(字节)
|
||||
download_quota_operation: 'set', // set/increase/decrease
|
||||
download_quota_adjust_value: 1, // 增减额度数值
|
||||
@@ -407,7 +407,8 @@ createApp({
|
||||
if (this.downloadTrafficReport?.quota?.is_unlimited === true) {
|
||||
return true;
|
||||
}
|
||||
return this.downloadTrafficQuotaBytes <= 0;
|
||||
const userQuota = Number(this.user?.download_traffic_quota);
|
||||
return Number.isFinite(userQuota) && userQuota < 0;
|
||||
},
|
||||
|
||||
downloadTrafficRemainingBytes() {
|
||||
@@ -434,7 +435,7 @@ createApp({
|
||||
}
|
||||
|
||||
if (this.downloadTrafficQuotaBytes <= 0) {
|
||||
return 0;
|
||||
return 100;
|
||||
}
|
||||
|
||||
return Math.min(100, Math.round((this.downloadTrafficUsedBytes / this.downloadTrafficQuotaBytes) * 100));
|
||||
@@ -3120,8 +3121,9 @@ handleDragLeave(e) {
|
||||
this.editStorageForm.oss_quota_unit = 'MB';
|
||||
}
|
||||
|
||||
// 下载流量配额(0 表示不限)
|
||||
// 下载流量配额(-1 表示不限,0 表示禁止下载)
|
||||
const downloadQuotaBytes = Number(user.download_traffic_quota || 0);
|
||||
const isDownloadUnlimited = Number.isFinite(downloadQuotaBytes) && downloadQuotaBytes < 0;
|
||||
const effectiveDownloadQuotaBytes = Number.isFinite(downloadQuotaBytes) && downloadQuotaBytes > 0
|
||||
? downloadQuotaBytes
|
||||
: 0;
|
||||
@@ -3137,10 +3139,13 @@ handleDragLeave(e) {
|
||||
this.editStorageForm.download_quota_expires_at = this.toDateTimeLocalInput(user.download_traffic_quota_expires_at);
|
||||
this.editStorageForm.reset_download_used_now = false;
|
||||
|
||||
this.editStorageForm.download_quota_unlimited = effectiveDownloadQuotaBytes <= 0;
|
||||
if (effectiveDownloadQuotaBytes <= 0) {
|
||||
this.editStorageForm.download_quota_unlimited = isDownloadUnlimited;
|
||||
if (isDownloadUnlimited) {
|
||||
this.editStorageForm.download_traffic_quota_value = 1;
|
||||
this.editStorageForm.download_quota_unit = 'GB';
|
||||
} else if (effectiveDownloadQuotaBytes <= 0) {
|
||||
this.editStorageForm.download_traffic_quota_value = 0;
|
||||
this.editStorageForm.download_quota_unit = 'MB';
|
||||
} else if (effectiveDownloadQuotaBytes >= tb && effectiveDownloadQuotaBytes % tb === 0) {
|
||||
this.editStorageForm.download_traffic_quota_value = effectiveDownloadQuotaBytes / tb;
|
||||
this.editStorageForm.download_quota_unit = 'TB';
|
||||
@@ -3196,10 +3201,11 @@ handleDragLeave(e) {
|
||||
let downloadQuotaBytes = null;
|
||||
let downloadTrafficDelta = null;
|
||||
if (this.editStorageForm.download_quota_operation === 'set') {
|
||||
downloadQuotaBytes = 0;
|
||||
if (!this.editStorageForm.download_quota_unlimited) {
|
||||
if (!this.editStorageForm.download_traffic_quota_value || this.editStorageForm.download_traffic_quota_value < 1) {
|
||||
this.showToast('error', '参数错误', '下载流量配额必须大于 0,或选择不限流量');
|
||||
if (this.editStorageForm.download_quota_unlimited) {
|
||||
downloadQuotaBytes = -1;
|
||||
} else {
|
||||
if (this.editStorageForm.download_traffic_quota_value === null || this.editStorageForm.download_traffic_quota_value === undefined || this.editStorageForm.download_traffic_quota_value < 0) {
|
||||
this.showToast('error', '参数错误', '下载流量配额必须大于等于 0,或选择不限流量');
|
||||
return;
|
||||
}
|
||||
downloadQuotaBytes = toBytes(
|
||||
@@ -3287,7 +3293,9 @@ handleDragLeave(e) {
|
||||
getAdminUserDownloadQuotaPercentage(user) {
|
||||
const quota = Number(user?.download_traffic_quota || 0);
|
||||
const used = Number(user?.download_traffic_used || 0);
|
||||
if (!Number.isFinite(quota) || quota <= 0) return 0;
|
||||
if (!Number.isFinite(quota)) return 0;
|
||||
if (quota < 0) return 0;
|
||||
if (quota === 0) return 100;
|
||||
if (!Number.isFinite(used) || used <= 0) return 0;
|
||||
return Math.min(100, Math.round((used / quota) * 100));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user