From e61f2d061f738d29c0ff2a74464635df83e57647 Mon Sep 17 00:00:00 2001 From: Frontend Developer Date: Tue, 10 Mar 2026 09:20:35 +0000 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/renderer/utils/helpers.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 frontend/src/renderer/utils/helpers.js diff --git a/frontend/src/renderer/utils/helpers.js b/frontend/src/renderer/utils/helpers.js new file mode 100644 index 0000000..0d9f98c --- /dev/null +++ b/frontend/src/renderer/utils/helpers.js @@ -0,0 +1,25 @@ +export const formatFileSize = (bytes) => { + if (!bytes) return '0 B'; + const units = ['B', 'KB', 'MB', 'GB', 'TB']; + const i = Math.floor(Math.log(bytes) / Math.log(1024)); + return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${units[i]}`; +}; + +export const formatDate = (date) => { + if (!date) return ''; + return new Date(date).toLocaleDateString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit' + }); +}; + +export const getFileExt = (filename) => { + return filename?.split('.').pop()?.toLowerCase() || ''; +}; + +export const generateId = () => { + return Date.now().toString(36) + Math.random().toString(36).substr(2); +};