feat: apply UI/storage/share optimizations and quota improvements

This commit is contained in:
2026-02-12 18:02:57 +08:00
parent 1fcc60b9aa
commit 12859cbb20
13 changed files with 4476 additions and 828 deletions

View File

@@ -1,4 +1,6 @@
const { createApp } = Vue;
const DEFAULT_LOCAL_STORAGE_QUOTA_BYTES = 1024 * 1024 * 1024; // 1GB
const DEFAULT_OSS_STORAGE_QUOTA_BYTES = 1024 * 1024 * 1024; // 1GB
createApp({
data() {
@@ -90,18 +92,13 @@ createApp({
// 分享管理
shares: [],
showShareAllModal: false,
showShareFileModal: false,
creatingShare: false, // 创建分享中状态
shareAllForm: {
password: "",
expiryType: "never",
customDays: 7
},
shareFileForm: {
fileName: "",
filePath: "",
isDirectory: false, // 新增:标记是否为文件夹
enablePassword: false,
password: "",
expiryType: "never",
customDays: 7
@@ -246,12 +243,15 @@ createApp({
contextMenuX: 0,
contextMenuY: 0,
contextMenuFile: null,
showMobileFileActionSheet: false,
mobileActionFile: null,
// 长按检测
longPressTimer: null,
longPressStartX: 0,
longPressStartY: 0,
longPressFile: null,
longPressTriggered: false,
// 媒体预览
showImageViewer: false,
@@ -260,15 +260,18 @@ createApp({
currentMediaUrl: '',
currentMediaName: '',
currentMediaType: '', // 'image', 'video', 'audio'
longPressDuration: 500, // 长按时间(毫秒)
longPressDuration: 420, // 长按时间(毫秒)
// 管理员编辑用户存储权限
showEditStorageModal: false,
editStorageForm: {
userId: null,
username: '',
storage_permission: 'oss_only',
local_storage_quota_value: 1, // 配额数值
quota_unit: 'GB' // 配额单位MB 或 GB
local_storage_quota_value: 1, // 本地配额数值
quota_unit: 'GB', // 本地配额单位MB 或 GB
oss_storage_quota_value: 1, // OSS配额数值默认1GB
oss_quota_unit: 'GB', // OSS配额单位MB / GB / TB
oss_quota_unlimited: false // 兼容旧数据字段(当前固定为有限配额)
},
// 服务器存储统计
@@ -325,11 +328,82 @@ createApp({
return Math.round((this.localUsed / this.localQuota) * 100);
},
// OSS 配额相关(文件页展示)
ossQuotaBytes() {
const quota = Number(this.user?.oss_storage_quota || DEFAULT_OSS_STORAGE_QUOTA_BYTES);
if (!Number.isFinite(quota) || quota <= 0) {
return DEFAULT_OSS_STORAGE_QUOTA_BYTES;
}
return quota;
},
ossUsedBytes() {
const usageFromStats = Number(this.ossUsage?.totalSize);
if (Number.isFinite(usageFromStats) && usageFromStats >= 0) {
return usageFromStats;
}
const usageFromUser = Number(this.user?.storage_used || 0);
if (Number.isFinite(usageFromUser) && usageFromUser >= 0) {
return usageFromUser;
}
return 0;
},
ossQuotaFormatted() {
return this.formatBytes(this.ossQuotaBytes);
},
ossUsedFormatted() {
return this.formatBytes(this.ossUsedBytes);
},
ossQuotaPercentage() {
if (this.ossQuotaBytes <= 0) return 0;
return Math.min(100, Math.round((this.ossUsedBytes / this.ossQuotaBytes) * 100));
},
// 存储类型显示文本
storageTypeText() {
return this.storageType === 'local' ? '本地存储' : 'OSS存储';
},
// 文件统计信息(用于文件页工具栏)
fileStats() {
const list = Array.isArray(this.files) ? this.files : [];
let directoryCount = 0;
let fileCount = 0;
let totalFileBytes = 0;
for (const item of list) {
if (item?.isDirectory) {
directoryCount += 1;
continue;
}
fileCount += 1;
const currentSize = Number(item?.size || 0);
if (Number.isFinite(currentSize) && currentSize > 0) {
totalFileBytes += currentSize;
}
}
return {
totalCount: list.length,
directoryCount,
fileCount,
totalFileBytes
};
},
currentPathLabel() {
if (!this.currentPath || this.currentPath === '/') {
return '根目录';
}
return this.currentPath;
},
// 分享筛选+排序后的列表
filteredShares() {
let list = [...this.shares];
@@ -344,8 +418,16 @@ createApp({
}
if (this.shareFilters.type !== 'all') {
const targetType = this.shareFilters.type === 'all_files' ? 'all' : this.shareFilters.type;
list = list.filter(s => (s.share_type || 'file') === targetType);
const selectedType = this.shareFilters.type;
list = list.filter(s => {
if (selectedType === 'all_files') {
return this.isShareAllFiles(s);
}
if (selectedType === 'directory') {
return (s.share_type || 'file') === 'directory' && !this.isShareAllFiles(s);
}
return (s.share_type || 'file') === selectedType;
});
}
if (this.shareFilters.status !== 'all') {
@@ -353,8 +435,8 @@ createApp({
if (this.shareFilters.status === 'expired') return this.isExpired(s.expires_at);
if (this.shareFilters.status === 'expiring') return this.isExpiringSoon(s.expires_at) && !this.isExpired(s.expires_at);
if (this.shareFilters.status === 'active') return !this.isExpired(s.expires_at);
if (this.shareFilters.status === 'protected') return !!s.share_password;
if (this.shareFilters.status === 'public') return !s.share_password;
if (this.shareFilters.status === 'protected') return this.hasSharePassword(s);
if (this.shareFilters.status === 'public') return !this.hasSharePassword(s);
return true;
});
}
@@ -1125,6 +1207,7 @@ handleDragLeave(e) {
// 停止定期检查
this.stopProfileSync();
this.closeMobileFileActionSheet();
},
// 获取公开的系统配置(上传限制等)
@@ -1306,6 +1389,11 @@ handleDragLeave(e) {
// 更新用户本地存储信息(使用防抖避免频繁请求)
this.debouncedLoadUserProfile();
// OSS 模式下刷新一次空间统计,保证文件页配额显示实时
if (this.storageType === 'oss' && this.user?.oss_config_source !== 'none') {
this.loadOssUsage();
}
}
} catch (error) {
console.error('加载文件失败:', error);
@@ -1320,6 +1408,12 @@ handleDragLeave(e) {
},
async handleFileClick(file) {
// 修复:长按后会触发一次 click需要忽略避免误打开文件/目录
if (this.longPressTriggered) {
this.longPressTriggered = false;
return;
}
if (file.isDirectory) {
const newPath = this.currentPath === '/'
? `/${file.name}`
@@ -1510,13 +1604,23 @@ handleDragLeave(e) {
// ===== 右键菜单和长按功能 =====
// 显示右键菜单PC端
// 显示右键菜单PC端/ 长按菜单(移动端)
showFileContextMenu(file, event) {
// 文件和文件夹都可以显示右键菜单
event.preventDefault();
event?.preventDefault?.();
event?.stopPropagation?.();
const isTouchContextMenu = this.isMobileViewport()
|| event?.pointerType === 'touch'
|| Boolean(event?.sourceCapabilities?.firesTouchEvents);
if (isTouchContextMenu) {
this.openMobileFileActionSheet(file, event);
return;
}
this.contextMenuFile = file;
this.contextMenuX = event.clientX;
this.contextMenuY = event.clientY;
this.contextMenuX = event?.clientX || 0;
this.contextMenuY = event?.clientY || 0;
this.showContextMenu = true;
// 点击其他地方关闭菜单
@@ -1530,10 +1634,52 @@ handleDragLeave(e) {
this.showContextMenu = false;
this.contextMenuFile = null;
},
isMobileViewport() {
return window.matchMedia('(max-width: 768px)').matches;
},
setMobileSheetScrollLock(locked) {
if (!document.body) return;
document.body.style.overflow = locked ? 'hidden' : '';
},
openMobileFileActionSheet(file, event) {
if (event) {
event.preventDefault();
event.stopPropagation();
}
this.hideContextMenu();
this.mobileActionFile = file;
this.showMobileFileActionSheet = true;
this.setMobileSheetScrollLock(true);
},
closeMobileFileActionSheet() {
this.showMobileFileActionSheet = false;
this.mobileActionFile = null;
this.setMobileSheetScrollLock(false);
},
async mobileFileAction(action) {
const targetFile = this.mobileActionFile;
this.closeMobileFileActionSheet();
if (!targetFile) {
return;
}
this.contextMenuFile = targetFile;
await this.contextMenuAction(action);
},
// 长按开始(移动端)
handleLongPressStart(file, event) {
if (file.isDirectory) return; // 文件夹不响应长按
if (!event?.touches?.length) return;
if (this.showMobileFileActionSheet) return;
this.longPressTriggered = false;
// 记录初始触摸位置,用于检测是否在滑动
const touch = event.touches[0];
@@ -1542,29 +1688,39 @@ handleDragLeave(e) {
this.longPressFile = file;
this.longPressTimer = setTimeout(() => {
// 触发长按菜单
this.contextMenuFile = file;
this.longPressTriggered = true;
// 使用记录的触摸位置
this.contextMenuX = this.longPressStartX;
this.contextMenuY = this.longPressStartY;
this.showContextMenu = true;
if (event?.cancelable) {
event.preventDefault();
}
if (this.isMobileViewport()) {
this.openMobileFileActionSheet(file, event);
} else {
// 触发长按菜单
this.contextMenuFile = file;
// 使用记录的触摸位置
this.contextMenuX = this.longPressStartX;
this.contextMenuY = this.longPressStartY;
this.showContextMenu = true;
// 点击其他地方关闭菜单
this.$nextTick(() => {
document.addEventListener('click', this.hideContextMenu, { once: true });
});
}
// 触摸震动反馈(如果支持)
if (navigator.vibrate) {
navigator.vibrate(50);
}
// 点击其他地方关闭菜单
this.$nextTick(() => {
document.addEventListener('click', this.hideContextMenu, { once: true });
});
}, this.longPressDuration);
},
// 长按移动检测(移动端)- 滑动时取消长按
handleLongPressMove(event) {
if (!this.longPressTimer) return;
if (!this.longPressTimer || !event?.touches?.length) return;
const touch = event.touches[0];
const moveX = Math.abs(touch.clientX - this.longPressStartX);
@@ -1583,6 +1739,7 @@ handleDragLeave(e) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
this.longPressFile = null;
},
// 从菜单执行操作
@@ -1768,6 +1925,7 @@ handleDragLeave(e) {
? file.name
: `${this.currentPath}/${file.name}`;
this.shareFileForm.isDirectory = file.isDirectory; // 设置是否为文件夹
this.shareFileForm.enablePassword = false;
this.shareFileForm.password = '';
this.shareFileForm.expiryType = 'never';
this.shareFileForm.customDays = 7;
@@ -1775,45 +1933,76 @@ handleDragLeave(e) {
this.showShareFileModal = true;
},
async createShareAll() {
if (this.creatingShare) return; // 防止重复提交
this.creatingShare = true;
try {
const expiryDays = this.shareAllForm.expiryType === 'never' ? null :
this.shareAllForm.expiryType === 'custom' ? this.shareAllForm.customDays :
parseInt(this.shareAllForm.expiryType);
const response = await axios.post(
`${this.apiBase}/api/share/create`,
{
share_type: 'all',
password: this.shareAllForm.password || null,
expiry_days: expiryDays
},
);
if (response.data.success) {
this.shareResult = response.data;
this.showToast('success', '成功', '分享链接已创建');
this.loadShares();
}
} catch (error) {
console.error('创建分享失败:', error);
this.showToast('error', '错误', error.response?.data?.message || '创建分享失败');
} finally {
this.creatingShare = false;
toggleSharePassword(formType) {
if (formType === 'file' && !this.shareFileForm.enablePassword) {
this.shareFileForm.password = '';
}
},
resolveShareExpiry(expiryType, customDays) {
if (expiryType === 'never') {
return { valid: true, value: null };
}
const days = expiryType === 'custom'
? Number(customDays)
: Number(expiryType);
if (!Number.isInteger(days) || days < 1 || days > 365) {
return {
valid: false,
message: '有效期必须是 1-365 天的整数'
};
}
return { valid: true, value: days };
},
normalizeSharePassword(enablePassword, rawPassword) {
if (!enablePassword) {
return { valid: true, value: null };
}
const password = (rawPassword || '').trim();
if (!password) {
return { valid: false, message: '已启用密码保护,请输入访问密码' };
}
if (password.length > 32) {
return { valid: false, message: '访问密码不能超过32个字符' };
}
return { valid: true, value: password };
},
buildShareResult(data, options = {}) {
return {
...data,
has_password: typeof options.hasPassword === 'boolean' ? options.hasPassword : !!data.has_password,
target_name: options.targetName || '文件',
target_type: options.targetType || 'file',
share_password_plain: options.password || ''
};
},
async createShareFile() {
if (this.creatingShare) return; // 防止重复提交
this.creatingShare = true;
try {
const expiryDays = this.shareFileForm.expiryType === 'never' ? null :
this.shareFileForm.expiryType === 'custom' ? this.shareFileForm.customDays :
parseInt(this.shareFileForm.expiryType);
const expiryCheck = this.resolveShareExpiry(this.shareFileForm.expiryType, this.shareFileForm.customDays);
if (!expiryCheck.valid) {
this.showToast('warning', '提示', expiryCheck.message);
return;
}
const passwordCheck = this.normalizeSharePassword(this.shareFileForm.enablePassword, this.shareFileForm.password);
if (!passwordCheck.valid) {
this.showToast('warning', '提示', passwordCheck.message);
return;
}
const expiryDays = expiryCheck.value;
const password = passwordCheck.value;
// 根据是否为文件夹决定share_type
const shareType = this.shareFileForm.isDirectory ? 'directory' : 'file';
@@ -1824,15 +2013,20 @@ handleDragLeave(e) {
share_type: shareType, // 修复文件夹使用directory类型
file_path: this.shareFileForm.filePath,
file_name: this.shareFileForm.fileName,
password: this.shareFileForm.password || null,
password,
expiry_days: expiryDays
},
);
if (response.data.success) {
this.shareResult = response.data;
const itemType = this.shareFileForm.isDirectory ? '文件夹' : '文件';
this.showToast('success', '成功', `${itemType}分享链接已创建`);
this.shareResult = this.buildShareResult(response.data, {
hasPassword: this.shareFileForm.enablePassword,
targetName: this.shareFileForm.fileName,
targetType: shareType,
password
});
this.showToast('success', '成功', this.shareFileForm.enablePassword ? `${itemType}加密分享已创建` : `${itemType}分享链接已创建`);
this.loadShares();
}
} catch (error) {
@@ -1909,12 +2103,21 @@ handleDragLeave(e) {
// OSS 直连上传
async uploadToOSSDirect(file) {
try {
// 预检查 OSS 配额(后端也会做强校验,未配置默认 1GB
const ossQuota = Number(this.user?.oss_storage_quota || DEFAULT_OSS_STORAGE_QUOTA_BYTES);
const currentUsage = Number(this.user?.storage_used || this.ossUsage?.totalSize || 0);
if (currentUsage + file.size > ossQuota) {
const remaining = Math.max(ossQuota - currentUsage, 0);
throw new Error(`OSS 配额不足:文件 ${this.formatBytes(file.size)},剩余 ${this.formatBytes(remaining)}(总配额 ${this.formatBytes(ossQuota)}`);
}
// 1. 获取签名 URL传递当前路径
const { data: signData } = await axios.get(`${this.apiBase}/api/files/upload-signature`, {
params: {
filename: file.name,
path: this.currentPath,
contentType: file.type || 'application/octet-stream'
contentType: file.type || 'application/octet-stream',
size: file.size
}
});
@@ -1922,6 +2125,10 @@ handleDragLeave(e) {
throw new Error(signData.message || '获取上传签名失败');
}
if (!signData.completionToken) {
throw new Error('上传签名缺少完成凭证,请刷新页面后重试');
}
// 2. 直连 OSS 上传(不经过后端!)
await axios.put(signData.uploadUrl, file, {
headers: {
@@ -1939,6 +2146,7 @@ handleDragLeave(e) {
await axios.post(`${this.apiBase}/api/files/upload-complete`, {
objectKey: signData.objectKey,
size: file.size,
completionToken: signData.completionToken,
path: this.currentPath
});
@@ -2106,11 +2314,52 @@ handleDragLeave(e) {
return expireDate <= now;
},
normalizeSharePath(sharePath) {
if (!sharePath) return '/';
const normalized = String(sharePath)
.replace(/\\/g, '/')
.replace(/\/+/g, '/');
if (!normalized || normalized === '.') {
return '/';
}
return normalized.startsWith('/') ? normalized : `/${normalized}`;
},
isShareAllFiles(share) {
if (!share) return false;
const shareType = share.share_type || 'file';
const sharePath = this.normalizeSharePath(share.share_path || '/');
return shareType === 'all' || (shareType === 'directory' && sharePath === '/');
},
hasSharePassword(share) {
if (!share) return false;
if (typeof share.has_password === 'boolean') {
return share.has_password;
}
return !!share.share_password;
},
getShareTypeIcon(share) {
if (this.isShareAllFiles(share)) return 'fa-layer-group';
if ((share?.share_type || 'file') === 'directory') return 'fa-folder';
return 'fa-file-alt';
},
// 分享类型标签
getShareTypeLabel(type) {
switch (type) {
getShareTypeLabel(shareOrType, sharePath) {
const share = typeof shareOrType === 'object' && shareOrType !== null
? shareOrType
: { share_type: shareOrType, share_path: sharePath };
if (this.isShareAllFiles(share)) {
return '全部文件';
}
switch (share.share_type) {
case 'directory': return '文件夹';
case 'all': return '全部文件';
case 'file':
default: return '文件';
}
@@ -2129,7 +2378,7 @@ handleDragLeave(e) {
// 分享保护标签
getShareProtection(share) {
if (share.share_password) {
if (this.hasSharePassword(share)) {
return { text: '已加密', class: 'info', icon: 'fa-lock' };
}
return { text: '公开', class: 'info', icon: 'fa-unlock' };
@@ -2202,20 +2451,32 @@ handleDragLeave(e) {
}
},
copyShareLink(url) {
// 复制分享链接到剪贴板
copyTextToClipboard(text, successMessage = '已复制到剪贴板') {
if (!text) {
this.showToast('warning', '提示', '没有可复制的内容');
return;
}
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(url).then(() => {
this.showToast('success', '成功', '分享链接已复制到剪贴板');
navigator.clipboard.writeText(text).then(() => {
this.showToast('success', '成功', successMessage);
}).catch(() => {
this.fallbackCopyToClipboard(url);
this.fallbackCopyToClipboard(text, successMessage);
});
} else {
this.fallbackCopyToClipboard(url);
this.fallbackCopyToClipboard(text, successMessage);
}
},
fallbackCopyToClipboard(text) {
copyShareLink(url) {
this.copyTextToClipboard(url, '分享链接已复制到剪贴板');
},
copySharePassword(password) {
this.copyTextToClipboard(password, '访问密码已复制到剪贴板');
},
fallbackCopyToClipboard(text, successMessage = '已复制到剪贴板') {
// 备用复制方法
const textArea = document.createElement('textarea');
textArea.value = text;
@@ -2225,7 +2486,7 @@ handleDragLeave(e) {
textArea.select();
try {
document.execCommand('copy');
this.showToast('success', '成功', '分享链接已复制到剪贴板');
this.showToast('success', '成功', successMessage);
} catch (err) {
this.showToast('error', '错误', '复制失败,请手动复制');
}
@@ -2247,6 +2508,7 @@ handleDragLeave(e) {
}
},
async banUser(userId, banned) {
const action = banned ? '封禁' : '解封';
if (!confirm(`确定要${action}这个用户吗?`)) return;
@@ -2467,6 +2729,9 @@ handleDragLeave(e) {
if (response.data.success) {
this.ossUsage = response.data.usage;
if (this.user && this.ossUsage && Number.isFinite(Number(this.ossUsage.totalSize))) {
this.user.storage_used = Number(this.ossUsage.totalSize);
}
}
} catch (error) {
console.error('获取OSS空间使用情况失败:', error);
@@ -2643,39 +2908,80 @@ handleDragLeave(e) {
this.editStorageForm.username = user.username;
this.editStorageForm.storage_permission = user.storage_permission || 'oss_only';
// 智能识别配额单位
const quotaBytes = user.local_storage_quota || 1073741824;
const quotaMB = quotaBytes / 1024 / 1024;
const quotaGB = quotaMB / 1024;
// 如果配额能被1024整除且大于等于1GB使用GB单位否则使用MB
if (quotaMB >= 1024 && quotaMB % 1024 === 0) {
this.editStorageForm.local_storage_quota_value = quotaGB;
// 智能识别本地配额单位
const localQuotaBytes = Number(user.local_storage_quota || DEFAULT_LOCAL_STORAGE_QUOTA_BYTES);
const localQuotaMB = localQuotaBytes / 1024 / 1024;
const localQuotaGB = localQuotaMB / 1024;
if (localQuotaMB >= 1024 && localQuotaMB % 1024 === 0) {
this.editStorageForm.local_storage_quota_value = localQuotaGB;
this.editStorageForm.quota_unit = 'GB';
} else {
this.editStorageForm.local_storage_quota_value = Math.round(quotaMB);
this.editStorageForm.local_storage_quota_value = Math.max(1, Math.round(localQuotaMB));
this.editStorageForm.quota_unit = 'MB';
}
// 智能识别 OSS 配额单位(未配置时默认 1GB
const ossQuotaBytes = Number(user.oss_storage_quota || DEFAULT_OSS_STORAGE_QUOTA_BYTES);
const effectiveOssQuotaBytes = Number.isFinite(ossQuotaBytes) && ossQuotaBytes > 0
? ossQuotaBytes
: DEFAULT_OSS_STORAGE_QUOTA_BYTES;
const mb = 1024 * 1024;
const gb = 1024 * 1024 * 1024;
const tb = 1024 * 1024 * 1024 * 1024;
this.editStorageForm.oss_quota_unlimited = false;
if (effectiveOssQuotaBytes >= tb && effectiveOssQuotaBytes % tb === 0) {
this.editStorageForm.oss_storage_quota_value = effectiveOssQuotaBytes / tb;
this.editStorageForm.oss_quota_unit = 'TB';
} else if (effectiveOssQuotaBytes >= gb && effectiveOssQuotaBytes % gb === 0) {
this.editStorageForm.oss_storage_quota_value = effectiveOssQuotaBytes / gb;
this.editStorageForm.oss_quota_unit = 'GB';
} else {
this.editStorageForm.oss_storage_quota_value = Math.max(1, Math.round(effectiveOssQuotaBytes / mb));
this.editStorageForm.oss_quota_unit = 'MB';
}
this.showEditStorageModal = true;
},
// 管理员:更新用户存储权限
async updateUserStorage() {
try {
// 根据单位计算字节
let quotaBytes;
// 计算本地配额(字节
if (!this.editStorageForm.local_storage_quota_value || this.editStorageForm.local_storage_quota_value < 1) {
this.showToast('error', '参数错误', '本地配额必须大于 0');
return;
}
let localQuotaBytes;
if (this.editStorageForm.quota_unit === 'GB') {
quotaBytes = this.editStorageForm.local_storage_quota_value * 1024 * 1024 * 1024;
localQuotaBytes = this.editStorageForm.local_storage_quota_value * 1024 * 1024 * 1024;
} else {
quotaBytes = this.editStorageForm.local_storage_quota_value * 1024 * 1024;
localQuotaBytes = this.editStorageForm.local_storage_quota_value * 1024 * 1024;
}
// 计算 OSS 配额(字节)
if (!this.editStorageForm.oss_storage_quota_value || this.editStorageForm.oss_storage_quota_value < 1) {
this.showToast('error', '参数错误', 'OSS 配额必须大于 0');
return;
}
let ossQuotaBytes;
if (this.editStorageForm.oss_quota_unit === 'TB') {
ossQuotaBytes = this.editStorageForm.oss_storage_quota_value * 1024 * 1024 * 1024 * 1024;
} else 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: localQuotaBytes,
oss_storage_quota: ossQuotaBytes
},
);
@@ -2700,6 +3006,22 @@ handleDragLeave(e) {
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
},
getAdminUserQuotaPercentage(user) {
const quota = Number(user?.local_storage_quota || 0);
const used = Number(user?.local_storage_used || 0);
if (!Number.isFinite(quota) || quota <= 0) return 0;
if (!Number.isFinite(used) || used <= 0) return 0;
return Math.round((used / quota) * 100);
},
getAdminUserOssQuotaPercentage(user) {
const quota = Number(user?.oss_storage_quota || DEFAULT_OSS_STORAGE_QUOTA_BYTES);
const used = Number(user?.storage_used || 0);
if (!Number.isFinite(quota) || quota <= 0) return 0;
if (!Number.isFinite(used) || used <= 0) return 0;
return Math.min(100, Math.round((used / quota) * 100));
},
formatDate(dateString) {
if (!dateString) return '-';