IYUUPlus/public/js/function.js
2021-02-02 15:48:07 +08:00

60 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 根据ID获取DOM元素对象
* @param {string} id
*/
function getById(id) {
return document.getElementById(id);
}
/**
* 格式化Layui输入框数组
* @description 适用于input 、checkbox 、 switch
* @param {string} field 待格式化的字段
* @param {object} obj 数据对象
*/
function format_input(field, obj) {
for (let key in obj[field]) {
let k = field +'['+ key +']';
obj[k] = obj[field][key];
}
return obj;
}
/**
* 包装的Ajax请求
* @param {string} url URL
* @param {object} fd 表单数据
* @param {string} msg 成功后提示消息
* @param {boolean} reload 成功后是否刷新窗口
*/
function ajax(url, fd, msg, reload) {
let $ = layui.jquery;
$.ajax({
url: url,
type: "POST",
data: fd,
success: function (d) {
console.log(d);
if (d.ret === 200) {
layer.msg(msg, function () {
if(reload) {
window.location.reload();
} else {
return true;
}
});
} else {
if (d.msg.length > 0) {
layer.alert(d.msg, {icon: 2, title: '出错提示'});
} else {
layer.alert('未知错误请截图当前界面然后求助于QQ群859882209、931954050、924099912', {icon: 2, title: '出错提示'});
}
}
},
complete: function () {
},
error : function(request) {
layer.alert('未知错误请截图当前界面然后求助于QQ群859882209、931954050、924099912', {icon: 2, title: '出错提示'});
}
});
}