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); +};