112 lines
3.3 KiB
JavaScript
112 lines
3.3 KiB
JavaScript
|
|
const dataUrl = 'http://127.0.0.1:21995/';
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/* 请求 */
|
|||
|
|
function ajaxRequest(url, type, data, async, beforeFn, successFn, errorFn, contentType) {
|
|||
|
|
$.ajax({
|
|||
|
|
url: url,
|
|||
|
|
type: type,
|
|||
|
|
headers: {
|
|||
|
|
"authorization": sessionStorage.getItem("gz-token"),
|
|||
|
|
},
|
|||
|
|
data: data,
|
|||
|
|
async: async,
|
|||
|
|
beforeSend: beforeFn,
|
|||
|
|
contentType: contentType || "application/x-www-form-urlencoded; charset=utf-8",
|
|||
|
|
success: function (data){
|
|||
|
|
successFn(data);
|
|||
|
|
},
|
|||
|
|
error:function (error) {
|
|||
|
|
errorFn(error)
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* 文件上传请求 */
|
|||
|
|
function ajaxRequestByUploadFile(url, data, beforeFn, successFn, errorFn) {
|
|||
|
|
$.ajax({
|
|||
|
|
url: url,
|
|||
|
|
headers: {
|
|||
|
|
"authorization": sessionStorage.getItem("gz-token"),
|
|||
|
|
},
|
|||
|
|
type: 'POST',
|
|||
|
|
dataType: 'json',
|
|||
|
|
processData: false,
|
|||
|
|
contentType: false,
|
|||
|
|
data: data,
|
|||
|
|
beforeSend: beforeFn,
|
|||
|
|
success: function (data){
|
|||
|
|
successFn(data);
|
|||
|
|
},
|
|||
|
|
error:function (error) {
|
|||
|
|
errorFn(error)
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* 请求错误 */
|
|||
|
|
function errorFn(xhr, status, error) {
|
|||
|
|
if (xhr.status === 0) {
|
|||
|
|
// 网络连接失败
|
|||
|
|
console.error("网络连接失败,请检查网络是否正常");
|
|||
|
|
} else {
|
|||
|
|
// 请求出现其他错误
|
|||
|
|
console.error("ajax请求错误:" + error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 公共导出excel
|
|||
|
|
function exportExcelUtil(url,fileName) {
|
|||
|
|
let loadingMsg = layer.msg("数据导出中,请稍候...", { icon: 16, scrollbar: false, time: 0, });
|
|||
|
|
let xhr = new XMLHttpRequest();
|
|||
|
|
xhr.open("get", url, true);
|
|||
|
|
xhr.responseType = "blob"; // 转换流
|
|||
|
|
xhr.setRequestHeader("encauthorizationypt",sessionStorage.getItem("gz-token"));
|
|||
|
|
xhr.onload = function () {
|
|||
|
|
layer.close(loadingMsg);
|
|||
|
|
if (this.status === 200) {
|
|||
|
|
let blob = this.response;
|
|||
|
|
var a = document.createElement("a");
|
|||
|
|
var url = window.URL.createObjectURL(blob);
|
|||
|
|
a.href = url;
|
|||
|
|
a.download = "机具公司发货" + getNowDate() + ".xlsx"; // 文件名
|
|||
|
|
} else {
|
|||
|
|
layer.msg("数据发生异常,请稍后重试", { icon: 16, scrollbar: false, time: 2000 });
|
|||
|
|
}
|
|||
|
|
a.click();
|
|||
|
|
window.URL.revokeObjectURL(url);
|
|||
|
|
};
|
|||
|
|
xhr.send();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 格式化日对象
|
|||
|
|
const getNowDate = () => {
|
|||
|
|
var date = new Date();
|
|||
|
|
var sign2 = "-";
|
|||
|
|
var year = date.getFullYear() // 年
|
|||
|
|
var month = date.getMonth() + 1; // 月
|
|||
|
|
var day = date.getDate(); // 日
|
|||
|
|
var hour = date.getHours(); // 时
|
|||
|
|
var minutes = date.getMinutes(); // 分
|
|||
|
|
var seconds = date.getSeconds() //秒
|
|||
|
|
var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
|
|||
|
|
var week = weekArr[date.getDay()];
|
|||
|
|
// 给一位数的数据前面加 “0”
|
|||
|
|
if (month >= 1 && month <= 9) {
|
|||
|
|
month = "0" + month;
|
|||
|
|
}
|
|||
|
|
if (day >= 0 && day <= 9) {
|
|||
|
|
day = "0" + day;
|
|||
|
|
}
|
|||
|
|
if (hour >= 0 && hour <= 9) {
|
|||
|
|
hour = "0" + hour;
|
|||
|
|
}
|
|||
|
|
if (minutes >= 0 && minutes <= 9) {
|
|||
|
|
minutes = "0" + minutes;
|
|||
|
|
}
|
|||
|
|
if (seconds >= 0 && seconds <= 9) {
|
|||
|
|
seconds = "0" + seconds;
|
|||
|
|
}
|
|||
|
|
return year + "-" + month + "-" + day + "-" + hour + sign2 + minutes + sign2 + seconds;
|
|||
|
|
}
|