Merge branch '2.x' of github.com:layui/layui into 2.x

pull/1226/head
贤心 2 years ago
commit fc9756bccd

@ -21,7 +21,7 @@ const config = {
,{pkg: pkg, js: ';'}
]
//模块
,modules: 'lay,laytpl,laypage,laydate,jquery,layer,util,dropdown,slider,colorpicker,element,upload,form,table,tree,transfer,carousel,rate,flow,code'
,modules: 'lay,laytpl,laypage,laydate,jquery,layer,util,dropdown,slider,colorpicker,element,upload,form,table,treeTable,tree,transfer,carousel,rate,flow,code'
};
// 获取参数

@ -834,6 +834,8 @@ a cite{font-style: normal; *cursor:pointer;}
.layui-form-checked.layui-checkbox-disabled[lay-skin="primary"] i{background: #eee!important; border-color: #eee!important;}
.layui-checkbox-disabled[lay-skin="primary"]:hover i{border-color: #d2d2d2;}
.layui-form-item .layui-form-checkbox[lay-skin="primary"]{margin-top: 10px;}
.layui-form-checkbox[lay-skin="primary"] > i.layui-icon-subtraction,
.layui-form-checkbox[lay-skin="primary"]:hover i.layui-icon-subtraction {color: darkgray;}
/* 复选框-开关风格 */.layui-form-switch{position: relative; display: inline-block; vertical-align: middle; height: 22px; line-height: 22px; min-width: 35px; padding: 0 5px; margin-top: 8px; border: 1px solid #d2d2d2; border-radius: 20px; cursor: pointer; background-color: #fff; -webkit-transition: .1s linear; transition: .1s linear;}
.layui-form-switch i{position: absolute; left: 5px; top: 3px; width: 16px; height: 16px; border-radius: 20px; background-color: #d2d2d2; -webkit-transition: .1s linear; transition: .1s linear;}
@ -1108,7 +1110,13 @@ body .layui-table-tips .layui-layer-content{background: none; padding: 0; box-sh
.layui-table-tips-c:hover{background-color: #777;}
.layui-table-tips-c:before{position: relative; right: -2px;}
/** 文件上传 **/
/** 树表 **/
.layui-table-tree-nodeIcon {width: 20px;}
.layui-table-tree-nodeIcon > * {width: 100%;}
.layui-table-tree-flexIcon,.layui-table-tree-nodeIcon {margin-right: 2px;}
.layui-table-tree-flexIcon {cursor: pointer;}
/** 文件上传 **/
.layui-upload-file{display: none!important; opacity: .01; filter: Alpha(opacity=1);}
.layui-upload-list{margin: 11px 0;}
.layui-upload-choose{max-width: 200px; padding: 0 10px; color: #999; font-size: 14px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}

@ -60,6 +60,7 @@
,transfer: 'transfer' //穿梭框
,tree: 'tree' //树结构
,table: 'table' //表格
,treeTable: 'treeTable' //树表
,element: 'element' //常用元素操作
,rate: 'rate' //评分组件
,colorpicker: 'colorpicker' //颜色选择器

@ -48,6 +48,9 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
,reload: function(options){
that.reload.call(that, options);
}
,reloadData: function(options){
dropdown.reloadData(id, options);
}
,close: function () {
that.remove()
}
@ -83,14 +86,14 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
};
//重载实例
Class.prototype.reload = function(options){
Class.prototype.reload = function(options, type){
var that = this;
that.config = $.extend({}, that.config, options);
that.init(true);
that.init(true, type);
};
// 初始化准备
Class.prototype.init = function(rerender){
Class.prototype.init = function(rerender, type){
var that = this;
var options = that.config;
@ -113,7 +116,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
var newThat = thisModule.getThis(elem.data(MOD_INDEX));
if(!newThat) return;
return newThat.reload(options);
return newThat.reload(options, type);
}
options.elem = $(options.elem);
@ -123,12 +126,12 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
elem.attr('id') || that.index
);
if(options.show) that.render(rerender); // 初始即显示
if(options.show || (type === 'reloadData' && that.elemView && $('body').find(that.elemView.get(0)).length)) that.render(rerender, type); //初始即显示或者面板弹出之后执行了刷新数据
that.events(); // 事件
};
//渲染
Class.prototype.render = function(rerender){
Class.prototype.render = function(rerender, type){
var that = this
,options = that.config
,elemBody = $('body')
@ -234,7 +237,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
}
//主模板
,TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit">'
,TPL_MAIN = ['<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" lay-id="' + options.id + '">'
,'</div>'].join('');
//如果是右键事件,则每次触发事件时,将允许重新渲染
@ -244,6 +247,10 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
if(!rerender && options.elem.data(MOD_INDEX +'_opened')) return;
//记录模板对象
that.elemView = $('.' + STR_ELEM + '[lay-id="' + options.id + '"]');
if (type === 'reloadData' && that.elemView.length) {
that.elemView.html(options.content || getDefaultView());
} else {
that.elemView = $(TPL_MAIN);
that.elemView.append(options.content || getDefaultView());
@ -251,7 +258,6 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
if(options.className) that.elemView.addClass(options.className);
if(options.style) that.elemView.attr('style', options.style);
//记录当前执行的实例索引
dropdown.thisId = options.id;
@ -264,6 +270,16 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
var shade = options.shade ? ('<div class="'+ STR_ELEM_SHADE +'" style="'+ ('z-index:'+ (that.elemView.css('z-index')-1) +'; background-color: ' + (options.shade[1] || '#000') + '; opacity: ' + (options.shade[0] || options.shade)) +'"></div>') : '';
that.elemView.before(shade);
//如果是鼠标移入事件,则鼠标移出时自动关闭
if(options.trigger === 'mouseenter'){
that.elemView.on('mouseenter', function(){
clearTimeout(thisModule.timer);
}).on('mouseleave', function(){
that.delayRemove();
});
}
}
//坐标定位
that.position();
thisModule.prevElem = that.elemView; //记录当前打开的元素,以便在下次关闭
@ -305,15 +321,6 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
}
});
//如果是鼠标移入事件,则鼠标移出时自动关闭
if(options.trigger === 'mouseenter'){
that.elemView.on('mouseenter', function(){
clearTimeout(thisModule.timer);
}).on('mouseleave', function(){
that.delayRemove();
});
}
// 组件打开完毕的事件
typeof options.ready === 'function' && options.ready(
that.elemView,
@ -545,14 +552,34 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
};
// 重载实例
dropdown.reload = function(id, options){
dropdown.reload = function(id, options, type){
var that = thisModule.getThis(id);
if(!that) return this;
that.reload(options);
that.reload(options, type);
return thisModule.call(that);
};
// 仅重载数据
dropdown.reloadData = function(){
var args = $.extend([], arguments);
args[2] = 'reloadData';
// 重载时,与数据相关的参数
var dataParams = new RegExp('^('+ [
'data', 'templet', 'content'
].join('|') + ')$');
// 过滤与数据无关的参数
layui.each(args[1], function (key, value) {
if(!dataParams.test(key)){
delete args[1][key];
}
});
return dropdown.reload.apply(null, args);
};
// 核心入口
dropdown.render = function(options){
var inst = new Class(options);

@ -98,9 +98,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
itemElem[0].checked = value;
} else if(type === 'radio') { // 如果为单选框
itemElem.each(function(){
if(this.value == value ){
this.checked = true
}
this.checked = this.value == value;
});
} else { // 其它类型的表单
itemElem.val(value);
@ -644,6 +642,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
var title = (check.attr('title')||'').split('|');
if(check[0].disabled) return;
if (check[0].indeterminate) {
check[0].indeterminate = false;
reElem.find('.layui-icon-subtraction').removeClass('layui-icon-subtraction').addClass('layui-icon-ok')
}
check[0].checked ? (
check[0].checked = false
@ -688,7 +691,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
// 复选框
"checkbox": [
(title[0] ? ('<span>'+ util.escape(title[0]) +'</span>') : '')
,'<i class="layui-icon layui-icon-ok"></i>'
,'<i class="layui-icon '+(skin === 'primary' && !check.checked && othis.get(0).indeterminate ? 'layui-icon-subtraction' : 'layui-icon-ok')+'"></i>'
].join(''),
// 开关

@ -46,11 +46,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var options = that.config;
var id = options.id || options.index;
if(id){
thisTable.that[id] = that; // 记录当前实例对象
thisTable.config[id] = options; // 记录当前实例配置项
}
return {
config: options,
reload: function(options, deep){
@ -322,10 +317,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
options.where = options.where || {};
// 初始化 id 属性 - 优先取 options > 元素 id > 自增索引
options.id = 'id' in options ? options.id : (
var id = options.id = 'id' in options ? options.id : (
options.elem.attr('id') || that.index
);
thisTable.that[id] = that; // 记录当前实例对象
thisTable.config[id] = options; // 记录当前实例配置项
//请求参数的自定义格式
options.request = $.extend({
pageName: 'page'
@ -813,13 +811,20 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
if(that.autoColNums > 0 && patchNums >= -colNums && patchNums <= colNums){
var getEndTh = function(th){
var field;
th = th || that.layHeader.eq(0).find('thead > tr:first-child > th:last-child')
field = th.data('field');
var field, thRet;
th = th || that.layHeader.eq(0).find('thead th:last-child')
layui.each(th, function (thIndex, thElem) {
thElem = $(thElem);
if (!thElem.children('.'+ELEM_GROUP).length) { // 排除合并表头
field = thElem.attr('data-field');
thRet = thElem;
}
})
if(!field && th.prev()[0]){
return getEndTh(th.prev())
}
return th
return thRet
};
var th = getEndTh();
var key = th.data('key');
@ -899,6 +904,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
table.cache[that.key] = []; //格式化缓存数据
that.syncCheckAll();
that.renderForm();
that.setColsWidth();
};
// 初始页码
@ -959,7 +966,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
// 检查数据格式是否符合规范
if(res[response.statusName] != response.statusCode){
that.renderForm();
that.errorView(
res[response.msgName] ||
('返回的数据不符合规范,正确的成功状态码应为:"'+ response.statusName +'": '+ response.statusCode)
@ -982,10 +988,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
,error: function(e, msg){
that.errorView('请求异常,错误提示:'+ msg);
that.renderForm();
that.setColsWidth();
typeof options.error === 'function' && options.error(e, msg);
}
});
@ -1037,38 +1039,14 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
};
// 数据渲染
Class.prototype.renderData = function(opts){
Class.prototype.getTrHtml = function(data, sort, curr, trsObj) {
var that = this;
var options = that.config;
var trs = trsObj && trsObj.trs || [];
var trs_fixed = trsObj && trsObj.trs_fixed || [];
var trs_fixed_r = trsObj && trsObj.trs_fixed_r || [];
curr = curr || 1
var res = opts.res;
var curr = opts.curr;
var count = opts.count;
var sort = opts.sort;
var data = res[options.response.dataName] || []; //列表数据
var totalRowData = res[options.response.totalRowName]; //合计行数据
var trs = [];
var trs_fixed = [];
var trs_fixed_r = [];
// 渲染视图
var render = function(){ // 后续性能提升的重点
// 同步表头父列的相关值
options.HAS_SET_COLS_PATCH || that.setColsPatch();
options.HAS_SET_COLS_PATCH = true;
var thisCheckedRowIndex;
if(!sort && that.sortKey){
return that.sort({
field: that.sortKey.field,
type: that.sortKey.sort,
pull: true,
reloadType: opts.type
});
}
layui.each(data, function(i1, item1){
var tds = [], tds_fixed = [], tds_fixed_r = []
,numbers = i1 + options.limit*(curr - 1) + 1; // 序号
@ -1158,7 +1136,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
break;
case 'radio': // 单选
if(tplData[checkName]){
thisCheckedRowIndex = i1;
that.thisCheckedRowIndex = i1;
}
return '<input type="radio" name="layTableRadio_'+ options.index +'" '
+ function(){
@ -1195,6 +1173,56 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
trs_fixed_r.push('<tr data-index="'+ i1 +'">'+ tds_fixed_r.join('') + '</tr>');
});
return {
trs: trs,
trs_fixed: trs_fixed,
trs_fixed_r: trs_fixed_r
}
}
// 返回行节点代码
table.getTrHtml = function (id, data) {
var that = getThisTable(id);
return that.getTrHtml(data);
}
// 数据渲染
Class.prototype.renderData = function(opts){
var that = this;
var options = that.config;
var res = opts.res;
var curr = opts.curr;
var count = opts.count;
var sort = opts.sort;
var data = res[options.response.dataName] || []; //列表数据
var totalRowData = res[options.response.totalRowName]; //合计行数据
var trs = [];
var trs_fixed = [];
var trs_fixed_r = [];
// 渲染视图
var render = function(){ // 后续性能提升的重点
// 同步表头父列的相关值
options.HAS_SET_COLS_PATCH || that.setColsPatch();
options.HAS_SET_COLS_PATCH = true;
that.thisCheckedRowIndex = '';
if(!sort && that.sortKey){
return that.sort({
field: that.sortKey.field,
type: that.sortKey.sort,
pull: true,
reloadType: opts.type
});
}
that.getTrHtml(data, sort, curr, {
trs: trs,
trs_fixed: trs_fixed,
trs_fixed_r: trs_fixed_r
});
// 容器的滚动条位置
if(!(options.scrollPos === 'fixed' && opts.type === 'reloadData')){
that.layBody.scrollTop(0);
@ -1211,9 +1239,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
that.renderForm();
// 标注选中行样式
typeof thisCheckedRowIndex === 'number' && that.setRowChecked({
typeof that.thisCheckedRowIndex === 'number' && that.setRowChecked({
type: 'radio',
index: thisCheckedRowIndex
index: that.thisCheckedRowIndex
}, true);
that.syncCheckAll();
@ -1245,7 +1273,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
//如果无数据
if(data.length === 0){
that.renderForm();
return that.errorView(options.text.none);
} else {
that.layFixLeft.removeClass(HIDE);
@ -2694,7 +2721,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 获取表格配置信息
table.getOptions = function (id) {
return $.extend(true, {}, getThisTableConfig(id));
return getThisTableConfig(id);
}
// 显示或隐藏列
@ -2761,18 +2788,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var args = $.extend([], arguments);
args[3] = 'reloadData';
// 重载时,与数据相关的参数
// 重载时,影响整个结构的参数,不适合更新的参数
var dataParams = new RegExp('^('+ [
'data', 'url', 'method', 'contentType',
'dataType','jsonpCallback',
'headers', 'where', 'page', 'limit',
'request', 'response', 'parseData',
'scrollPos'
'elem', 'id', 'cols', 'width', 'height', 'maxHeight',
'toolbar', 'defaultToolbar',
'className', 'css', 'totalRow', 'page', 'pagebar'
].join('|') + ')$');
// 过滤与数据无关的参数
layui.each(args[1], function (key, value) {
if(!dataParams.test(key)){
if(dataParams.test(key)){
delete args[1][key];
}
});

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save