oak-general-business/lib/utils/extraFile.js

54 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bytesToSize = exports.getFileURL = void 0;
//获取file文件url
function getFileURL(file) {
let getUrl = '';
// @ts-ignore
if (window.createObjectURL !== undefined) {
// basic
// @ts-ignore
getUrl = window.createObjectURL(file);
}
else if (window.URL !== undefined) {
// mozilla(firefox)
getUrl = window.URL.createObjectURL(file);
}
else if (window.webkitURL !== undefined) {
// webkit or chrome
getUrl = window.webkitURL.createObjectURL(file);
}
return getUrl;
}
exports.getFileURL = getFileURL;
function bytesToSize(size) {
let data = '';
if (size < 0.1 * 1024) {
//小于0.1KB则转化成B
data = size.toFixed(2) + 'B';
}
else if (size < 0.1 * 1024 * 1024) {
// 小于0.1MB则转化成KB
data = (size / 1024).toFixed(2) + 'KB';
}
else if (size < 0.1 * 1024 * 1024 * 1024) {
// 小于0.1GB则转化成MB
data = (size / (1024 * 1024)).toFixed(2) + 'MB';
}
else {
// 其他转化成GB
data = (size / (1024 * 1024 * 1024)).toFixed(2) + 'GB';
}
// 转成字符串
let sizeStr = data + '',
// 获取小数点处的索引
index = sizeStr.indexOf('.'),
// 获取小数点后两位的值
dou = sizeStr.substring(index + 1, 2);
// 判断后两位是否为00如果是则删除00
if (dou == '00')
return sizeStr.substring(0, index) + sizeStr.substring(index + 3, 2);
return sizeStr;
}
exports.bytesToSize = bytesToSize;