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