添加页面及附件查看

This commit is contained in:
zhengw
2026-02-04 11:42:19 +08:00
parent 1c0e0b265d
commit e10c7bc537
34 changed files with 817 additions and 68 deletions

View File

@@ -136,6 +136,29 @@ export const isImageFile = (path: string) => {
return /\.(jpe?g|png|gif|svg|webp|bmp)$/i.test(path);
};
export const isPDFFile = (path: string) => {
return /\.(pdf)$/i.test(path);
};
/** 判断是不是Excel */
export const isExcelFile = (path: string) => {
return /\.(xlsx|xls)$/i.test(path);
};
/** 获取文件类型 */
export const getFileType = (path: string): 'file' | 'image' | 'excel' | 'pdf' => {
if (typeof path == 'string') {
if (isExcelFile(path)) {
return 'excel';
} else if (isImageFile(path)) {
return 'image';
} else if (isPDFFile(path)) {
return 'pdf';
}
}
return 'file';
};
/** 滚动到顶部 */
export const scrollToTop = () => {
wx.pageScrollTo({ scrollTop: 0 });
@@ -347,3 +370,16 @@ export const sleep = (callback?: () => void, ms = 300): Promise<boolean> => {
};
export const cloneLite = (data: any) => JSON.parse(JSON.stringify(data));
/** 转换文件大小 */
export const formatFileSize = (fileSize: any): string => {
const file_size = toNumber(fileSize);
if (file_size == 0) {
return '0B';
}
const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let index = 0;
index = Math.floor(Math.log(file_size) / Math.log(1024));
const size = file_size / 1024 ** index;
return size.toFixed(0) + unitArr[index];
};