升级LAYUI至2.7-b5

This commit is contained in:
Anyon 2022-03-02 12:19:49 +08:00
parent c404534ea7
commit 969bbcf6e3
12 changed files with 495 additions and 643 deletions

View File

@ -17,12 +17,10 @@
namespace app\admin\controller; namespace app\admin\controller;
use think\admin\Controller; use think\admin\Controller;
use think\admin\extend\FaviconExtend;
use think\admin\service\AdminService; use think\admin\service\AdminService;
use think\admin\service\ModuleService; use think\admin\service\ModuleService;
use think\admin\service\SystemService; use think\admin\service\SystemService;
use think\admin\storage\AliossStorage; use think\admin\storage\AliossStorage;
use think\admin\storage\LocalStorage;
use think\admin\storage\QiniuStorage; use think\admin\storage\QiniuStorage;
use think\admin\storage\TxcosStorage; use think\admin\storage\TxcosStorage;

View File

@ -1,4 +1,4 @@
<form class="layui-form layui-card" action="{:sysuri()}" data-auto="true" method="post" autocomplete="off"> <form class="layui-form layui-card" data-table-id="BaseData" action="{:sysuri()}" data-auto="true" method="post">
<div class="layui-card-body padding-left-40"> <div class="layui-card-body padding-left-40">

View File

@ -1,4 +1,4 @@
<form class="layui-form layui-card" action="{:sysuri()}" id="UserForm" data-auto="true" method="post" autocomplete="off"> <form class="layui-form layui-card" action="{:sysuri()}" data-table-id="UserData" data-auto="true" method="post">
<div class="layui-card-body padding-left-40"> <div class="layui-card-body padding-left-40">
<fieldset> <fieldset>

View File

