lib.js精简

master
王兵 4 years ago
parent 0df1b11421
commit 513756136c

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,10 +1,8 @@
<jscompress public="http://www.jscompress.cn/" command="import-combineset"> <jscompress public="http://www.jscompress.cn/" command="import-combineset">
<combinefile path="lib.js"> <combinefile path="lib.js">
<auto value="1" /> <auto value="1" />
<sourcefile path="..\js\jquery.js" /> <sourcefile path=".\source\vue.js" />
<sourcefile path="..\js\vue.js" /> <sourcefile path=".\source\axios.js" />
<sourcefile path="..\js\vue-router.js" /> <sourcefile path=".\source\base.js" />
<sourcefile path="..\js\axios.js" />
<sourcefile path="..\js\base.js" />
</combinefile> </combinefile>
</jscompress> </jscompress>

File diff suppressed because one or more lines are too long

@ -1,7 +1,111 @@
/** /* 常用的便捷函数集合 */
* 获取url参数 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);
var link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', name);
document.body.appendChild(link);
link.dispatchEvent(new MouseEvent('click'));
document.body.removeChild(link);
},
/**
* base64转为String
* @param base64 base64字符串
* @returns {string} 字符串
*/
base64toString: function (base64) {
return window.atob(base64);
},
/**
* String转为base64
*
* @param base64 base64字符串
* @returns {string} 字符串
*/
stringtoBase64: function (str) {
return window.btoa(str);
},
/**
* base64转为字节数组
* @param base64 base64字符串
* @returns {string} 字节数组
*/
base64toBytes: function (base64) {
var str = window.atob(base64);
var len = str.length;
var bytes = new Int8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = str.charCodeAt(i);
}
return bytes;
},
/**
* base64字符转Blob对象
* @param base64
* @returns {Int8Array}
*/
base64toBlob: function (base64) {
return new Blob(this.base64toBytes(base64));
},
isEmpty: function (val) {
return val === '' || typeof val === 'undefined' || val === null;
},
/**
* 动态加载Js或css文件
* @param url 文件http地址
*/
loadJsCss: function (url) {
var node_;
if (url.match(/\\.js$/i)) {
node_ = document.createElement('script');
node_.setAttribute("type", "text/javascript");
node_.setAttribute("src", url);
} else if (url.match(/\\.css$/i)) {
node_ = document.createElement('link');
node_.setAttribute("rel", "stylesheet");
node_.setAttribute("type", "text/css");
node_.setAttribute("href", url);
}
if (node_) {
document.getElementsByTagName("head")[0].appendChild(node_);
} else {
console.error("load " + url + " method error!");
}
},
/**
* 深拷贝对象
* @param obj
*/
copy: function (obj) {
return JSON.parse(JSON.stringify(obj));
}
}
/**
* 获取参数
* @param key * @param key
* @returns {*}
*/ */
window.location.getParam = function (key) { window.location.getParam = function (key) {
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)"); var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
@ -13,22 +117,27 @@ window.location.getParam = function (key) {
} }
/** /**
* 打开新地址 * 打开新地址
*
* @param url * @param url
*/ */
window.location.open = function (url) { window.location.open = function (url) {
$("body").append($("<a id='wb-open' href='" + url + "' target='_self' style='display:none;'></a>")) var el = document.createElement("a");
document.getElementById("wb-open").click(); el.href = url;
$("#wb-open").remove(); el.target = "_self";
el.style.display = "none";
el.click();
document.body.removeChild(el)
} }
/** /**
* 打开新标签 * 打开新标签
* @param url * @param url
*/ */
window.location.openNew = function (url) { window.location.openNew = function (url) {
$("body").append($("<a id='wb-open' href='" + url + "' target='_blank' style='display:none;'></a>")) var el = document.createElement("a");
document.getElementById("wb-open").click(); el.href = url;
$("#wb-open").remove(); el.target = "_blank";
el.style.display = "none";
el.click();
document.body.removeChild(el);
} }
/** /**
* 日期格式化 * 日期格式化
@ -198,114 +307,4 @@ function Map() {
this.getValues = function () { this.getValues = function () {
return this.values.slice(0, this.values.length); return this.values.slice(0, this.values.length);
}; };
}; };
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);
var link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', name);
document.body.appendChild(link);
link.dispatchEvent(new MouseEvent('click'));
document.body.removeChild(link);
},
/**
* base64转为String
*
* @param base64 base64字符串
* @returns {string} 字符串
*/
base64toString: function (base64) {
return window.atob(base64);
},
/**
* String转为base64
*
* @param base64 base64字符串
* @returns {string} 字符串
*/
stringtoBase64: function (str) {
return window.btoa(str);
},
/**
* base64转为字节数组
*
* @param base64 base64字符串
* @returns {string} 字节数组
*/
base64toBytes: function (base64) {
var str = window.atob(base64);
var len = str.length;
var bytes = new Int8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = str.charCodeAt(i);
}
return bytes;
},
/**
* base64字符转Blob对象
*
* @param base64
* @returns {Int8Array}
*/
base64toBlob: function (base64) {
return new Blob(this.base64toBytes(base64));
},
isEmpty: function (val) {
return val === '' || typeof val === 'undefined' || val === null;
},
/**
* 动态加载Js或css文件
*
* @param url 文件http地址
*/
loadJsCss: function (url) {
var node_;
if (url.match(/\\.js$/i)) {
node_ = document.createElement('script');
node_.setAttribute("type", "text/javascript");
node_.setAttribute("src", url);
} else if (url.match(/\\.css$/i)) {
node_ = document.createElement('link');
node_.setAttribute("rel", "stylesheet");
node_.setAttribute("type", "text/css");
node_.setAttribute("href", url);
}
if (node_) {
document.getElementsByTagName("head")[0].appendChild(node_);
} else {
console.error("load " + url + " method error!");
}
},
/**
* 深拷贝对象
*
* @param obj
*/
copy: function (obj) {
return JSON.parse(JSON.stringify(obj));
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save

Powered by TurnKey Linux.