|
//显示
function init() {
if (!window.localStorage) {
console.log('浏览器不支持localStorage, 请更换浏览器');
$('#loading').modal('show');
$("#resultLoading").html("初始化失败, 请更换浏览器(如Edge, Chrome)");
} else {
// console.log(window.sessionStorage.getItem("loading"));
if (window.sessionStorage.getItem("loading") == null || window.localStorage.getItem("salesData") == null) {
$('#loading').modal('show');
storageSalesData();
}
}
}
/**
* 获取销售数据表里的数据并存入浏览器不支持localStorage
*/
function storageSalesData(refresh = false) {
console.log(refresh);
$.ajax({
url: "/index/index/sales_data",
// async: false, //改为同步方式
type: "post",
data: {},
dataType: 'json',
success: function (res) {
if (res.code == 0) {
window.sessionStorage.setItem('loading', 1);
window.localStorage.setItem('salesData', JSON.stringify(res.data));
console.log(refresh);
if (refresh) {
alert('数据刷新成功');
} else {
setTimeout(function(){ $('#loading').modal('hide'); }, 1000);
}
} else {
console.log('销售数据获取失败');
$("#resultLoading").html("初始化失败, 请稍后重试");
}
},
error: function (res) {
console.log('数据请求失败');
$("#resultLoading").html("初始化失败, 请稍后重试");
}
});
}
// 隐藏
// function close() {
// setTimeout(function(){ $('#loading').modal('hide'); }, 1000);
// }
|