1、地址栏请求参数的截取
function getQueryVariable(variable) {
var query = window.location.href.split('?')[1];
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1] ? pair[1].replace('#/', '') : '';
}
}
return '';
}
2、将标准时间Thu Nov 11 2021 17:39:28 GMT+0800 (中国标准时间)转化为:2021-10-11 00:00:00 的形式
function getFomatData(time, flag) {
let date = new Date(time);
let myyear = date.getFullYear();
let mymonth = date.getMonth() + 1;
let myweekday = date.getDate();
mymonth = mymonth < 10 ? ('0' + mymonth) : mymonth;
myweekday = myweekday < 10 ? ('0' + myweekday) : myweekday;
let yymmdd = myyear + '-' + mymonth + '-' + myweekday;
if (flag === 's') {
yymmdd += ' 00:00:00'
} else if (flag === 'e') {
yymmdd += ' 23:59:59'
}
return yymmdd
}
3、文件上传
function fileUpload(url, params, callback, callParam, transParam, uploadCallback, errMethod) {
axios
.post(url, params, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then((res) => {
if (res.data.head.resultcode === '0') {
callback && callback(res, callParam, transParam, uploadCallback);
} else {
callParam.loading = false;
callParam.recordLoadingFlag = false
errMethod && errMethod(res, callParam, );
}
})
.catch((err) => {
callParam.loading = false;
callParam.recordLoadingFlag = false
errMethod && errMethod(err, callParam);
});
}