wujingjing
2025-03-10 0159386060edb946f29b5adcd9659dbfac06d6e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { ElMessage } from 'element-plus';
import { GetImageThumbTool } from '/@/api/artImage/artImageTool';
import { MAIN_URL } from '/@/constants';
import type { BankImage } from '/@/projectCom/artImage/bank/image/types';
 
export const getFullFilePath = (url, fileName) => {
    return `${url}/${fileName}`;
};
 
export const getBankImageUrl = (bankImage: BankImage, isRelative = false, baseUrl = MAIN_URL) => {
    const urlArr = bankImage?.StorageHouse ? [bankImage?.StorageHouse, bankImage?.StorageCode] : [bankImage?.StorageCode];
    if (!isRelative) {
        urlArr.unshift(baseUrl);
    }
    const fullPath = urlArr.join('/');
    return fullPath;
};
 
export type FileRecordObj = {
    StorageCode: string;
    StorageHouse: string;
    [key: string]: any;
};
export const getFileUrl = (fileObj: FileRecordObj, isRelative = false, baseUrl = MAIN_URL) => {
    const urlArr = fileObj?.StorageHouse ? [fileObj?.StorageHouse, fileObj?.StorageCode] : [fileObj?.StorageCode];
    if (!isRelative) {
        urlArr.unshift(baseUrl);
    }
    const fullPath = urlArr.join('/');
    return fullPath;
};
 
 
/**
 * 文件大小字节转换为XXX
 * @param size 字节大小
 * @returns {string|*}
 */
export const convertFileSize = (size) => {
    if (!size && size !== 0) return '';
    if (size < pow1024(1)) return size + ' B';
    if (size < pow1024(2)) return (size / pow1024(1)).toFixed(2) + ' KB';
    if (size < pow1024(3)) return (size / pow1024(2)).toFixed(2) + ' MB';
    if (size < pow1024(4)) return (size / pow1024(3)).toFixed(2) + ' GB';
    return (size / pow1024(4)).toFixed(2) + ' TB';
};
 
// 求次幂
function pow1024(num) {
    return Math.pow(1024, num);
}