前端: 添加工具函数
This commit is contained in:
parent
892e5acd50
commit
e61f2d061f
25
frontend/src/renderer/utils/helpers.js
Normal file
25
frontend/src/renderer/utils/helpers.js
Normal file
@ -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);
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user