Files
peko-admin-web/src/utils/maintainer.js
2024-02-27 21:39:13 +08:00

59 lines
1.5 KiB
JavaScript

export function showLoading() {
$(".loadingGif").css('top', window.innerHeight / 2);
$(".loadingGif").css('left', window.innerWidth / 2);
$(".loading").css('z-index', 3000);
$(".loading").modal('show');
}
export function hideLoading() {
$(".loading").modal('hide');
}
export function formatTime(val) {
var date;
if (val) {
// 兼容Safari
var userAgent = navigator.userAgent;
if (userAgent.indexOf('Version') > -1) {
date = new Date(val.split('+')[0]);
} else {
date = new Date(val);
}
return date.format('yyyy-MM-dd hh:mm:ss');
} else {
return '';
}
}
export function cleanArray(actual) {
const newArray = []
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
newArray.push(actual[i])
}
}
return newArray
}
export function serverError(req) {
$("#tipMsg").text(req.responseJSON.message);
$("#tipModal").modal('show');
}
export function apiResult(json) {
if (json.code == 200 && json.message == 'success') {
return true;
}
$("#tipMsg").text("请求失败,错误信息:" + json.message);
$("#tipModal").modal('show');
return false;
}
export function genQueryParam(json) {
if (!json) return ''
return cleanArray(Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' +
encodeURIComponent(json[key])
})).join('&');
}