mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
优化layui.table使用
This commit is contained in:
parent
907a21e0cc
commit
c7bc315d5c
@ -36,12 +36,10 @@ if (typeof Array.prototype.forEach !== 'function') {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! 脚本应用根路径 */
|
/*! 应用根路径,静态插件库路径,动态插件库路径 */
|
||||||
var srcs = document.scripts[document.scripts.length - 1].src.split('/');
|
var srcs = document.scripts[document.scripts.length - 1].src.split('/');
|
||||||
window.appRoot = srcs.slice(0, -2).join('/') + '/';
|
window.appRoot = srcs.slice(0, -2).join('/') + '/';
|
||||||
/*! 静态插件库路径 */
|
|
||||||
window.baseRoot = srcs.slice(0, -1).join('/') + '/';
|
window.baseRoot = srcs.slice(0, -1).join('/') + '/';
|
||||||
/*! 动态插件库路径 */
|
|
||||||
window.tapiRoot = window.tapiRoot || window.appRoot + "admin";
|
window.tapiRoot = window.tapiRoot || window.appRoot + "admin";
|
||||||
|
|
||||||
/*! 挂载 layui & jquery 对象 */
|
/*! 挂载 layui & jquery 对象 */
|
||||||
@ -677,24 +675,34 @@ $(function () {
|
|||||||
}
|
}
|
||||||
// 动态计算最大页数
|
// 动态计算最大页数
|
||||||
option.done = function () {
|
option.done = function () {
|
||||||
layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (table.loading = true);
|
$table.data('that', this);
|
||||||
|
layui.sessionData('pages', {key: table.id, value: this.page.curr || 1}), (option.loading = true);
|
||||||
$.form.reInit($table.next()).find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
|
$.form.reInit($table.next()).find('[data-load],[data-queue],[data-action],[data-iframe]').not('[data-table-id]').attr('data-table-id', table.id);
|
||||||
}, option.parseData = function (res) {
|
}, option.parseData = function (res) {
|
||||||
if (typeof params.filter === 'function') res.data = params.filter(res.data, res);
|
if (typeof params.filter === 'function') res.data = params.filter(res.data, res);
|
||||||
var maxp = Math.ceil(res.count / table.limit), curp = layui.sessionData('pages')[option.id] || 1;
|
if (!this.page || !this.page.curr) return res;
|
||||||
if (curp > maxp && curp > 1) table.elem.trigger('reload', {page: {curr: maxp}});
|
var curp = this.page.curr, maxp = Math.ceil(res.count / option.limit);
|
||||||
|
if (curp > maxp && maxp > 1) $table.trigger('reload', {page: {curr: maxp}});
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
// 实例并绑定的对象
|
// 实例并绑定的对象
|
||||||
$table.data('this', layui.table.render(bindData(option)));
|
$table.data('this', layui.table.render(bindData(option)));
|
||||||
// 绑定实例重载事件
|
// 绑定实例重载事件
|
||||||
$table.bind('reload render reloadData', function (evt, opts) {
|
$table.bind('reload render reloadData', function (evt, opts) {
|
||||||
opts = opts || {}, opts.loading = true;
|
data = $.extend({}, data, (opts = opts || {}).where || {});
|
||||||
data = $.extend({}, data, opts.where || {});
|
opts = bindData($.extend({}, opts, {loading: true}));
|
||||||
if (evt.type === 'render1' || evt.type === 'reloadData') {
|
if (evt.type.indexOf('reload') > -1) {
|
||||||
layui.table.reloadData(table.id, bindData(opts || {}));
|
var $that = $table.data('that');
|
||||||
|
if ($that && $that.page && $that.page.jump) {
|
||||||
|
$that.sort = $that.initSort = opts.initSort;
|
||||||
|
$that.where = data, $that.loading = opts.loading;
|
||||||
|
if (opts.page && opts.page.curr) $that.page.curr = opts.page.curr || 1;
|
||||||
|
$that.page.jump({curr: $that.page.curr, limit: option.limit});
|
||||||
|
} else {
|
||||||
|
layui.table.reloadData(table.id, opts);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
layui.table.reload(table.id, bindData(opts || {}));
|
layui.table.reload(table.id, 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 + '(' + table.dataset.id + ')', call)
|
layui.table.on(evt.type + '(' + table.dataset.id + ')', call)
|
||||||
|
@ -25,7 +25,7 @@ CKEDITOR.plugins.add("uimage", {
|
|||||||
editor.ui.addButton("UploadImage", {label: "上传本地图片", command: 'uimage', icon: 'image', toolbar: 'insert,10'});
|
editor.ui.addButton("UploadImage", {label: "上传本地图片", command: 'uimage', icon: 'image', toolbar: 'insert,10'});
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$('#cke_' + editor.name).find('.cke_button__uploadimage_label').parent().map(function () {
|
$('#cke_' + editor.name).find('.cke_button__uploadimage_label').parent().map(function () {
|
||||||
$(this).attr('data-type', 'png,jpg,gif').attr('data-file', 'mul').uploadFile(function (url) {
|
$(this).attr('data-type', 'png,jpg,gif,jpeg').attr('data-file', 'mul').uploadFile(function (url) {
|
||||||
editor.insertElement(CKEDITOR.dom.element.createFromHtml('<span><img style="max-width:100%;border:0" alt="" src="' + url + '"></span>'));
|
editor.insertElement(CKEDITOR.dom.element.createFromHtml('<span><img style="max-width:100%;border:0" alt="" src="' + url + '"></span>'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user