Browse Source

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

pull/1284/head
贤心 1 year ago
parent
commit
5ffc5be821
  1. 6
      src/modules/form.js
  2. 21
      src/modules/table.js
  3. 51
      src/modules/treeTable.js

6
src/modules/form.js

@ -314,6 +314,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
reElem.addClass(CLASS + 'up');
}
// 删除input已有文本并放入 placeholder,方便输入
if (input.val()) {
// 有值时才删除并替换placeholder
input.attr('placeholder', input.val());
input.val(''); // 清空输入框的值
}
followScroll();
}

21
src/modules/table.js

@ -84,6 +84,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var options = this.config || {};
var item3 = obj.item3; // 表头数据
var content = obj.content; // 原始内容
if (item3.type === 'numbers') content = obj.tplData[table.config.numbersName];
// 是否编码 HTML
var escaped = 'escape' in item3 ? item3.escape : options.escape;
@ -919,6 +920,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
Class.prototype.pullData = function(curr, opts){
var that = this;
var options = that.config;
// 同步表头父列的相关值
options.HAS_SET_COLS_PATCH || that.setColsPatch();
options.HAS_SET_COLS_PATCH = true;
var request = options.request;
var response = options.response;
var sort = function(){
@ -930,10 +934,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
});
}
};
var done = function(res){
var done = function(res, isRenderData){
that.setColsWidth();
typeof options.done === 'function' && options.done(
res, curr, res[response.countName]
res, curr, res[response.countName], isRenderData
);
};
@ -960,7 +964,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
curr: curr,
count: res[response.countName],
type: opts.type,
}), sort(), done(res);
}), sort(), done(res, true);
} else if(options.url){ // Ajax请求
var params = {};
// 当 page 开启,默认自动传递 page、limit 参数
@ -1229,10 +1233,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 渲染视图
var render = function(){ // 后续性能提升的重点
// 同步表头父列的相关值
options.HAS_SET_COLS_PATCH || that.setColsPatch();
options.HAS_SET_COLS_PATCH = true;
if(!sort && that.sortKey){
return that.sort({
field: that.sortKey.field,
@ -2444,6 +2444,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
var othis = $(this);
var td = othis.closest('td');
var index = othis.parents('tr').eq(0).data('index');
// 标记当前活动行
that.setRowActive(index);
// 执行事件
layui.event.call(
this,
@ -2456,8 +2459,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}
})
);
// 标记当前活动行
that.setRowActive(index);
};
// 行工具条单击事件
@ -2742,7 +2743,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
});
} else {
table.eachCols(id, function(i3, item3){
if(item3.field && item3.type == 'normal'){
if(item3.ignoreExport === false || item3.field && item3.type == 'normal'){
// 不导出隐藏列
if(item3.hide || item3.ignoreExport){
if(i1 == 0) fieldsIsHide[item3.field] = true; // 记录隐藏列

51
src/modules/treeTable.js

@ -54,11 +54,6 @@ layui.define(['table'], function (exports) {
return that || null;
}
// 获取当前实例配置项
var getThisTableConfig = function (id) {
return getThisTable(id).config;
}
// 字符
var MOD_NAME = 'treeTable';
var HIDE = 'layui-hide';
@ -166,9 +161,6 @@ layui.define(['table'], function (exports) {
if (treeOptions.data.isSimpleData) {
options.data = that.flatToTree(options.data);
}
if (options.initSort && options.initSort.type) {
layui.sort(options.data, options.initSort.field, options.initSort.type === 'desc', true)
}
that.initData(options.data);
}
@ -176,6 +168,10 @@ layui.define(['table'], function (exports) {
options.done = function () {
var args = arguments;
var doneThat = this;
var isRenderData = args[3]; // 是否是 renderData
if (!isRenderData) {
delete that.isExpandAll;
}
var tableView = this.elem.next();
that.updateStatus(null, {
@ -230,6 +226,7 @@ layui.define(['table'], function (exports) {
id: "id", // 唯一标识的属性名称
pid: "parentId", // 父节点唯一标识的属性名称
icon: "icon", // 图标的属性名称
expandAllDefault: false, // 默认展开所有节点
},
view: {
indent: 14, // 层级缩进量
@ -738,6 +735,7 @@ layui.define(['table'], function (exports) {
}
}
} else {
treeTableThat.isExpandAll = false;
// 关闭
if (sonSign && !isToggle) { // 非状态切换的情况下
layui.each(childNodes, function (i1, item1) {
@ -812,8 +810,9 @@ layui.define(['table'], function (exports) {
}
var that = getThisTable(id);
if(!that) return;
if (!that) return;
that.isExpandAll = expandFlag;
var options = that.getOptions();
var treeOptions = options.tree;
var tableView = options.elem.next();
@ -1012,6 +1011,10 @@ layui.define(['table'], function (exports) {
});
});
if (!level && treeOptions.view.expandAllDefault && that.isExpandAll === undefined) {
return treeTable.expandAll(tableId, true); // 默认展开全部
}
// 当前层的数据看看是否需要展开
if (sonSign !== false && dataExpand) {
layui.each(dataExpand, function (index, item) {
@ -1064,7 +1067,7 @@ layui.define(['table'], function (exports) {
});
// 根据需要处理options中的一些参数
updateOptions(that.config.id, options, type || true);
updateOptions(that.getOptions().id, options, type || true);
// 对参数进行深度或浅扩展
that.config = $.extend(deep, {}, that.config, options);
@ -1128,26 +1131,9 @@ layui.define(['table'], function (exports) {
if(!that) return;
var options = that.getOptions();
var initSort = options.initSort;
if (!options.url) {
if (initSort.type) {
layui.sort(options.data, initSort.field, initSort.type === 'desc', true);
} else {
layui.sort(options.data, table.config.indexName, null, true);
}
that.initData(options.data);
treeTable.reloadData(id);
} else {
// url异步取数的表格一般需要自己添加监听之后进行reloadData并且把排序参数加入到where中
if (options.autoSort) {
var tableData = that.initData();
var res = {};
res[options.response.dataName] = tableData;
typeof options.done === 'function' && options.done(
res, that.page, that.count
);
}
if (!options.url || options.autoSort) {
that.initData();
treeTable.renderData(id);
}
}
@ -1856,12 +1842,9 @@ layui.define(['table'], function (exports) {
// 重载
treeTable.reload = function (id, options, deep, type) {
deep = deep !== false; // 默认采用深拷贝
var config = getThisTableConfig(id); // 获取当前实例配置项
if (!config) return;
var that = getThisTable(id);
if (!that) return;
that.reload(options, deep, type);
return thisTreeTable.call(that);
};

Loading…
Cancel
Save