Browse Source

feat(treeTable): 支持 class 图标 (#1808)

pull/1828/head
morning-star 7 months ago committed by GitHub
parent
commit
1452d2a7b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      src/modules/treeTable.js

15
src/modules/treeTable.js

@ -83,6 +83,8 @@ layui.define(['table'], function (exports) {
var LAY_HAS_EXPANDED = 'LAY_HAS_EXPANDED'; var LAY_HAS_EXPANDED = 'LAY_HAS_EXPANDED';
var LAY_ASYNC_STATUS = 'LAY_ASYNC_STATUS'; var LAY_ASYNC_STATUS = 'LAY_ASYNC_STATUS';
var LAY_CASCADE = ['all', 'parent', 'children', 'none']; var LAY_CASCADE = ['all', 'parent', 'children', 'none'];
var HTML_TAG_RE = /<[^>]+?>/;
var ICON_PROPS = ['flexIconClose', 'flexIconOpen', 'iconClose', 'iconOpen', 'iconLeaf', 'icon']
/** /**
* 构造器 * 构造器
@ -209,6 +211,11 @@ layui.define(['table'], function (exports) {
} }
options.done.mod = true; options.done.mod = true;
} }
// 处理图标
layui.each(ICON_PROPS, function(i, iconProp){
options.tree.view[iconProp] = that.normalizedIcon(options.tree.view[iconProp]);
})
} }
Class.prototype.init = function () { Class.prototype.init = function () {
@ -277,6 +284,12 @@ layui.define(['table'], function (exports) {
}, },
}; };
Class.prototype.normalizedIcon = function(iconStr){
return iconStr
? HTML_TAG_RE.test(iconStr) ? iconStr : '<i class="' + iconStr +'"></i>'
: ''
}
Class.prototype.getOptions = function () { Class.prototype.getOptions = function () {
var that = this; var that = this;
if (that.tableIns) { if (that.tableIns) {
@ -1052,7 +1065,7 @@ layui.define(['table'], function (exports) {
((trData[customName.icon] || treeOptionsView.icon) ? ' layui-table-tree-iconCustom' : '') + ((trData[customName.icon] || treeOptionsView.icon) ? ' layui-table-tree-iconCustom' : '') +
(trData[isParentKey] ? '' : ' layui-table-tree-iconLeaf') + (trData[isParentKey] ? '' : ' layui-table-tree-iconLeaf') +
'">' + '">' +
(trData[customName.icon] || treeOptionsView.icon || (that.normalizedIcon(trData[customName.icon]) || treeOptionsView.icon ||
(trData[isParentKey] ? (trData[isParentKey] ?
(trData[LAY_EXPAND] ? treeOptionsView.iconOpen : treeOptionsView.iconClose) : (trData[LAY_EXPAND] ? treeOptionsView.iconOpen : treeOptionsView.iconClose) :
treeOptionsView.iconLeaf) || treeOptionsView.iconLeaf) ||

Loading…
Cancel
Save