Merge pull request #1141 from layui/main

同步主干到 2.x
This commit is contained in:
贤心 2022-10-09 00:37:02 +08:00 committed by GitHub
commit fe17f0edb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 276 additions and 78 deletions

View File

@ -75,6 +75,11 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;}
.laydate-footer-btns{position: absolute; right: 10px; top: 10px;}
.laydate-footer-btns span{margin: 0 0 0 -1px;}
/* 快捷栏 */
.layui-laydate-shortcut{width: 80px;display: inline-block;vertical-align: top;overflow: auto;max-height: 276px;}
.layui-laydate-shortcut+.layui-laydate-main{display: inline-block;border-left: 1px solid #e2e2e2;}
.layui-laydate-shortcut>li{padding: 6px;cursor: pointer;line-height: 18px;}
/* 年月列表 */
.layui-laydate-list{position: absolute; left: 0; top: 0; width: 100%; height: 100%; padding: 10px; box-sizing: border-box; background-color: #fff;}
.layui-laydate-list>li{position: relative; display: inline-block; width: 33.3%; height: 36px; line-height: 36px; margin: 3px 0; vertical-align: middle; text-align: center; cursor: pointer;}
@ -108,7 +113,8 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;}
.layui-laydate-content td.laydate-selected{background-color: #B5FFF8;}
.laydate-selected:hover{background-color: #00F7DE !important;}
.layui-laydate-content td>div:hover,
.layui-laydate-list li:hover{background-color: #eee; color: #333;}
.layui-laydate-list li:hover,
.layui-laydate-shortcut>li:hover{background-color: #eee; color: #333;}
.laydate-time-list li ol{margin: 0; padding: 0; border: 1px solid #e2e2e2; border-left-width: 0;}
.laydate-time-list li:first-child ol{border-left-width: 1px;}
.laydate-time-list>li:hover{background: none;}
@ -121,7 +127,7 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;}
.laydate-day-mark::after{background-color: #5FB878;}
.layui-laydate-content td.layui-this .laydate-day-mark::after{display: none;}
.layui-laydate-footer span[lay-type="date"]{color: #5FB878;}
.layui-laydate .layui-this{background-color: #009688 !important; color: #fff !important;}
.layui-laydate .layui-this,.layui-laydate .layui-this>div{background-color: #009688 !important; color: #fff !important;}
.layui-laydate .laydate-disabled,
.layui-laydate .laydate-disabled:hover{background:none !important; color: #d2d2d2 !important; cursor: not-allowed !important; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}
.layui-laydate-content td>div{padding: 7px 0;height: 100%;}
@ -169,4 +175,4 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;}
.laydate-theme-fullpanel .laydate-time-show .layui-laydate-header .layui-icon,
.laydate-theme-fullpanel .laydate-time-show .laydate-set-ym span[lay-type="year"],
.laydate-theme-fullpanel .laydate-time-show .laydate-set-ym span[lay-type="month"] {display: inline-block !important;}
.laydate-theme-fullpanel .laydate-btns-time{display: none;}
.laydate-theme-fullpanel .laydate-btns-time{display: none;}

View File

@ -743,9 +743,14 @@
if(fn){
config.event[eventName] = config.event[eventName] || {};
//这里不再对重复事件做支持
//config.event[eventName][filterName] ? config.event[eventName][filterName].push(fn) :
config.event[eventName][filterName] = [fn];
if (filterName) {
// 带filter不支持重复事件
config.event[eventName][filterName] = [fn];
} else {
// 不带filter处理的是所有的同类事件应该支持重复事件
config.event[eventName][filterName] = config.event[eventName][filterName] || [];
config.event[eventName][filterName].push(fn);
}
return this;
}

View File

@ -48,6 +48,9 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
,reload: function(options){
that.reload.call(that, options);
}
,remove: function () {
that.remove()
}
}
}

View File

@ -87,12 +87,14 @@
var ELEM_PREV = 'laydate-day-prev';
var ELEM_NEXT = 'laydate-day-next';
var ELEM_FOOTER = 'layui-laydate-footer';
var ELEM_SHORTCUT = 'layui-laydate-shortcut';
var ELEM_NOW = '.laydate-btns-now'
var ELEM_CONFIRM = '.laydate-btns-confirm';
var ELEM_TIME_TEXT = 'laydate-time-text';
var ELEM_TIME_BTN = 'laydate-btns-time';
var ELEM_PREVIEW = 'layui-laydate-preview';
var ELEM_MAIN = 'layui-laydate-main';
// 组件构造器
var Class = function(options){
var that = this;
@ -103,7 +105,7 @@
var elem = lay(options.elem || that.config.elem);
if(elem.length > 1){
lay.each(elem, function(){
laydate.render(lay.extend({}, that.config, lay.options(this),{
laydate.render(lay.extend({}, that.config, {
elem: this
}));
});
@ -111,7 +113,7 @@
}
// 初始化 id 参数
options = that.config;
options = lay.extend(that.config, lay.options(elem[0])); // 继承节点上的属性
options.id = ('id' in options) ? options.id : that.index;
// 初始化
@ -160,6 +162,7 @@
,zIndex: null //控件层叠顺序
,done: null //控件选择完毕后的回调,点击清空/现在/确定也均会触发
,change: null //日期时间改变后的回调
,autoConfirm: true //是否自动确认(日期|年份|月份选择器非range下是否自动确认
};
//多语言
@ -413,6 +416,11 @@
//底部区域
,divFooter = that.footer = lay.elem('div', {
"class": ELEM_FOOTER
})
//快捷栏
,divShortcut = that.shortcut = lay.elem('ul', {
"class": ELEM_SHORTCUT
});
if(options.zIndex) elem.style.zIndex = options.zIndex;
@ -491,7 +499,7 @@
divContent.appendChild(table);
elemMain[i] = lay.elem('div', {
"class": 'layui-laydate-main laydate-main-list-'+ i
"class": ELEM_MAIN + ' laydate-main-list-'+ i
});
elemMain[i].appendChild(divHeader);
@ -521,7 +529,69 @@
html.push('<div class="laydate-footer-btns">'+ btns.join('') +'</div>');
return html.join('');
}());
// 生成快捷键栏
if (options.shortcuts) {
elem.appendChild(divShortcut);
lay(divShortcut).html(function () {
var shortcutBtns = [];
lay.each(options.shortcuts, function (i, item) {
shortcutBtns.push('<li data-index="' + i + '">'+item.text+'</li>')
})
return shortcutBtns.join('');
}()).find('li').on('click', function (event) {
var btnSetting = options.shortcuts[this.dataset['index']] || {};
var value = btnSetting.value || [];
if (!layui.isArray(value)) {
value = [value];
}
var type = options.type;
lay.each(value, function (i, item) {
var dateTime = [options.dateTime, that.endDate][i];
if (type === 'time' && layui.type(item) !== 'date') {
if (that.EXP_IF.test(item)) {
item = (item.match(that.EXP_SPLIT) || []).slice(1);
lay.extend(dateTime, {hours: item[0] | 0, minutes: item[2] | 0, seconds: item[4] | 0})
}
} else {
lay.extend(dateTime, that.systemDate(layui.type(item) === 'date' ? item : new Date(item)))
}
if (type === 'time') {
that[['startTime', 'endTime'][i]] = {
hours: dateTime.hours,
minutes: dateTime.minutes,
seconds: dateTime.seconds,
}
}
if (type === 'year' || type === 'month' || type === 'time') {
that.listYM[i] = [dateTime.year, dateTime.month + 1];
that.checkDate('limit').calendar(null,i);
that.list(type, i);
} else {
that.checkDate('limit').calendar(null,i);
that.closeList();
}
});
var timeBtn = lay(that.footer).find('.'+ ELEM_TIME_BTN).removeClass(DISABLED);
timeBtn && timeBtn.attr('lay-type') === 'date' && timeBtn[0].click();
that.done(null, 'change');
lay(this).addClass(THIS);
if (options.position !== 'static' && !options.range && options.autoConfirm) {
if (type === 'date') {
that.choose(lay(elem).find('td.layui-this'))
} else if (type === 'year' || type === 'month') {
if(lay(elemMain[0]).find('.' + ELEM_MAIN + ' li.' + THIS + ':not(.laydate-disabled)')[0]) {
that.setValue(that.parse()).remove().done();
}
}
}
})
}
//插入到主区域
lay.each(elemMain, function(i, main){
elem.appendChild(main);
@ -529,11 +599,12 @@
options.showBottom && elem.appendChild(divFooter);
//生成自定义主题
var style;
var style = lay.elem('style');
var styleText = [];
var colorTheme;
lay.each(options.theme, function (index, theme) {
if(/^#/.test(theme)){
style = style || lay.elem('style');
colorTheme = true;
styleText.push([
'#{{id}} .layui-laydate-header{background-color:{{theme}};}'
,'#{{id}} li.layui-this,#{{id}} td.layui-this>div{background-color:{{theme}} !important;}'
@ -541,7 +612,11 @@
].join('').replace(/{{id}}/g, that.elemID).replace(/{{theme}}/g, theme));
}
});
if (style) {
//快捷栏样式
if (options.shortcuts && options.range) {
styleText.push('#{{id}}.layui-laydate-range{width: 628px;}'.replace(/{{id}}/g, that.elemID))
}
if (styleText.length) {
styleText = styleText.join('');
if('styleSheet' in style){
style.setAttribute('type', 'text/css');
@ -549,8 +624,8 @@
} else {
style.innerHTML = styleText;
}
lay(elem).addClass('laydate-theme-molv');
colorTheme && lay(elem).addClass('laydate-theme-molv');
elem.appendChild(style);
}
@ -1063,6 +1138,9 @@
//同步按钮可点状态
that.setBtnStatus();
// 重置快捷栏选中状态
lay(that.shortcut).find('li.' + THIS).removeClass(THIS);
return that;
};
@ -1275,7 +1353,7 @@
//若为月选择器,只有当选择月份时才自动关闭;
//若为年选择器,选择年份即自动关闭
//且在范围未开启时
if(!options.range){
if(!options.range && options.autoConfirm){
if((options.type === 'month' && type === 'month') || (options.type === 'year' && type === 'year')){
that.setValue(that.parse()).remove().done();
}
@ -1563,7 +1641,7 @@
} else if(options.position === 'static'){ //直接嵌套的选中
that.calendar().done().done(null, 'change'); //同时执行 done 和 change 回调
} else if(options.type === 'date'){
that.setValue(that.parse()).remove().done();
options.autoConfirm ? that.setValue(that.parse()).remove().done() : that.calendar().done(null, 'change');
} else if(options.type === 'datetime'){
that.calendar().done(null, 'change');
}

View File

@ -988,18 +988,30 @@ layer.style = function(index, options, limit){
//最小化
layer.min = function(index, options){
options = options || {};
var layero = $('#'+ doms[0] + index)
,shadeo = $('#'+ doms.SHADE + index)
,titHeight = layero.find(doms[1]).outerHeight() || 0
,left = layero.attr('minLeft') || (181*ready.minIndex)+'px'
,position = layero.css('position')
,settings = {
var layero = $('#'+ doms[0] + index);
var maxminStatus = layero.data('maxminStatus');
// 检查当前的状态是否已经是最小化
if (maxminStatus === 'min') {
return;
}
// 当前处于最大化的状态 先恢初始状态再执行最小化
if (maxminStatus === 'max') {
layer.restore(index);
}
layero.data('maxminStatus', 'min');
var shadeo = $('#'+ doms.SHADE + index);
var titHeight = layero.find(doms[1]).outerHeight() || 0;
var left = layero.attr('minLeft') || (181*ready.minIndex)+'px';
var position = layero.css('position')
var settings = {
width: 180
,height: titHeight
,position: 'fixed'
,overflow: 'hidden'
};
//记录宽高坐标,用于还原
ready.record(layero);
@ -1029,10 +1041,13 @@ layer.min = function(index, options){
//还原
layer.restore = function(index){
var layero = $('#'+ doms[0] + index)
,shadeo = $('#'+ doms.SHADE + index)
,area = layero.attr('area').split(',')
,type = layero.attr('type');
var layero = $('#'+ doms[0] + index);
// 恢复最大最小状态
layero.data('maxminStatus', '');
var shadeo = $('#'+ doms.SHADE + index);
var area = layero.attr('area').split(',');
var type = layero.attr('type');
//恢复原来尺寸
layer.style(index, {
@ -1047,15 +1062,26 @@ layer.restore = function(index){
layero.find('.layui-layer-max').removeClass('layui-layer-maxmin');
layero.find('.layui-layer-min').show();
layero.attr('type') === 'page' && layero.find(doms[4]).show();
layero.attr('minLeft', '');
ready.rescollbar(index);
//恢复遮罩
shadeo.show();
ready.events.resize[index]();
};
//全屏
layer.full = function(index){
var layero = $('#'+ doms[0] + index), timer;
// 检查当前的状态是否已经是最小化
var maxminStatus = layero.data('maxminStatus');
if (maxminStatus === 'max') {
return;
}
if (maxminStatus === 'min') {
layer.restore(index);
}
layero.data('maxminStatus', 'max');
ready.record(layero);
if(!doms.html.attr('layer-full')){
doms.html.css('overflow','hidden').attr('layer-full', index);
@ -1066,8 +1092,8 @@ layer.full = function(index){
layer.style(index, {
top: isfix ? 0 : win.scrollTop(),
left: isfix ? 0 : win.scrollLeft(),
width: win.width(),
height: win.height()
width: '100%',
height: '100%'
}, true);
layero.find('.layui-layer-min').hide();
}, 100);
@ -1176,7 +1202,7 @@ var cache = layer.cache||{}, skin = function(type){
//仿系统prompt
layer.prompt = function(options, yes){
var style = '';
var style = '', placeholder = '';
options = options || {};
if(typeof options === 'function') yes = options;
@ -1186,8 +1212,11 @@ layer.prompt = function(options, yes){
style = 'style="width: '+ area[0] +'; height: '+ area[1] + ';"';
delete options.area;
}
var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style +'></textarea>' : function(){
return '<input type="'+ (options.formType == 1 ? 'password' : 'text') +'" class="layui-layer-input">';
if (options.placeholder) {
placeholder = ' placeholder="' + options.placeholder + '"';
}
var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style + placeholder + '></textarea>' : function () {
return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input"' + placeholder + '>';
}();
var success = options.success;
@ -1536,4 +1565,4 @@ window.layui && layui.define ? (
}()
);
}(window);
}(window);

View File

@ -67,6 +67,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
}
}
// 获取当前实例
,getThisTable = function(id){
var that = thisTable.that[id];
if(!that) hint.error(id ? ('The table instance with ID \''+ id +'\' not found') : 'ID argument required');
return that || null;
}
// 获取当前实例配置项
,getThisTableConfig = function(id){
@ -131,6 +138,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
,ELEM_HOVER = 'layui-table-hover'
,ELEM_GROUP = 'laytable-cell-group'
,ELEM_COL_SPECIAL = 'layui-table-col-special'
,ELEM_TOOL_PANEL = 'layui-table-tool-panel'
,DATA_MOVE_NAME = 'LAY_TABLE_MOVE_DICT'
@ -301,6 +309,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
,text: {
none: '无数据'
}
,cols: []
};
// 表格渲染
@ -355,6 +364,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
type: 'reloadData'
});
}
// 初始化索引
options.index = that.index;
that.key = options.id || options.index;
//初始化一些其他参数
that.setInit();
//高度铺满full-差距值
if(options.height && /^full-\d+$/.test(options.height)){
@ -367,13 +383,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
options.height = $(that.parentDiv).height() - that.parentHeightGap;
}
// 初始化索引
options.index = that.index;
that.key = options.id || options.index;
//初始化一些其他参数
that.setInit();
//开始插入替代元素
var othis = options.elem
,hasRender = othis.next('.' + ELEM_VIEW)
@ -488,6 +497,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}();
if(type === 'width') return options.clientWidth;
// 初始化高度配置,如果设置了最高高度,以最高高度形式为准
options.height = options.maxHeight || options.height;
// 初始化 css 参数
if(options.css && options.css.indexOf(ELEM_VIEW) === -1){
@ -667,9 +678,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var groups = that.layHeader.find((
// 根据当前活动的表头 parentkey 属性查找其组合表头
th ? ('th[data-key='+ th.data('parentkey') +']>') : ''
) + '.' + ELEM_GROUP).get().reverse(); // 若无指向当前活动表头,则自下而上获取所有组合表头
) + '.' + ELEM_GROUP); // 若无指向当前活动表头,则自下而上获取所有组合表头
layui.each(groups, function(){
groups.css('width', 0);
layui.each(groups.get().reverse(), function(){
var othis = $(this);
var key = othis.parent().data('key');
var maxWidth = 0;
@ -688,6 +700,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
that.setGroupWidth(othis.parent());
}
});
groups.css('width', 'auto');
};
// 动态分配列宽
@ -837,6 +850,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 将表格宽度设置为跟表头一样的宽度,使之可以出现底部滚动条,以便滚动查看所有字段
var headerWidth = that.layHeader.first().children('table').width()
that.layMain.find('table').width(headerWidth);
} else {
that.layMain.find('table').width('auto');
}
that.loading(!0);
@ -1567,7 +1582,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
bodyHeight -= (that.layPage.outerHeight() || 43);
}
that.layMain.outerHeight(bodyHeight);
if (options.maxHeight) {
layui.each({elem: height, layMain: bodyHeight}, function (elemName, elemHeight) {
that[elemName].css({
height: 'auto',
maxHeight: elemHeight + 'px'
});
});
} else {
that.layMain.outerHeight(bodyHeight);
}
};
//获取滚动条宽度
@ -1646,7 +1670,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
,events = othis.attr('lay-event')
,openPanel = function(sets){
var list = $(sets.list)
,panel = $('<ul class="layui-table-tool-panel"></ul>');
,panel = $('<ul class="' + ELEM_TOOL_PANEL + '"></ul>');
panel.html(list);
@ -1656,7 +1680,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
// 插入元素
othis.find('.layui-table-tool-panel')[0] || othis.append(panel);
othis.find('.' + ELEM_TOOL_PANEL)[0] || othis.append(panel);
that.renderForm();
panel.on('click', function(e){
@ -1830,7 +1854,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
if(dict.rule){
var setWidth = dict.ruleWidth + e.clientX - dict.offset[0];
var id = thisTable.eventMoveElem.closest('.' + ELEM_VIEW).attr('lay-id');
var thatTable = thisTable.that[id];
var thatTable = getThisTable(id);
if(!thatTable) return;
@ -1846,7 +1870,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
if(thisTable.eventMoveElem){
var th = thisTable.eventMoveElem; // 当前触发拖拽的 th 元素
var id = th.closest('.' + ELEM_VIEW).attr('lay-id');
var thatTable = thisTable.that[id];
var thatTable = getThisTable(id);
if(!thatTable) return;
@ -2246,7 +2270,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
//工具面板移除事件
_DOC.on('table.remove.tool.panel', function(){
$('.layui-table-tool-panel').remove();
$('.' + ELEM_TOOL_PANEL).remove();
});
})();
@ -2257,7 +2281,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var inst = null;
var elemTable = filter
? $('table[lay-filter="'+ filter +'"]')
: $(ELEM + '[lay-data],'+ ELEM + '[lay-options]');
: $(ELEM + '[lay-data], '+ ELEM + '[lay-options]');
var errorTips = 'Table element property lay-data configuration item has a syntax error: ';
//遍历数据表格
@ -2269,7 +2293,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
errorText: errorTips + (attrData || othis.attr('lay-options'))
});
var cols = [], options = $.extend({
var options = $.extend({
elem: this
,cols: []
,data: []
@ -2293,36 +2317,37 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var row = $.extend({
title: th.text()
,colspan: th.attr('colspan') || 0 //列单元格
,rowspan: th.attr('rowspan') || 0 //行单元格
,colspan: parseInt(th.attr('colspan')) || 0 //列单元格
,rowspan: parseInt(th.attr('rowspan')) || 0 //行单元格
}, itemData);
if(row.colspan < 2) cols.push(row);
options.cols[i].push(row);
});
});
//获取表体数据
othis.find('tbody>tr').each(function(i1){
var tr = $(this), row = {};
//如果定义了字段名
tr.children('td').each(function(i2, item2){
var td = $(this)
,field = td.data('field');
if(field){
return row[field] = td.html();
}
});
//如果未定义字段名
layui.each(cols, function(i3, item3){
var td = tr.children('td').eq(i3);
row[item3.field] = td.html();
});
options.data[i1] = row;
});
//缓存静态表体数据
var trElem = othis.find('tbody>tr');
//执行渲染
table.render(options);
var tableIns = table.render(options);
//获取表体数据
if (trElem.length && !settings.data && !tableIns.config.url) {
var tdIndex = 0;
table.eachCols(tableIns.config.id, function (i3, item3) {
trElem.each(function(i1){
options.data[i1] = options.data[i1] || {};
var tr = $(this);
var field = item3.field;
options.data[i1][field] = tr.children('td').eq(tdIndex).html();
});
tdIndex++;
})
tableIns.reloadData({
data: options.data
})
}
});
return that;
@ -2460,7 +2485,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
layui.each(id, function(i, item){
i1 == 0 && dataTitle.push(item || '');
});
layui.each(table.clearCacheKey(item1), function(i2, item2){
layui.each(layui.isArray(item1) ? $.extend([], item1) : table.clearCacheKey(item1), function(i2, item2){
vals.push('"'+ (item2 || '') +'"');
});
} else {
@ -2516,7 +2541,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var config = getThisTableConfig(id); //获取当前实例配置项
if(!config) return;
thisTable.that[id].resize();
getThisTable(id).resize();
} else { //否则重置所有表格实例尺寸
layui.each(thisTable.that, function(){
@ -2530,7 +2555,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var config = getThisTableConfig(id); //获取当前实例配置项
if(!config) return;
var that = thisTable.that[id];
var that = getThisTable(id);
that.reload(options, deep, type);
return thisTable.call(that);
@ -2575,6 +2600,58 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
delete data[table.config.disabledName];
return data;
};
// 获取表格配置信息
table.getOptions = function (id) {
return $.extend(true, {}, getThisTableConfig(id));
}
table.hideCol = function (id, cols) {
var that = getThisTable(id);
if (!that) {
return;
}
if (layui.type(cols) === 'boolean') {
// 显示全部或者隐藏全部
that.eachCols(function (i2, item2) {
var key = item2.key;
var col = that.col(key);
var parentKey = item2.parentKey;
// 同步勾选列的 hide 值和隐藏样式
if (col.hide != cols) {
var hide = col.hide = cols;
that.elem.find('*[data-key="'+ key +'"]')[
hide ? 'addClass' : 'removeClass'
](HIDE);
// 根据列的显示隐藏,同步多级表头的父级相关属性值
that.setParentCol(hide, parentKey);
}
})
} else {
layui.each(cols, function (i1, item1) {
that.eachCols(function (i2, item2) {
if (item1.field === item2.field) {
var key = item2.key;
var col = that.col(key);
var parentKey = item2.parentKey;
// 同步勾选列的 hide 值和隐藏样式
if ('hide' in item1 && col.hide != item1.hide) {
var hide = col.hide = !!item1.hide;
that.elem.find('*[data-key="'+ key +'"]')[
hide ? 'addClass' : 'removeClass'
](HIDE);
// 根据列的显示隐藏,同步多级表头的父级相关属性值
that.setParentCol(hide, parentKey);
}
}
})
});
}
$('.' + ELEM_TOOL_PANEL).remove(); // 关闭字段筛选面板如果打开的话
// 重新适配尺寸
that.resize();
}
// 自动完成渲染
$(function(){