feat: 添加 OSS 存储配额功能
- 数据库:添加 oss_storage_quota 字段(0 表示无限制) - 后端:登录/用户信息返回 OSS 配额 - 后端:管理员可设置用户 OSS 配额 - 后端:上传时检查 OSS 配额限制 - 前端:管理员编辑用户增加 OSS 配额设置 - 前端:用户文件页面显示 OSS 使用量和配额 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1808,8 +1808,10 @@
|
||||
<i class="fas fa-exclamation-triangle"></i> {{ ossUsageError }}
|
||||
</div>
|
||||
<div v-else-if="ossUsage" style="font-size: 13px; font-weight: 600; color: #4b5fc9;">
|
||||
{{ ossUsage.totalSizeFormatted }}
|
||||
<span style="font-weight: 400; color: var(--text-muted); font-size: 12px;">({{ ossUsage.fileCount }} 文件)</span>
|
||||
{{ ossUsage.totalSizeFormatted }}
|
||||
<span v-if="ossQuota > 0" style="font-weight: 400; color: var(--text-muted);">/ {{ formatBytes(ossQuota) }}</span>
|
||||
<span v-else style="font-weight: 400; color: var(--text-muted);">/ 无限制</span>
|
||||
<div style="font-weight: 400; color: var(--text-muted); font-size: 12px; margin-top: 4px;">{{ ossUsage.fileCount }} 文件</div>
|
||||
</div>
|
||||
<div v-else style="font-size: 12px; color: var(--text-muted);">点击刷新查看</div>
|
||||
</div>
|
||||
@@ -3109,7 +3111,19 @@
|
||||
• 默认配额: 1GB<br>
|
||||
• 当前配额: {{ editStorageForm.local_storage_quota_value }} {{ editStorageForm.quota_unit }}
|
||||
({{ editStorageForm.quota_unit === 'GB' ? (editStorageForm.local_storage_quota_value * 1024).toFixed(0) : editStorageForm.local_storage_quota_value }} MB)<br>
|
||||
• 配额仅影响本地存储,OSS存储不受此限制
|
||||
• 本地配额默认: 1GB | OSS配额默认: 无限制
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- OSS 存储配额 -->
|
||||
<div class="form-group">
|
||||
<label class="form-label">OSS 存储配额 <span style="color: var(--text-muted); font-weight: normal;">(0 = 无限制)</span></label>
|
||||
<div style="display: flex; gap: 10px;">
|
||||
<input type="number" class="form-input" v-model.number="editStorageForm.oss_storage_quota_value" min="0" max="102400" step="1" style="flex: 1;">
|
||||
<select class="form-input" v-model="editStorageForm.oss_quota_unit" style="width: 100px;">
|
||||
<option value="GB">GB</option>
|
||||
<option value="MB">MB</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -239,6 +239,7 @@ createApp({
|
||||
storagePermission: 'oss_only', // 存储权限
|
||||
localQuota: 0, // 本地存储配额(字节)
|
||||
localUsed: 0, // 本地存储已使用(字节)
|
||||
ossQuota: 0, // OSS 存储配额(字节,0表示无限制)
|
||||
|
||||
|
||||
// 右键菜单
|
||||
@@ -653,6 +654,7 @@ handleDragLeave(e) {
|
||||
this.storageType = this.user.current_storage_type || 'oss';
|
||||
this.localQuota = this.user.local_storage_quota || 0;
|
||||
this.localUsed = this.user.local_storage_used || 0;
|
||||
this.ossQuota = this.user.oss_storage_quota || 0;
|
||||
|
||||
console.log('[登录] 存储权限:', this.storagePermission, '存储类型:', this.storageType, 'OSS配置:', this.user.oss_config_source);
|
||||
|
||||
@@ -1157,6 +1159,7 @@ handleDragLeave(e) {
|
||||
this.storageType = this.user.current_storage_type || 'oss';
|
||||
this.localQuota = this.user.local_storage_quota || 0;
|
||||
this.localUsed = this.user.local_storage_used || 0;
|
||||
this.ossQuota = this.user.oss_storage_quota || 0;
|
||||
|
||||
console.log('[页面加载] Cookie验证成功,存储权限:', this.storagePermission, '存储类型:', this.storageType);
|
||||
|
||||
@@ -1912,7 +1915,8 @@ handleDragLeave(e) {
|
||||
params: {
|
||||
filename: file.name,
|
||||
path: this.currentPath,
|
||||
contentType: file.type || 'application/octet-stream'
|
||||
contentType: file.type || 'application/octet-stream',
|
||||
fileSize: file.size
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2655,6 +2659,23 @@ handleDragLeave(e) {
|
||||
this.editStorageForm.quota_unit = 'MB';
|
||||
}
|
||||
|
||||
// OSS 配额初始化
|
||||
const ossQuotaBytes = user.oss_storage_quota || 0;
|
||||
if (ossQuotaBytes === 0) {
|
||||
this.editStorageForm.oss_storage_quota_value = 0;
|
||||
this.editStorageForm.oss_quota_unit = "GB";
|
||||
} else {
|
||||
const ossQuotaMB = ossQuotaBytes / 1024 / 1024;
|
||||
const ossQuotaGB = ossQuotaMB / 1024;
|
||||
if (ossQuotaMB >= 1024 && ossQuotaMB % 1024 === 0) {
|
||||
this.editStorageForm.oss_storage_quota_value = ossQuotaGB;
|
||||
this.editStorageForm.oss_quota_unit = "GB";
|
||||
} else {
|
||||
this.editStorageForm.oss_storage_quota_value = Math.round(ossQuotaMB);
|
||||
this.editStorageForm.oss_quota_unit = "MB";
|
||||
}
|
||||
}
|
||||
|
||||
this.showEditStorageModal = true;
|
||||
},
|
||||
|
||||
@@ -2669,11 +2690,22 @@ handleDragLeave(e) {
|
||||
quotaBytes = this.editStorageForm.local_storage_quota_value * 1024 * 1024;
|
||||
}
|
||||
|
||||
// 计算 OSS 配额字节数
|
||||
let ossQuotaBytes = 0;
|
||||
if (this.editStorageForm.oss_storage_quota_value > 0) {
|
||||
if (this.editStorageForm.oss_quota_unit === "GB") {
|
||||
ossQuotaBytes = this.editStorageForm.oss_storage_quota_value * 1024 * 1024 * 1024;
|
||||
} else {
|
||||
ossQuotaBytes = this.editStorageForm.oss_storage_quota_value * 1024 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await axios.post(
|
||||
`${this.apiBase}/api/admin/users/${this.editStorageForm.userId}/storage-permission`,
|
||||
{
|
||||
storage_permission: this.editStorageForm.storage_permission,
|
||||
local_storage_quota: quotaBytes
|
||||
local_storage_quota: quotaBytes,
|
||||
oss_storage_quota: ossQuotaBytes
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user