From 01eaef2bf965ffdf30273929e672c86454d7363b Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 17 Oct 2024 12:15:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=AB=99=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/@core/utils/formatters.ts | 16 +- src/api/types.ts | 4 + src/components/dialog/SiteUserDataDialog.vue | 348 ++++++++++++++++++- src/components/dialog/UserAddEditDialog.vue | 8 +- src/views/user/UserProfileView.vue | 38 +- 5 files changed, 380 insertions(+), 34 deletions(-) diff --git a/src/@core/utils/formatters.ts b/src/@core/utils/formatters.ts index 1b54972c..4a8b4d3f 100644 --- a/src/@core/utils/formatters.ts +++ b/src/@core/utils/formatters.ts @@ -60,19 +60,25 @@ export const prefixWithPlus = (value: number) => (value > 0 ? `+${value}` : valu export const formatSeason = (value: string) => (value ? `S${value.padStart(2, '0')}` : '') // 格式化为xx[TGMK]B -export function formatFileSize(bytes: number, decimals = 2) { - if (bytes < 0) throw new Error('字节数不能为负数。') +export function formatFileSize(bytes: number, decimals = 2, prefix = false) { + // 负数标记 + let negative = false + let size = bytes + if (bytes < 0) { + negative = true + size = Math.abs(bytes) + } const units = ['B', 'KB', 'MB', 'GB', 'TB'] - let size = bytes let unitIndex = 0 while (size >= 1024 && unitIndex < units.length - 1) { size /= 1024 unitIndex++ } - - return `${size.toFixed(decimals)} ${units[unitIndex]}` + if (negative) return `-${size.toFixed(decimals)} ${units[unitIndex]}` + else + return prefix ? `+${size.toFixed(decimals)} ${units[unitIndex]}` : `${size.toFixed(decimals)} ${units[unitIndex]}` } // 将时间秒格式化为时分秒 diff --git a/src/api/types.ts b/src/api/types.ts index b0ad8df9..7ecea116 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -471,6 +471,10 @@ export interface SiteUserData { message_unread_contents?: any[] // 默认为空数组 // 错误信息 err_msg?: string | null // 默认为 null + // 更新日期 + updated_day?: string + // 更新时间 + updated_time?: string } // 正在下载 diff --git a/src/components/dialog/SiteUserDataDialog.vue b/src/components/dialog/SiteUserDataDialog.vue index 67aba6ad..0ad530e4 100644 --- a/src/components/dialog/SiteUserDataDialog.vue +++ b/src/components/dialog/SiteUserDataDialog.vue @@ -1,7 +1,11 @@ diff --git a/src/components/dialog/UserAddEditDialog.vue b/src/components/dialog/UserAddEditDialog.vue index c0ec2e1b..8b1615a5 100644 --- a/src/components/dialog/UserAddEditDialog.vue +++ b/src/components/dialog/UserAddEditDialog.vue @@ -218,14 +218,14 @@ watch(() => store.state.auth.avatar, () => { - + - 还原当前头像 + 重置 - - 重置默认头像 + + 默认 diff --git a/src/views/user/UserProfileView.vue b/src/views/user/UserProfileView.vue index f2db1bf0..6d55a61c 100644 --- a/src/views/user/UserProfileView.vue +++ b/src/views/user/UserProfileView.vue @@ -1,12 +1,12 @@