Files
yinmeng-admin-web/src/utils/maintainer.js
2023-12-22 15:52:51 +08:00

71 lines
1.8 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 param(json) {
if (!json) return ''
return cleanArray(Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' +
encodeURIComponent(json[key])
})).join('&')
}
export function buildSelectOption(id, defVal, array) {
let $select = $(id);
for(let i in array) {
let obj = array[i];
let selected = false;
if (obj.value == defVal) {
selected = true;
}
$select.append('<option value="' + obj.value + '"' + (selected ? 'selected' : '') + '>' + obj.text + '</option>');
}
}