|
|
|
@ -70,29 +70,70 @@ Array.prototype.exchange = function (val1, val2) {
|
|
|
|
|
this.splice(val1, 1, o2);
|
|
|
|
|
this.splice(val2, 1, o1);
|
|
|
|
|
};
|
|
|
|
|
window.utils = {};
|
|
|
|
|
window.utils.downBlob = function (name, blob) {
|
|
|
|
|
window.utils = {
|
|
|
|
|
/**
|
|
|
|
|
* 隐藏文件选择器
|
|
|
|
|
*
|
|
|
|
|
* @param cb 回调函数
|
|
|
|
|
*/
|
|
|
|
|
selectFile: function (cb) {
|
|
|
|
|
var input = document.createElement('input');
|
|
|
|
|
input.style.display = 'none';
|
|
|
|
|
input.type = "file";
|
|
|
|
|
document.body.appendChild(input);
|
|
|
|
|
input.dispatchEvent(new MouseEvent('click'));
|
|
|
|
|
input.onchange = function (ev) {
|
|
|
|
|
cb(ev.target.files);
|
|
|
|
|
document.body.removeChild(input);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Blob二进制文件异步下载
|
|
|
|
|
*
|
|
|
|
|
* @param name 文件名
|
|
|
|
|
* @param blob 二进制文件
|
|
|
|
|
*/
|
|
|
|
|
blobtoDown: function (name, blob) {
|
|
|
|
|
var url = window.URL.createObjectURL(blob);
|
|
|
|
|
console.log(url)
|
|
|
|
|
var link = document.createElement('a')
|
|
|
|
|
var link = document.createElement('a');
|
|
|
|
|
link.style.display = 'none';
|
|
|
|
|
link.href = url;
|
|
|
|
|
link.setAttribute('download', name)
|
|
|
|
|
link.setAttribute('download', name);
|
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
var evt = document.createEvent("MouseEvents");
|
|
|
|
|
evt.initEvent("click", false, false);
|
|
|
|
|
link.dispatchEvent(evt);
|
|
|
|
|
link.dispatchEvent(new MouseEvent('click'));
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
};
|
|
|
|
|
window.utils.base64toString = function (base64) {
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* base64转为String
|
|
|
|
|
*
|
|
|
|
|
* @param base64 base64字符串
|
|
|
|
|
* @returns {string} 字符串
|
|
|
|
|
*/
|
|
|
|
|
base64toString: function (base64) {
|
|
|
|
|
return window.atob(base64);
|
|
|
|
|
};
|
|
|
|
|
window.utils.base64toBytes = function (base64) {
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* base64转为字节数组
|
|
|
|
|
*
|
|
|
|
|
* @param base64 base64字符串
|
|
|
|
|
* @returns {string} 字节数组
|
|
|
|
|
*/
|
|
|
|
|
base64toBytes: function (base64) {
|
|
|
|
|
var str = window.atob(base64);
|
|
|
|
|
var len = str.length;
|
|
|
|
|
var bytes = new Int8Array(len)
|
|
|
|
|
var bytes = new Int8Array(len);
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
bytes[i] = str.charCodeAt(i);
|
|
|
|
|
}
|
|
|
|
|
return bytes;
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param base64
|
|
|
|
|
* @returns {Int8Array}
|
|
|
|
|
*/
|
|
|
|
|
base64toBlob: function (base64) {
|
|
|
|
|
return new Blob(this.base64toBytes(base64));
|
|
|
|
|
}
|
|
|
|
|
}
|