Compare commits

...

2 Commits

Author SHA1 Message Date
Anyon
973095738d Update admin.js 2022-07-18 09:37:08 +08:00
Anyon
946e88eb06 Update admin.js 2022-07-18 09:30:36 +08:00

View File

@ -174,39 +174,43 @@ $(function () {
/*! 消息组件实例 */
$.msg = new function () {
var that = this;
this.idx = [], this.mdx = [];
this.shade = [0.02, '#000000'];
this.idx = [], this.mdx = [], this.shade = [0.02, '#000000'];
/*! 关闭最新窗口 */
this.closeLastModal = function () {
while ($.msg.mdx.length > 0 && (this.tdx = $.msg.mdx.pop()) > 0) {
if ($('#layui-layer' + this.tdx).size()) return layer.close(this.tdx);
}
};
/*! 关闭消息框 */
this.close = function (idx) {
if (idx !== null) return layer.close(idx);
for (var i in this.idx) that.close(this.idx[i]);
for (var i in this.idx) $.msg.close(this.idx[i]);
this.idx = [];
};
/*! 弹出警告框 */
this.alert = function (msg, call) {
var idx = layer.alert(msg, {end: call, scrollbar: false});
return that.idx.push(idx), idx;
return $.msg.idx.push(idx), idx;
};
/*! 显示成功类型的消息 */
this.success = function (msg, time, call) {
var idx = layer.msg(msg, {icon: 1, shade: this.shade, scrollbar: false, end: call, time: (time || 2) * 1000, shadeClose: true});
return that.idx.push(idx), idx;
return $.msg.idx.push(idx), idx;
};
/*! 显示失败类型的消息 */
this.error = function (msg, time, call) {
var idx = layer.msg(msg, {icon: 2, shade: this.shade, scrollbar: false, time: (time || 3) * 1000, end: call, shadeClose: true});
return that.idx.push(idx), idx;
return $.msg.idx.push(idx), idx;
};
/*! 状态消息提示 */
this.tips = function (msg, time, call) {
var idx = layer.msg(msg, {time: (time || 3) * 1000, shade: this.shade, end: call, shadeClose: true});
return that.idx.push(idx), idx;
return $.msg.idx.push(idx), idx;
};
/*! 显示加载提示 */
this.loading = function (msg, call) {
var idx = msg ? layer.msg(msg, {icon: 16, scrollbar: false, shade: this.shade, time: 0, end: call}) : layer.load(2, {time: 0, scrollbar: false, shade: this.shade, end: call});
return that.idx.push(idx), idx;
return $.msg.idx.push(idx), idx;
};
/*! 页面加载层 */
this.page = new function () {
@ -215,22 +219,22 @@ $(function () {
this.stat = function () {
return this.$body.is(':visible');
}, this.done = function () {
that.page.$body.fadeOut();
$.msg.page.$body.fadeOut();
}, this.show = function () {
this.stat() || this.$main.removeClass('layui-hide').show();
}, this.hide = function () {
if (this.time) clearTimeout(this.time);
this.time = setTimeout(function () {
(that.page.time = 0) || that.page.$main.fadeOut();
($.msg.page.time = 0) || $.msg.page.$main.fadeOut();
}, 200);
};
};
/*! 确认对话框 */
this.confirm = function (msg, ok, no) {
return layer.confirm(msg, {title: '操作确认', btn: ['确认', '取消']}, function (idx) {
(typeof ok === 'function' && ok.call(this, idx)), that.close(idx);
(typeof ok === 'function' && ok.call(this, idx)), $.msg.close(idx);
}, function (idx) {
(typeof no === 'function' && no.call(this, idx)), that.close(idx);
(typeof no === 'function' && no.call(this, idx)), $.msg.close(idx);
});
};
/*! 自动处理JSON数据 */
@ -240,13 +244,7 @@ $(function () {
if (parseInt(ret.code) === 1 && time === 'false') {
return url ? location.href = url : $.form.reload();
} else return (parseInt(ret.code) === 1) ? this.success(msg, time, function () {
url ? location.href = url : $.form.reload();
that.close(function (idx) {
while ($.msg.mdx.length > 0 && (idx = $.msg.mdx.pop())) {
if ($('#layui-layer' + idx).size()) return idx;
}
return null;
}());
$.msg.closeLastModal(url ? location.href = url : $.form.reload());
}) : this.error(msg, 3, function () {
url ? location.href = url : '';
});
@ -255,7 +253,6 @@ $(function () {
/*! 表单自动化组件 */
$.form = new function () {
var that = this;
/*! 内容区选择器 */
this.selecter = '.layui-layout-admin>.layui-body>.think-page-body';
/*! 刷新当前页面 */
@ -290,7 +287,7 @@ $(function () {
};
/*! 在内容区显示视图 */
this.show = function (html) {
that.reInit($(this.selecter).html(html));
$.form.reInit($(this.selecter).html(html));
};
/*! 异步加载的数据 */
this.load = function (url, data, method, callable, loading, tips, time, headers) {
@ -322,8 +319,8 @@ $(function () {
}
}, success: function (ret) {
time = time || ret.wait || undefined;
if (typeof callable === 'function' && callable.call(that, ret, time) === false) return false;
return typeof ret === 'object' ? $.msg.auto(ret, time) : that.show(ret);
if (typeof callable === 'function' && callable.call($.form, ret, time) === false) return false;
return typeof ret === 'object' ? $.msg.auto(ret, time) : $.form.show(ret);
}, complete: function () {
$.msg.page.done();
$.msg.close(loadidx);
@ -340,7 +337,7 @@ $(function () {
/*! 加载 HTML 到 BODY 位置 */
this.open = function (url, data, call, load, tips) {
this.load(url, data, 'get', function (ret) {
return (typeof ret === 'object' ? $.msg.auto(ret) : that.show(ret)), false;
return (typeof ret === 'object' ? $.msg.auto(ret) : $.form.show(ret)), false;
}, load, tips);
};
/*! 打开 IFRAME 窗口 */
@ -354,7 +351,7 @@ $(function () {
if (typeof res === 'object') return $.msg.auto(res), false;
return $.msg.mdx.push(this.idx = layer.open({
type: 1, btn: false, area: area || "800px", resize: false, content: res, title: name || '', offset: offset || 'auto', success: function ($dom, idx) {
typeof call === 'function' && call.call(that, $dom);
typeof call === 'function' && call.call($.form, $dom);
$.form.reInit($dom.off('click', '[data-close]').on('click', '[data-close]', function () {
onConfirm(this.dataset.confirm, function () {
layer.close(idx);
@ -368,7 +365,6 @@ $(function () {
/*! 后台菜单辅助插件 */
$.menu = new function () {
var that = this;
/*! 计算 URL 地址中有效的 URI */
this.getUri = function (uri) {
uri = uri || location.href;
@ -417,7 +413,7 @@ $(function () {
(layui.data('AdminMenuType')['mini'] || $body.width() < 1000) ? layout.addClass(mclass) : layout.removeClass(mclass);
}).trigger('resize').on('hashchange', function () {
if (/^#(https?:)?(\/\/|\\\\)/.test(location.hash)) return $.msg.tips('禁止访问外部链接!');
if (location.hash.length < 1) return $body.find('[data-menu-node]:first').trigger('click'); else return that.href(location.hash);
if (location.hash.length < 1) return $body.find('[data-menu-node]:first').trigger('click'); else return $.menu.href(location.hash);
}).trigger('hashchange');
};
/*! 同步二级菜单展示状态 */
@ -430,10 +426,10 @@ $(function () {
/*! 页面 LOCATION-HASH 跳转 */
this.href = function (hash, node) {
if ((hash || '').length < 1) return $('[data-menu-node]:first').trigger('click');
// $.msg.page.show(),$.form.load(hash, {}, 'get', $.msg.page.hide, true),that.sync(2);
$.form.load(hash, {}, 'get', false, !$.msg.page.stat()), that.sync(2);
// $.msg.page.show(),$.form.load(hash, {}, 'get', $.msg.page.hide, true),$.menu.sync(2);
$.form.load(hash, {}, 'get', false, !$.msg.page.stat()), $.menu.sync(2);
/*! 菜单选择切换 */
if (/^m-/.test(node = node || that.queryNode(that.getUri()))) {
if (/^m-/.test(node = node || $.menu.queryNode($.menu.getUri()))) {
var arr = node.split('-'), tmp = arr.shift(), $all = $('a[data-menu-node]').parent('.layui-this');
while (arr.length > 0) {
tmp = tmp + '-' + arr.shift();
@ -544,8 +540,8 @@ $(function () {
var call = window[emap.callable || '_default_callable'] || (taid ? function (ret) {
if (typeof ret === 'object' && ret.code > 0 && $('#' + taid).size() > 0) {
return $.msg.success(ret.info, 3, function () {
$.msg.closeLastModal();
(typeof ret.data === 'string' && ret.data) ? location.href = ret.data : $.layTable.reload(taid);
$.msg.close($.msg.mdx.length > 0 ? $.msg.mdx.pop() : null);
}) && false;
}
} : undefined);
@ -576,9 +572,7 @@ $(function () {
var key, keys = this.name.match(rules.key), merge = this.value, name = this.name;
while ((key = keys.pop()) !== undefined) {
name = name.replace(new RegExp("\\[" + key + "\\]$"), '');
if (key.match(rules.push)) merge = self.build([], self.pushCounter(name), merge);
else if (key.match(rules.fixed)) merge = self.build([], key, merge);
else if (key.match(rules.named)) merge = self.build({}, key, merge);
if (key.match(rules.push)) merge = self.build([], self.pushCounter(name), merge); else if (key.match(rules.fixed)) merge = self.build([], key, merge); else if (key.match(rules.named)) merge = self.build({}, key, merge);
}
data = $.extend(true, data, merge);
});
@ -625,10 +619,7 @@ $(function () {
}).on('click', 'i.layui-icon-close', function (event) {
event.stopPropagation(), $bt.attr('style', ''), $in.val('');
}).find('[data-file]').data('input', this).attr({
'data-path': $in.data('path') || '',
'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg',
'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0,
'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0,
'data-path': $in.data('path') || '', 'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg', 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0, 'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0,
});
});
};
@ -640,10 +631,7 @@ $(function () {
var $bt = $('<div class="uploadimage"><span><a data-file="mul" class="layui-icon layui-icon-upload-drag"></a></span><span data-file="images"></span></div>');
var ims = this.value ? this.value.split('|') : [], $in = $(this).after($bt);
$bt.find('[data-file]').attr({
'data-path': $in.data('path') || '',
'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg',
'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0,
'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0,
'data-path': $in.data('path') || '', 'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg', 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0, 'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0,
}).on('push', function (evt, src) {
ims.push(src), $in.val(ims.join('|')), showImageContainer([src]);
}) && (ims.length > 0 && showImageContainer(ims));