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:
2026-01-22 19:25:49 +08:00
parent 4bc147e53c
commit 949653ac00
6 changed files with 138 additions and 8 deletions

View File

@@ -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
},
);