UNPKG

@beisen/ethos

Version:

beisencloud pc react components

132 lines (114 loc) 5.15 kB
'use strict'; var _typeof2 = require('babel-runtime/helpers/typeof'); var _typeof3 = _interopRequireDefault(_typeof2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var React = require('react'); var renderMenu = require('./renderMenu'); var renderRow = require('./renderRow'); var tableStyle = require('./tableStyle'); var slice = require('./slice'); //var LoadMask = require('react-load-mask') var assign = require('object-assign'); var normalize = require('react-style-normalizer'); function getData(props) { if (!props.virtualRendering) { return props.data; } return slice(props.data, props); } module.exports = function (props, rows, fixStatus) { var data = props.data ? props.data : props.dataSource, callIndex = props.startIndex; rows = rows || getData(props).map(function (data, index) { var _this = this; var AllRows = []; // 先加入本行数据 AllRows.push(renderRow.call(this, props, data, callIndex, fixStatus)); callIndex = callIndex + 1; // 树形表格相关 if (data.treeNode) { // 先展开所有的children数据,取出要展示的部分,注意只有展开的节点才需要渲染子数据 var treeNodes = [], showAllTreeNodes = function showAllTreeNodes(rowData, retract) { if (rowData.treeNode && rowData.treeNode.status === 'expand' && rowData.treeNode.children && rowData.treeNode.children.length > 0) { // 标记为展开,且children里有数据,为正常展开情况,展示所有子节点 rowData.treeNode.children.forEach(function (child) { // 记录目录深度,在单元格中计算左侧padding距离 child.retract = retract; treeNodes.push(child); showAllTreeNodes(child, retract + 1); }); } else if (rowData.treeNode && rowData.treeNode.status === 'expand' && !rowData.treeNode.children) { // 标记为展开,但是没有子节点定义,说明数据没有返回,展示加载中 treeNodes.push('loading'); } else if (rowData.treeNode && rowData.treeNode.status === 'expand' && rowData.treeNode.children && rowData.treeNode.children.length == 0) { // 标记为展开,且children里的数据为空,说明返回内容为空,展示为没有数据 treeNodes.push('nocontent'); } }; showAllTreeNodes(data, 1); var translation = props.translation; // 将所有树形节点加入展示队列 treeNodes.forEach(function (node, idx) { // 区分是否为数据节点 if ((typeof node === 'undefined' ? 'undefined' : (0, _typeof3.default)(node)) != 'object') { if (node === 'loading') { AllRows.push(React.createElement( 'div', { className: 'z-row tree-children-loading' }, React.createElement('div', { className: 'circle' }) )); } else if (node === 'nocontent') { AllRows.push(React.createElement( 'div', { className: 'z-row tree-children-empty' }, React.createElement( 'p', null, translation.contentEmpty ) )); } } else { AllRows.push(renderRow.call(_this, props, node, callIndex, fixStatus)); callIndex = callIndex + 1; } }); } // 树形表格相关 end return AllRows; }, this); //wuzhe----默认加阴影,在外部控制其显示隐藏 var fixLeftClass = 'z-table fixBodyLeft'; //wuzhe----由于像左固定列那样在内部处理遇到问题,因此右固定列默认添加阴影,通过在外部添加类控制该阴影的显示隐藏 var fixRightClass = 'z-table fixBodyRight fixRightShadow'; var backColor = "#fff"; if (props.style) { backColor = props.style.backgroundColor || "#fff"; } var fixStyle = { background: backColor }; var rollStyle = {}; if (fixStatus == "left") { fixStyle = assign({}, fixStyle, rollStyle); return { className: fixLeftClass, style: fixStyle, children: rows }; } if (fixStatus == "right") { fixStyle = assign({}, fixStyle, rollStyle); return { className: fixRightClass, style: fixStyle, children: rows }; } return { className: 'z-table', style: tableStyle(props), children: rows }; };