function dealDate(timestamp) {
console.log(timestamp)
if (timestamp == null || timestamp == "") {
return timestamp
}
let date = new Date(timestamp),
Y = date.getFullYear() + '-',
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-',
D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ',
h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':',
m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':',
s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
return Y + M + D + h + m + s;
}
处理URL,返回form传递来的参数
function getRequest(urlStr) {
if (typeof urlStr == "undefined") {
var url = decodeURI(location.search); //获取url中"?"符后的字符串
} else {
var url = "?" + urlStr.split("?")[1];
}
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
return theRequest;
}
拆分数组
// 数组 拆分长度
function arrayChunk(array, size) {
if (size === "number") {}
let data = []
for (let i = 0; i < array.length; i += size) {
data.push(array.slice(i, i + size))
}
return data
}
获取系统时间 (年月日)
function gettime() {
var myDate = new Date;
var year = myDate.getFullYear(); //获取当前年
var yue = myDate.getMonth() + 1; //获取当前月
var date = myDate.getDate(); //获取当前日
if (yue < 10) {
yue = "0" + yue
}
if (date < 10) {
date = "0" + date
}
return year + "-" + yue + "-" + date;
}
ecxal文件导入
var wb; //读取
var rABS = false;
//开始导入 ShowJson 显示json数据的标签的id
function importf(obj, ShowJson) {
if (!obj.files) {
return;
}
var f = obj.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
if (rABS) {
wb = XLSX.read(btoa(fixdata(data)), { //手动转化
type: 'base64'
});
} else {
wb = XLSX.read(data, {
type: 'binary'
});
}
/**
* wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
* wb.Sheets[Sheet名]获取第一个Sheet的数据
*/
var excelJson = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
document.getElementById(ShowJson).innerHTML = JSON.stringify(excelJson);
};
if (rABS) {
reader.readAsArrayBuffer(f);
} else {
reader.readAsBinaryString(f);
}
}
//文件流转BinaryString
function fixdata(data) {
var o = "",
l = 0,
w = 10240;
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w +
w)));
o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
return o;
}