@ -53,8 +53,9 @@ window.tapiRoot = window.tapiRoot || window.appRoot + "admin";
layui.config({base: baseRoot + 'plugs/layui_exts/'}); layui.config({base: baseRoot + 'plugs/layui_exts/'});
/*! 挂载 layui & jquery 对象 */ /*! 挂载 layui & jquery 对象 */
if (typeof jQuery === 'undefined') window.$ = window.jQuery = layui.$; window.form = layui.form, window.layer = layui.layer;
window.form = layui.form, window.layer = layui.layer, window.laydate = layui.laydate; window.laytpl = layui.laytpl, window.laydate = layui.laydate;
window.jQuery = window.$ = window.jQuery || window.$ || layui.$;
/*! 配置 require 参数 */ /*! 配置 require 参数 */
require.config({ require.config({
@ -219,12 +220,13 @@ $(function () {
this.selecter = '.layui-layout-admin>.layui-body>.think-page-body'; this.selecter = '.layui-layout-admin>.layui-body>.think-page-body';
/*! 刷新当前页面 */ /*! 刷新当前页面 */
this.reload = function (force) { this.reload = function (force) {
force ? top.location.reload() : (self !== top ? location.reload() : window.onhashchange.call(this)); if (force) top.location.reload();
else if (self !== top) location.reload();
else window.onhashchange.call(this);
}; };
/*! 内容区域动态加载后初始化 */ /*! 内容区域动态加载后初始化 */
this.reInit = function ($dom) { this.reInit = function ($dom) {
layui.element.render(), layui.form.render(); $(window).trigger('scroll'), $.vali.listen(this), $dom = $dom || $(this.selecter);
$(window).trigger('scroll'), $.vali.listen(), $dom = $dom || $(this.selecter);
return $dom.find('[required]').map(function ($parent) { return $dom.find('[required]').map(function ($parent) {
if (($parent = $(this).parent()) && $parent.is('label')) { if (($parent = $(this).parent()) && $parent.is('label')) {
$parent.addClass('label-required-prev'); $parent.addClass('label-required-prev');
@ -244,15 +246,19 @@ $(function () {
} }
}); });
}), $dom.find('[data-lazy-src]:not([data-lazy-loaded])').each(function () { }), $dom.find('[data-lazy-src]:not([data-lazy-loaded])').each(function () {
if (this.dataset.lazyLoaded === 'true') return; if (this.dataset.lazyLoaded !== 'true') {
this.dataset.lazyLoaded = 'true'; this.dataset.lazyLoaded = 'true';
if (this.nodeName === 'IMG') this.src = this.dataset.lazySrc; if (this.nodeName === 'IMG') {
else this.style.backgroundImage = 'url(' + this.dataset.lazySrc + ')'; this.src = this.dataset.lazySrc;
} else {
this.style.backgroundImage = 'url(' + this.dataset.lazySrc + ')';
}
}
}), $dom; }), $dom;
}; };
/*! 在内容区显示视图 */ /*! 在内容区显示视图 */
this.show = function (html) { this.show = function (html) {
return that.reInit($(this.selecter).html(html)); that.reInit($(this.selecter).html(html));
}; };
/*! 异步加载的数据 */ /*! 异步加载的数据 */
this.load = function (url, data, method, callable, loading, tips, time, headers) { this.load = function (url, data, method, callable, loading, tips, time, headers) {
@ -292,10 +298,10 @@ $(function () {
}; };
/*! 以 HASH 打开新网页 */ /*! 以 HASH 打开新网页 */
this.href = function (url, ele) { this.href = function (url, ele) {
var isNode = ele && ele.dataset.menuNode; // 重置表格页数缓存
isNode && layui.sessionData('pages', null); if (ele && ele.dataset.menuNode) layui.sessionData('pages', null);
if (url !== '#') return location.hash = $.menu.parseUri(url, ele); if (url !== '#') location.hash = $.menu.parseUri(url, ele);
isNode && $('[data-menu-node^="' + ele.dataset.menuNode + '-"]:first').trigger('click'); else if (ele && ele.dataset.menuNode) $('[data-menu-node^="' + ele.dataset.menuNode + '-"]:first').trigger('click');
}; };
/*! 加载 HTML 到 BODY 位置 */ /*! 加载 HTML 到 BODY 位置 */
this.open = function (url, data, call, load, tips) { this.open = function (url, data, call, load, tips) {
@ -319,7 +325,8 @@ $(function () {
})(this.dataset.confirm, function () { })(this.dataset.confirm, function () {
layer.close(idx); layer.close(idx);
}); });
})) && typeof call === 'function' && call.call(that, $dom); }));
typeof call === 'function' && call.call(that, $dom);
} }
})), false; })), false;
}, load, tips); }, load, tips);
@ -466,9 +473,11 @@ $(function () {
if (!$(input).is(':visible')) return true; if (!$(input).is(':visible')) return true;
return this.showError(input, input.getAttribute('title') || input.getAttribute('placeholder') || '输入错误'), false; return this.showError(input, input.getAttribute('title') || input.getAttribute('placeholder') || '输入错误'), false;
}, this.showError = function (ele, tip) { }, this.showError = function (ele, tip) {
this.insertError($(ele).addClass('validate-error')).addClass('layui-anim-fadein').css({width: 'auto'}).html(tip); $(ele).addClass('validate-error');
this.insertError(ele).addClass('layui-anim-fadein').css({width: 'auto'}).html(tip);
}, this.hideError = function (ele) { }, this.hideError = function (ele) {
this.insertError($(ele).removeClass('validate-error')).removeClass('layui-anim-fadein').css({width: '30px'}).html(''); $(ele).removeClass('validate-error');
this.insertError(ele).removeClass('layui-anim-fadein').css({width: '30px'}).html('');
}, this.insertError = function (ele) { }, this.insertError = function (ele) {
if ($(ele).data('input-info')) return $(ele).data('input-info'); if ($(ele).data('input-info')) return $(ele).data('input-info');
var $html = $('<span class="absolute block layui-anim text-center font-s12 notselect" style="color:#A44;z-index:2"></span>'); var $html = $('<span class="absolute block layui-anim text-center font-s12 notselect" style="color:#A44;z-index:2"></span>');
@ -477,7 +486,7 @@ $(function () {
return $(ele).data('input-info', $html.css(style).insertAfter(ele)), $html; return $(ele).data('input-info', $html.css(style).insertAfter(ele)), $html;
}; };
/*! 表单元素验证 */ /*! 表单元素验证 */
this.form.attr({onsubmit: 'return false;', novalidate: 'novalidate', autocomplete: 'off'}); this.form.attr({onsubmit: 'return false', novalidate: 'novalidate', autocomplete: 'off'});
this.form.off(this.evts, this.tags).on(this.evts, this.tags, function () { this.form.off(this.evts, this.tags).on(this.evts, this.tags, function () {
that.checkInput(this); that.checkInput(this);
}).data('validate', this).bind("submit", function (evt) { }).data('validate', this).bind("submit", function (evt) {
@ -512,7 +521,7 @@ $(function () {
var call = window[form.dataset.callable || '_default_callable'] || (taid ? function (ret) { var call = window[form.dataset.callable || '_default_callable'] || (taid ? function (ret) {
if (typeof ret === 'object' && ret.code > 0 && $('#' + taid).size() > 0) { if (typeof ret === 'object' && ret.code > 0 && $('#' + taid).size() > 0) {
return $.msg.success(ret.info, 3, function () { return $.msg.success(ret.info, 3, function () {
(typeof ret.data === 'string' && ret.data) ? location.href = ret.data : $('#' + taid).trigger('reload'); (typeof ret.data === 'string' && ret.data) ? location.href = ret.data : $.layTable.reload(taid);
$.msg.close($.msg.mdx.length > 0 ? $.msg.mdx.pop() : null); $.msg.close($.msg.mdx.length > 0 ? $.msg.mdx.pop() : null);
}), false; }), false;
} }
@ -651,59 +660,73 @@ $(function () {
} }
this.focus(); this.focus();
}); });
} };
/*! 组件 layui.table 封装 */ /*! 组件 layui.table 封装 */
$.fn.layTable = function (params) { $.fn.layTable = function (params) {
return this.each(function (idx, elem) { return this.each(function () {
// 动态初始化数据表 $.layTable.create(this, params);
this.id = this.id || 't' + Math.random().toString().replace('.', ''); });
this.setAttribute('lay-filter', this.dataset.id = this.getAttribute('lay-filter') || this.id); };
$.layTable = new function () {
this.render = function (tabldId) {
return $('#' + tabldId).trigger('render');
}, this.reload = function (tabldId) {
return $('#' + tabldId).trigger('reload');
}, this.create = function (table, params) {
// 动态初始化表格
table.id = table.id || 't' + Math.random().toString().replace('.', '');
var $table = $(table).attr('lay-filter', table.dataset.id = table.getAttribute('lay-filter') || table.id);
// 插件初始化参数 // 插件初始化参数
var opt = params || {}, data = opt.where || {}, sort = opt.initSort || opt.sort || {}; var option = params || {}, data = option.where || {}, sort = option.initSort || option.sort || {};
opt.id = elem.id, opt.elem = elem, opt.url = params.url || elem.dataset.url || location.href; option.id = table.id, option.elem = table, option.url = params.url || table.dataset.url || location.href;
opt.page = params.page !== false ? (params.page || true) : false, opt.limit = params.limit || 20; option.page = params.page !== false ? (params.page || true) : false, option.limit = params.limit || 20;
opt.loading = params.loading === true, opt.autoSort = params.autoSort === true, opt.cols = params.cols || [[]]; option.loading = params.loading === true, option.autoSort = params.autoSort === true, option.cols = params.cols || [[]];
// 默认动态设置页数, 动态设置最大高度 // 默认动态设置页数, 动态设置最大高度
if (opt.page === true) opt.page = {curr: layui.sessionData('pages')[opt.id] || 1} if (option.page === true) option.page = {curr: layui.sessionData('pages')[option.id] || 1};
if (opt.height === 'full') if ($(elem).parents('.iframe-pagination').size()) { if (option.height === 'full') if ($table.parents('.iframe-pagination').size()) {
$(elem).parents('.iframe-pagination').addClass('not-footer'); $table.parents('.iframe-pagination').addClass('not-footer');
opt.height = $(window).height() - $(elem).removeClass('layui-hide').offset().top - 20; option.height = $(window).height() - $table.removeClass('layui-hide').offset().top - 20;
} else { } else {
opt.height = $(window).height() - $(elem).removeClass('layui-hide').offset().top - 35; option.height = $(window).height() - $table.removeClass('layui-hide').offset().top - 35;
} }
// 动态计算最大页数 // 动态计算最大页数
opt.done = function () { option.done = function () {
layui.sessionData('pages', {key: elem.id, value: this.page.curr || 1}), (this.loading = true); layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (table.loading = true);
this.elem.next().find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', elem.id); $table.next().find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
}, opt.parseData = function (res) { }, option.parseData = function (res) {
var maxPage = Math.ceil(res.count / this.limit), curPage = layui.sessionData('pages')[opt.id] || 1; var maxp = Math.ceil(res.count / table.limit), curp = layui.sessionData('pages')[option.id] || 1;
if (curPage > maxPage && curPage > 1) this.elem.trigger('reload', {page: {curr: maxPage}}); if (curp > maxp && curp > 1) table.elem.trigger('reload', {page: {curr: maxp}});
}; };
// 实例并绑定的对象 // 实例并绑定的对象
$(this).data('this', layui.table.render(bindData(opt))); $table.data('this', layui.table.render(bindData(option)));
// 绑定实例重载事件 // 绑定实例重载事件
$(this).bind('reload', function (evt, opts) { $table.bind('reload render', function (evt, opts) {
opts = opts || {}, opts.loading = true; opts = opts || {}, opts.loading = true;
data = $.extend({}, data, opts.where || {}); data = $.extend({}, data, opts.where || {});
layui.table.reload(elem.id, bindData(opts || {})); if (evt.type === 'render') {
layui.table.reload(table.id, bindData(opts || {}));
} else {
layui.table.reloadData(table.id, bindData(opts || {}));
}
}).bind('row sort tool edit radio toolbar checkbox rowDouble', function (evt, call) { }).bind('row sort tool edit radio toolbar checkbox rowDouble', function (evt, call) {
layui.table.on(evt.type + '(' + elem.dataset.id + ')', call) layui.table.on(evt.type + '(' + table.dataset.id + ')', call)
}).bind('setFullHeight', function () { }).bind('setFullHeight', function () {
$(elem).trigger('reload', {height: $(window).height() - $(elem).next().offset().top - 35}) $table.trigger('render', {height: $(window).height() - $table.next().offset().top - 35})
}).trigger('sort', function (object) { }).trigger('sort', function (rets) {
(sort = object), $(elem).trigger('reload') (sort = rets), $table.trigger('reload')
}); });
// 搜索表单关联对象 // 搜索表单关联对象
var search = params.search || this.dataset.targetSearch; var search = params.search || table.dataset.targetSearch;
if (search) $body.find(search).map(function () { if (search) $body.find(search).map(function () {
$(this).attr('data-table-id', elem.id); $(this).attr('data-table-id', table.id);
}); });
// 绑定选择项关联对象 // 绑定选择项关联对象
var checked = params.checked || this.dataset.targetChecked; var checked = params.checked || table.dataset.targetChecked;
if (checked) $body.find(checked).map(function () { if (checked) $body.find(checked).map(function () {
$(this).attr('data-table-id', elem.id); $(this).attr('data-table-id', table.id);
}); });
return $table;
// 生成初始化参数 // 生成初始化参数
function bindData(options) { function bindData(options) {
@ -715,17 +738,17 @@ $(function () {
if (options.page === false) options.limit = ''; if (options.page === false) options.limit = '';
return (options['where'] = data), options; return (options['where'] = data), options;
} }
}); };
} };
/*! 弹出图片层 */ /*! 弹出图片层 */
$.previewImage = function (src, area) { $.previewImage = function (src, area) {
var img = new Image(), defer = $.Deferred(), loaded = $.msg.loading(); var img = new Image(), defer = $.Deferred(), loaded = $.msg.loading();
img.style.background = '#FFF', img.referrerPolicy = 'no-referrer'; img.style.background = '#FFF', img.referrerPolicy = 'no-referrer';
img.style.height = 'auto', img.style.width = area || '100%', img.style.display = 'none'; img.style.height = 'auto', img.style.width = area || '100%', img.style.display = 'none';
document.body.appendChild(img), img.onerror = function () { return document.body.appendChild(img), img.onerror = function () {
$.msg.close(loaded), defer.reject(); $.msg.close(loaded), defer.reject();
}, img.onload = function () { }, img.src = src, img.onload = function () {
layer.open({ layer.open({
type: 1, title: false, shadeClose: true, content: $(img), success: function ($elem, idx) { type: 1, title: false, shadeClose: true, content: $(img), success: function ($elem, idx) {
$.msg.close(loaded), defer.notify($elem, idx); $.msg.close(loaded), defer.notify($elem, idx);
@ -733,8 +756,7 @@ $(function () {
document.body.removeChild(img), defer.resolve() document.body.removeChild(img), defer.resolve()
} }
}); });
}; }, defer.promise();
return (img.src = src), defer.resolve();
}; };
/*! 以手机模式显示内容 */ /*! 以手机模式显示内容 */
@ -746,12 +768,12 @@ $(function () {
/*! 显示任务进度消息 */ /*! 显示任务进度消息 */
$.loadQueue = function (code, doScript, element) { $.loadQueue = function (code, doScript, element) {
var doAjax = true, doReload = false; var doAjax = true, doReload = false;
layer.open({ layui.layer.open({
type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () { type: 1, title: false, area: ['560px', '315px'], anim: 2, shadeClose: false, end: function () {
doAjax = false; doAjax = false;
if (doReload && doScript) { if (doReload && doScript) {
if (element && element.dataset && element.dataset.tableId) { if (element && element.dataset && element.dataset.tableId) {
$('#' + element.dataset.tableId).trigger('reload'); $.layTable.reload(element.dataset.tableId);
} else { } else {
$.form.reload(); $.form.reload();
} }
@ -845,17 +867,17 @@ $(function () {
(function (confirm, callable) { (function (confirm, callable) {
confirm ? $.msg.confirm(confirm, callable) : callable(); confirm ? $.msg.confirm(confirm, callable) : callable();
})(emap.confirm, function () { })(emap.confirm, function () {
$.form.load(emap.load, data, 'get', !emap.tableId ? false : function (ret) { $.form.load(emap.load, data, 'get', emap.tableId ? function (ret) {
if (ret.code > 0) return $.msg.success(ret.info, 3, function () { if (ret.code > 0) return $.msg.success(ret.info, 3, function () {
$('#' + emap.tableId).trigger('reload'); $.layTable.reload(emap.tableId);
}), false; }), false;
}, true, emap.tips, emap.time); } : false, true, emap.tips, emap.time);
}); });
}); });
/*! 注册 data-reload 事件行为 */ /*! 注册 data-reload 事件行为 */
onEvent('click', '[data-reload]', function () { onEvent('click', '[data-reload]', function () {
this.dataset.tableId ? $('#' + this.dataset.tableId).trigger('reload') : $.form.reload(); this.dataset.tableId ? $.layTable.reload(this.dataset.tableId) : $.form.reload();
}); });
/*! 注册 data-dbclick 事件行为 */ /*! 注册 data-dbclick 事件行为 */
@ -918,12 +940,11 @@ $(function () {
(function (confirm, callable) { (function (confirm, callable) {
confirm ? $.msg.confirm(confirm, callable) : callable(); confirm ? $.msg.confirm(confirm, callable) : callable();
})(emap.confirm, function () { })(emap.confirm, function () {
var call = !emap.tableId ? false : function (ret) { $.form.load(emap.action, data, emap.method || 'post', emap.tableId ? function (ret) {
if (ret.code > 0) return $.msg.success(ret.info, 3, function () { if (ret.code > 0) return $.msg.success(ret.info, 3, function () {
$('#' + emap.tableId).trigger('reload'); $.layTable.reload(emap.tableId);
}), false; }), false;
} } : false, load, tips, emap.time)
$.form.load(emap.action, data, emap.method || 'post', call, load, tips, emap.time)
}); });
}); });
@ -942,7 +963,7 @@ $(function () {
var area = emap.area || [emap.width || '800px', emap.height || '580px']; var area = emap.area || [emap.width || '800px', emap.height || '580px'];
var frame = emap.iframe + (emap.iframe.indexOf('?') > -1 ? '&' : '?') + $.param(data); var frame = emap.iframe + (emap.iframe.indexOf('?') > -1 ? '&' : '?') + $.param(data);
$(this).attr('data-index', $.form.iframe(frame, name, area, emap.offset || 'auto', emap.tableId ? function () { $(this).attr('data-index', $.form.iframe(frame, name, area, emap.offset || 'auto', emap.tableId ? function () {
typeof emap.refresh !== 'undefined' && $('#' + emap.tableId).trigger('reload'); typeof emap.refresh !== 'undefined' && $.layTable.reload(emap.tableId);
} : function () { } : function () {
typeof emap.refresh !== 'undefined' && $.form.reload(); typeof emap.refresh !== 'undefined' && $.form.reload();
})); }));
@ -982,7 +1003,7 @@ $(function () {
var opts = {tips: [$(this).attr('data-tips-type') || 3, '#78BA32'], time: 0}; var opts = {tips: [$(this).attr('data-tips-type') || 3, '#78BA32'], time: 0};
var layidx = layer.tips($(this).attr('data-tips-text') || this.innerText, this, opts); var layidx = layer.tips($(this).attr('data-tips-text') || this.innerText, this, opts);
$(this).off('mouseleave').on('mouseleave', function () { $(this).off('mouseleave').on('mouseleave', function () {
setTimeout("layer.close('" + layidx + "')", 100); setTimeout("layui.layer.close('" + layidx + "')", 100);
}); });
}); });
@ -993,7 +1014,7 @@ $(function () {
img.layopt = {time: 0, skin: 'layui-layer-image', anim: 5, isOutAnim: false, scrollbar: false}; img.layopt = {time: 0, skin: 'layui-layer-image', anim: 5, isOutAnim: false, scrollbar: false};
img.referrerPolicy = 'no-referrer', img.style.maxWidth = '260px', img.style.maxHeight = '260px'; img.referrerPolicy = 'no-referrer', img.style.maxWidth = '260px', img.style.maxHeight = '260px';
ele.data('layidx', layer.tips(img.outerHTML, this, img.layopt)).off('mouseleave').on('mouseleave', function () { ele.data('layidx', layer.tips(img.outerHTML, this, img.layopt)).off('mouseleave').on('mouseleave', function () {
layer.close(ele.data('layidx')); layui.layer.close(ele.data('layidx'));
}); });
} }
}); });

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 299 KiB

After

Width:  |  Height:  |  Size: 309 KiB

File diff suppressed because one or more lines are too long