2022-12-02 11:16:57 +08:00
|
|
|
/*!
|
2023-08-04 11:06:34 +08:00
|
|
|
* center For Home - v1.0.0 - 2022-10-10
|
2022-12-02 11:16:57 +08:00
|
|
|
* https://github.com/meystack/swiftadmin
|
|
|
|
|
* Copyright (c) meystack
|
|
|
|
|
* Licensed Apache2.0
|
2022-08-19 19:48:37 +08:00
|
|
|
*/
|
2022-12-02 11:16:57 +08:00
|
|
|
layui.use(['jquery', 'form', 'upload', 'table', 'dropdown'], function () {
|
2022-08-19 19:48:37 +08:00
|
|
|
|
|
|
|
|
let $ = layui.$;
|
|
|
|
|
let form = layui.form;
|
|
|
|
|
let layer = layui.layer;
|
2022-11-28 19:11:12 +08:00
|
|
|
let table = layui.table;
|
2022-08-19 19:48:37 +08:00
|
|
|
let upload = layui.upload;
|
2022-11-28 19:11:12 +08:00
|
|
|
let dropdown = layui.dropdown;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 短消息下拉框
|
|
|
|
|
* @param count
|
|
|
|
|
*/
|
|
|
|
|
window.bellMessage = function (count) {
|
2022-12-02 11:16:57 +08:00
|
|
|
dropdown.render({
|
2022-11-28 19:11:12 +08:00
|
|
|
elem: '#notice'
|
|
|
|
|
, trigger: 'hover'
|
|
|
|
|
, align: 'center'
|
|
|
|
|
, data: [{
|
|
|
|
|
title: !count ? '暂无消息' : '您有<b class="msg">' + count + '</b>条未读消息'
|
|
|
|
|
}], ready: function (elemPanel, elem) {
|
|
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
, click: function (data, index) {
|
2022-11-28 19:11:12 +08:00
|
|
|
let elem = $('.layui-nav-tree li [lay-href="/user/message"]');
|
|
|
|
|
$(elem).parents('.layui-nav-item').addClass('layui-nav-itemed');
|
|
|
|
|
$(elem).trigger('click');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-19 19:48:37 +08:00
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
/**
|
|
|
|
|
* 前端全局对象
|
|
|
|
|
* @access object
|
|
|
|
|
* screen: 屏幕宽度
|
|
|
|
|
* event: 事件对象
|
|
|
|
|
* Cookie: Cookie操作对象
|
|
|
|
|
* */
|
2022-08-19 19:48:37 +08:00
|
|
|
window.Home = {
|
2022-12-02 11:16:57 +08:00
|
|
|
screen: function () {
|
|
|
|
|
let width = $(window).width()
|
|
|
|
|
if (width > 1200) {
|
2022-08-19 19:48:37 +08:00
|
|
|
return 3; //大屏幕
|
2022-12-02 11:16:57 +08:00
|
|
|
} else if (width > 992) {
|
2022-08-19 19:48:37 +08:00
|
|
|
return 2; //中屏幕
|
2022-12-02 11:16:57 +08:00
|
|
|
} else if (width > 768) {
|
2022-08-19 19:48:37 +08:00
|
|
|
return 1; //小屏幕
|
|
|
|
|
} else {
|
|
|
|
|
return 0; //超小屏幕
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
event: {
|
2022-12-02 11:16:57 +08:00
|
|
|
closeDialog: function (that) {
|
2022-08-19 19:48:37 +08:00
|
|
|
that = that || this;
|
|
|
|
|
let _type = $(that).parents(".layui-layer").attr("type");
|
|
|
|
|
if (typeof _type === "undefined") {
|
|
|
|
|
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
2022-12-02 11:16:57 +08:00
|
|
|
} else {
|
2022-08-19 19:48:37 +08:00
|
|
|
let layerId = $(that).parents(".layui-layer").attr("id").substring(11);
|
|
|
|
|
layer.close(layerId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// cookie
|
2022-12-02 11:16:57 +08:00
|
|
|
Cookie: { // 获取cookies
|
2022-08-19 19:48:37 +08:00
|
|
|
'Set': function (name, value, days) {
|
|
|
|
|
let exp = new Date();
|
|
|
|
|
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
|
2022-12-02 11:16:57 +08:00
|
|
|
document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
|
2022-08-19 19:48:37 +08:00
|
|
|
document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toUTCString();
|
|
|
|
|
},
|
|
|
|
|
'Get': function (name) {
|
|
|
|
|
let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
|
|
|
|
|
if (arr != null) {
|
|
|
|
|
return unescape(arr[2]);
|
|
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
return null;
|
2022-08-19 19:48:37 +08:00
|
|
|
},
|
|
|
|
|
'Del': function (name) {
|
|
|
|
|
let exp = new Date();
|
|
|
|
|
exp.setTime(exp.getTime() - 1);
|
|
|
|
|
let cval = this.Get(name);
|
|
|
|
|
if (cval != null) {
|
|
|
|
|
document.cookie = name + "=" + escape(cval) + ";path=/;expires=" + exp.toUTCString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
/**
|
|
|
|
|
* 监听全局form表单提交
|
|
|
|
|
* @param data
|
|
|
|
|
* @param callback
|
|
|
|
|
* @type button lay-filter="submitIframe"
|
|
|
|
|
*/
|
|
|
|
|
form.on('submit(submitIframe)', function (data) {
|
2022-08-19 19:48:37 +08:00
|
|
|
let that = $(this), _form = that.parents('form'),
|
|
|
|
|
_url = _form.attr("action") || false,
|
|
|
|
|
_close = that.data("close") || undefined,
|
|
|
|
|
_reload = that.data('reload');
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
// 开启节流
|
|
|
|
|
that.attr("disabled", true);
|
2023-08-04 11:06:34 +08:00
|
|
|
setTimeout(function () {
|
|
|
|
|
that.attr("disabled", false);
|
|
|
|
|
}, 2000);
|
2022-12-02 11:16:57 +08:00
|
|
|
$.post(_url,
|
|
|
|
|
data.field, function (res) {
|
|
|
|
|
if (res.code === 200) {
|
2022-08-19 19:48:37 +08:00
|
|
|
top.layer.msg(res.msg);
|
|
|
|
|
switch (_reload) {
|
|
|
|
|
case 'top':
|
|
|
|
|
top.location.reload();
|
|
|
|
|
break;
|
|
|
|
|
case 'parent':
|
|
|
|
|
parent.location.reload();
|
|
|
|
|
break;
|
|
|
|
|
case 'self':
|
|
|
|
|
location.reload();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof res.url !== 'undefined' && res.url) {
|
|
|
|
|
location.href = res.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 默认关闭
|
|
|
|
|
if (_close === undefined) {
|
|
|
|
|
Home.event.closeDialog(that);
|
|
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
} else {
|
2023-08-04 11:06:34 +08:00
|
|
|
top.layui.layer.msg(res.msg, {icon: 5});
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
/**
|
|
|
|
|
* token重载下
|
|
|
|
|
* 框架也需要更新
|
|
|
|
|
*/
|
|
|
|
|
if (typeof res.data.__token__ !== 'undefined') {
|
|
|
|
|
$('input#__token__').val(res.data.__token__);
|
|
|
|
|
}
|
2023-08-04 11:06:34 +08:00
|
|
|
} catch (e) {}
|
2022-08-19 19:48:37 +08:00
|
|
|
}, 'json');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 监听form表单搜索
|
2022-12-02 11:16:57 +08:00
|
|
|
* 默认表格ID: lay-tableList
|
2022-08-19 19:48:37 +08:00
|
|
|
*/
|
|
|
|
|
form.on('submit(formSearch)', function (data) {
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
let field = data.field;
|
2022-08-19 19:48:37 +08:00
|
|
|
for (const key in field) {
|
|
|
|
|
if (!field[key]) {
|
|
|
|
|
delete field[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layui.table.reload('lay-tableList', {
|
|
|
|
|
page: {curr: 1},
|
|
|
|
|
where: field
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 监听全局事件
|
|
|
|
|
$(document).on("click", "*[sa-event]", function () {
|
|
|
|
|
let name = $(this).attr("sa-event");
|
|
|
|
|
let obj = Home.event[name];
|
|
|
|
|
obj && obj.call(this, $(this));
|
|
|
|
|
});
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
let uploadURL = '/index/user/upload';
|
2022-08-19 19:48:37 +08:00
|
|
|
layui.each($('*[lay-upload]'), function (index, elem) {
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
let that = $(this),
|
2022-08-19 19:48:37 +08:00
|
|
|
name = $(elem).attr('lay-upload') || undefined,
|
|
|
|
|
type = $(elem).data('type') || 'normal',
|
|
|
|
|
size = $(elem).data('size') || 51200, // 限制最大5M
|
2022-12-02 11:16:57 +08:00
|
|
|
accept = $(elem).data('accept') || 'file';
|
2022-08-19 19:48:37 +08:00
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
// 文件上传回调
|
|
|
|
|
let uploadFiles = {
|
2022-08-19 19:48:37 +08:00
|
|
|
normal: function (res, name) {
|
|
|
|
|
$('input.' + name).prop('value', res.url);
|
|
|
|
|
$('img.' + name).prop('src', res.url);
|
|
|
|
|
},
|
|
|
|
|
images: function (res, name) {
|
2022-12-02 11:16:57 +08:00
|
|
|
let o = $('img.' + name);
|
2022-08-19 19:48:37 +08:00
|
|
|
o.prop('src', res.url);
|
|
|
|
|
o.parent('div').removeClass('layui-hide');
|
|
|
|
|
$('input.' + name).val(res.url);
|
|
|
|
|
$(elem).find('p,i,hr').addClass('layui-hide');
|
|
|
|
|
},
|
|
|
|
|
multiple: function (res, name) {
|
2022-12-02 11:16:57 +08:00
|
|
|
let index = $('.layui-imagesbox .layui-input-inline');
|
2022-08-19 19:48:37 +08:00
|
|
|
index = index.length ? index.length - 1 : 0;
|
2022-12-02 11:16:57 +08:00
|
|
|
let html = '<div class="layui-input-inline">';
|
|
|
|
|
html += '<img src="' + res.url + '" alt="alt" >';
|
2022-08-19 19:48:37 +08:00
|
|
|
html += '<input type="text" name="' + name + '[' + index + '][src]" class="layui-hide" value="' + res.url + '">';
|
|
|
|
|
html += '<input type="text" name="' + name + '[' + index + '][title]" class="layui-input" placeholder="图片简介">';
|
|
|
|
|
html += '<span class="layui-badge layui-badge-red" onclick="layui.$(this).parent().remove();">删除</span></div>';
|
|
|
|
|
$(elem).parent().before(html);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行上传操作
|
|
|
|
|
upload.render({
|
|
|
|
|
elem: elem
|
|
|
|
|
, url: uploadURL
|
|
|
|
|
, method: 'post'
|
|
|
|
|
, size: size
|
2022-12-02 11:16:57 +08:00
|
|
|
, accept: accept
|
2022-08-19 19:48:37 +08:00
|
|
|
, before: function (res) {
|
|
|
|
|
// 关闭按钮点击
|
|
|
|
|
that.prop("disabled", true);
|
|
|
|
|
}, done: function (res, index, file) {
|
|
|
|
|
if (res.code === 200 && res.url !== '') {
|
2022-12-02 11:16:57 +08:00
|
|
|
if (typeof res.chunkId != 'undefined') {
|
2022-08-19 19:48:37 +08:00
|
|
|
layer.close(window[res.chunkId]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer.msg(res.msg);
|
|
|
|
|
uploadFiles[type](res, name);
|
|
|
|
|
} else {
|
|
|
|
|
// 错误消息
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg(res.msg, {icon: 5});
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
that.prop("disabled", false);
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 全局监听打开窗口
|
2022-12-02 11:16:57 +08:00
|
|
|
$(document).on('click', "*[lay-open]", function () {
|
|
|
|
|
let clickThis = $(this),
|
2022-08-19 19:48:37 +08:00
|
|
|
config = {
|
2022-12-02 11:16:57 +08:00
|
|
|
url: clickThis.data('url') || undefined,
|
|
|
|
|
object: clickThis.data('object') || 'self',
|
|
|
|
|
type: clickThis.data('type') || 2,
|
|
|
|
|
area: clickThis.data('area') || "auto",
|
|
|
|
|
offset: clickThis.data('offset') || "25%",
|
|
|
|
|
title: clickThis.data('title') || false,
|
|
|
|
|
maxmin: clickThis.data('maxmin') || false,
|
|
|
|
|
auto: clickThis.data('auto') || "undefined",
|
2022-08-19 19:48:37 +08:00
|
|
|
iframeAuto: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let firstURL = config.url.substring(0, 1);
|
|
|
|
|
if (firstURL && firstURL === '#') {
|
|
|
|
|
config.type = 1;
|
|
|
|
|
config.url = $(config.url).html();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.area !== "auto") {
|
|
|
|
|
config.area = config.area.split(',');
|
|
|
|
|
if (config.area.length === 2 && config.area[1] === '100%') {
|
|
|
|
|
config.offset = 0;
|
|
|
|
|
if (typeof config.url == 'object') {
|
|
|
|
|
config.url = config.url[0];
|
|
|
|
|
}
|
|
|
|
|
} else if (config.area.length === 1) {
|
|
|
|
|
config.iframeAuto = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
/**
|
|
|
|
|
* 获取窗口索引
|
|
|
|
|
* @type {Window | (WorkerGlobalScope & Window)}
|
|
|
|
|
*/
|
|
|
|
|
let hierarchy = self;
|
2022-08-19 19:48:37 +08:00
|
|
|
if (config.object === 'top') {
|
2022-12-02 11:16:57 +08:00
|
|
|
hierarchy = top;
|
2022-08-19 19:48:37 +08:00
|
|
|
} else if (config.object === 'parent') {
|
2022-12-02 11:16:57 +08:00
|
|
|
hierarchy = parent;
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
hierarchy.layer.open({
|
2022-08-19 19:48:37 +08:00
|
|
|
type: config.type,
|
|
|
|
|
area: config.area,
|
|
|
|
|
title: config.title,
|
|
|
|
|
offset: config.offset,
|
|
|
|
|
maxmin: config.maxmin,
|
|
|
|
|
shadeClose: true,
|
|
|
|
|
scrollbar: true,
|
2022-12-02 11:16:57 +08:00
|
|
|
content: config.url,
|
|
|
|
|
success: function (layero, index) {
|
2022-08-19 19:48:37 +08:00
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
config.iframeAuto && layer.iframeAuto(index);
|
2022-08-19 19:48:37 +08:00
|
|
|
|
|
|
|
|
// 页面层才渲染
|
|
|
|
|
if (config.type === 1) {
|
|
|
|
|
layui.form.render();
|
2022-12-02 11:16:57 +08:00
|
|
|
layui.form.on("submit(submitPage)", function (post) {
|
|
|
|
|
let that = $(this),
|
|
|
|
|
url = that.parents('form').attr('action');
|
|
|
|
|
|
2022-08-19 19:48:37 +08:00
|
|
|
// 开始POST提交数据
|
2022-12-02 11:16:57 +08:00
|
|
|
that.attr('disabled', true);
|
|
|
|
|
$.post(url, post.field, function (res) {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Home.event.closeDialog(that);
|
|
|
|
|
if ($(that).data('reload')) {
|
|
|
|
|
location.reload();
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
2022-12-02 11:16:57 +08:00
|
|
|
layer.msg(res.msg);
|
|
|
|
|
} else {
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg(res.msg, {icon: 5});
|
2022-12-02 11:16:57 +08:00
|
|
|
}
|
|
|
|
|
that.attr('disabled', false);
|
|
|
|
|
}, 'json');
|
2022-08-19 19:48:37 +08:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
/**
|
|
|
|
|
* 表格批量操作
|
|
|
|
|
* @param obj
|
|
|
|
|
*/
|
2022-11-28 19:11:12 +08:00
|
|
|
$(document).on("click", "*[lay-batch]", function (obj) {
|
2022-12-02 11:16:57 +08:00
|
|
|
let that = $(this)
|
|
|
|
|
, tableId = that.data("table") || null
|
|
|
|
|
, fields = that.data("field") || undefined
|
2022-11-28 19:11:12 +08:00
|
|
|
, list = table.checkStatus(tableId);
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
let field = ['id'];
|
2022-11-28 19:11:12 +08:00
|
|
|
if (typeof fields !== 'undefined') {
|
|
|
|
|
field = field.concat(fields.split(','));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.data.length === 0) {
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg('请勾选数据');
|
2022-11-28 19:11:12 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
let data = {};
|
|
|
|
|
for (let n in field) {
|
|
|
|
|
let e = field[n];
|
2022-11-28 19:11:12 +08:00
|
|
|
field[e] = [];
|
2022-12-02 11:16:57 +08:00
|
|
|
for (let i in list.data) {
|
2022-11-28 19:11:12 +08:00
|
|
|
field[e].push(list.data[i][e]);
|
|
|
|
|
}
|
|
|
|
|
data[e] = field[e];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layer.confirm('确定执行批量操作', function (index) {
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
2022-12-02 11:16:57 +08:00
|
|
|
url: that.data("url"),
|
2022-11-28 19:11:12 +08:00
|
|
|
type: 'post',
|
|
|
|
|
data: data,
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
layer.msg(res.msg);
|
|
|
|
|
table.reload(tableId);
|
|
|
|
|
} else {
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg(res.msg, {icon: 5});
|
2022-11-28 19:11:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
layer.close(index);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-12-02 11:16:57 +08:00
|
|
|
/**
|
|
|
|
|
* 监听ajax操作
|
|
|
|
|
* @param obj
|
|
|
|
|
*/
|
|
|
|
|
$(document).on("click", "*[lay-ajax]", function (obj) {
|
|
|
|
|
|
|
|
|
|
let clickThis = $(this), config = {
|
|
|
|
|
url: clickThis.attr('data-url') || "undefined",
|
|
|
|
|
type: clickThis.data('type') || 'post',
|
|
|
|
|
dataType: clickThis.data('dataType') || 'json',
|
|
|
|
|
timeout: clickThis.data('timeout') || '6000',
|
|
|
|
|
tableId: clickThis.data('table') || clickThis.data('batch'),
|
|
|
|
|
reload: clickThis.data('reload'),
|
|
|
|
|
jump: clickThis.data('jump') || false,
|
|
|
|
|
confirm: clickThis.data('confirm'),
|
2022-08-19 19:48:37 +08:00
|
|
|
}, defer = $.Deferred();
|
|
|
|
|
|
|
|
|
|
// 定义初始化对象
|
|
|
|
|
let data = {}
|
|
|
|
|
// 获取拼接参数
|
2022-12-02 11:16:57 +08:00
|
|
|
, packet = clickThis.attr("data-data") || null
|
|
|
|
|
, object = clickThis.attr("data-object") || undefined;
|
2022-08-19 19:48:37 +08:00
|
|
|
|
|
|
|
|
if (config.confirm !== undefined) {
|
|
|
|
|
config.confirm = config.confirm || '确定执行此操作吗?';
|
2022-12-02 11:16:57 +08:00
|
|
|
layer.confirm(config.confirm, function (index) {
|
|
|
|
|
runningAjax(config);
|
2022-08-19 19:48:37 +08:00
|
|
|
layer.close(index);
|
2022-12-02 11:16:57 +08:00
|
|
|
}, function (index) {
|
2022-08-19 19:48:37 +08:00
|
|
|
layer.close(index);
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 传递类数据
|
|
|
|
|
if (typeof object !== "undefined") {
|
|
|
|
|
object = object.split(',');
|
|
|
|
|
for (let i = 0; i < object.length; i++) {
|
|
|
|
|
let ele = object[i].split(":");
|
2022-12-02 11:16:57 +08:00
|
|
|
data[ele[0]] = $('.' + ele[1]).val();
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 传递对象数据
|
|
|
|
|
if (packet !== 'null') {
|
2022-12-02 11:16:57 +08:00
|
|
|
packet = new Function("return " + packet)();
|
|
|
|
|
data = $.extend({}, data, packet);
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 传递input表单数据
|
2022-12-02 11:16:57 +08:00
|
|
|
let input = clickThis.data('input') || undefined;
|
2022-08-19 19:48:37 +08:00
|
|
|
if (typeof input !== undefined) {
|
2022-12-02 11:16:57 +08:00
|
|
|
let attribute = layui.$('.' + input).val();
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 回调函数
|
2022-12-02 11:16:57 +08:00
|
|
|
let runningAjax = function (config) {
|
2022-08-19 19:48:37 +08:00
|
|
|
// 执行AJAX操作
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: config.url,
|
|
|
|
|
type: config.type,
|
|
|
|
|
dataType: config.dataType,
|
|
|
|
|
timeout: config.timeout,
|
|
|
|
|
data: data,
|
|
|
|
|
xhrFields: {
|
|
|
|
|
withCredentials: true
|
|
|
|
|
},
|
|
|
|
|
crossDomain: true,
|
2022-12-02 11:16:57 +08:00
|
|
|
success: function (res) {
|
2022-08-19 19:48:37 +08:00
|
|
|
if (res.code === 200) {
|
|
|
|
|
layer.msg(res.msg);
|
|
|
|
|
|
|
|
|
|
if (typeof res.data.text !== 'undefined') {
|
2022-12-02 11:16:57 +08:00
|
|
|
$(clickThis).text(res.data.text);
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (config.reload) {
|
|
|
|
|
case 'top':
|
|
|
|
|
top.location.reload();
|
|
|
|
|
break;
|
|
|
|
|
case 'parent':
|
|
|
|
|
parent.location.reload();
|
|
|
|
|
break;
|
|
|
|
|
case 'self':
|
|
|
|
|
location.reload();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof (config.tableId) !== "undefined") {
|
|
|
|
|
layui.table.reload(config.tableId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg(res.msg, {icon: 5});
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-12-02 11:16:57 +08:00
|
|
|
error: function (res) {
|
2023-08-04 11:06:34 +08:00
|
|
|
layer.msg('Access methods failure', {icon: 5});
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.confirm) {
|
2022-12-02 11:16:57 +08:00
|
|
|
runningAjax(config);
|
2022-08-19 19:48:37 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|