Skip to content

Commit

Permalink
feat: 提供column.sumThousandth属性,用于设置合计行是否开启千分位功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ShileiLiu committed Oct 14, 2020
1 parent 90f2de3 commit 0a8f8c3
Show file tree
Hide file tree
Showing 16 changed files with 4,999 additions and 6,259 deletions.
1,599 changes: 2 additions & 1,597 deletions CHANGELOG.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions build/Table.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
position: relative;
line-height: 1.33;
overflow: hidden; }
.u-table.copy .u-table-thead th {
user-select: unset; }
.u-table-body {
position: relative; }
.u-table-body .u-table-row-expand-columns-in-body .expand-icon-con {
Expand Down Expand Up @@ -458,8 +460,8 @@
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
/*
Introduced in IE 10.
/*
Introduced in IE 10.
*/
-ms-user-select: none;
user-select: none; }
Expand Down
9 changes: 7 additions & 2 deletions build/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ var Table = function (_Component) {
onDropBorder = _props2.onDropBorder,
onDraggingBorder = _props2.onDraggingBorder,
bodyDisplayInRow = _props2.bodyDisplayInRow,
headerEventNoStop = _props2.headerEventNoStop;
headerEventNoStop = _props2.headerEventNoStop,
onCopy = _props2.onCopy;

this.columnsChildrenList = []; //复杂表头拖拽,重新render表头前,将其置空
var rows = this.getHeaderRows(columns);
Expand Down Expand Up @@ -688,7 +689,8 @@ var Table = function (_Component) {
leftFixedWidth: leftFixedWidth,
rightFixedWidth: rightFixedWidth,
bodyDisplayInRow: bodyDisplayInRow,
eventNoStop: headerEventNoStop
eventNoStop: headerEventNoStop,
onCopy: onCopy
})) : null;
};

Expand Down Expand Up @@ -1640,6 +1642,9 @@ var Table = function (_Component) {
if (props.bordered) {
className += ' ' + clsPrefix + '-bordered';
}
if (props.onCopy) {
className += ' copy';
}
className += ' ' + clsPrefix + '-scroll-position-' + this.state.scrollPosition;
//如果传入height说明是固定高度
//内容过多折行显示时,height 属性会失效,为了避免产生错行
Expand Down
12 changes: 10 additions & 2 deletions build/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ var TableHeader = function (_Component) {
return _react2["default"].createElement(
"th",
_extends({}, da, keyTemp, { className: thClassName, "data-th-fixed": da.fixed, "data-line-key": da.key,
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable" }),
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable", onCopy: function onCopy(event) {
_this7.onCopy(da, columIndex, event);
} }),
da.children,

// && columIndex != _rowLeng
Expand All @@ -536,7 +538,7 @@ var TableHeader = function (_Component) {
da.onClick ? thDefaultObj.onClick = function (e) {
da.onClick(da, e);
} : "";
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width } }));
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width }, onCopy: _this7.onCopy }));
}
})
);
Expand Down Expand Up @@ -1051,6 +1053,12 @@ var _initialiseProps = function _initialiseProps() {
return _react2["default"].createElement("div", null);
}
};

this.onCopy = function (data, index, event) {
if (_this8.props.onCopy) {
_this8.props.onCopy(_extends(data, { col: index }), event);
}
};
};

TableHeader.propTypes = propTypes;
Expand Down
10 changes: 6 additions & 4 deletions build/lib/bigData.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ function bigData(Table) {
_this.treeType = isTreeType;
//fix: 滚动加载场景中,数据动态改变下占位计算错误的问题(26 Jun)
if (newData.toString() !== props.data.toString()) {

_this.cachedRowHeight = []; //缓存每行的高度
_this.cachedRowParentIndex = [];
_this.computeCachedRowParentIndex(newData);
// fix:切换数据源,startIndex、endIndex错误
_this.currentIndex = 0;
_this.startIndex = _this.currentIndex; //数据开始位置
_this.endIndex = _this.currentIndex + _this.loadCount;
if (_this.scrollTop <= 0) {
// 增加scrollTop 判断,ncc场景下滚动条不在最上层, 会出现空白,因为重置了currentIndex没有重置滚动条
_this.currentIndex = 0;
_this.startIndex = _this.currentIndex; //数据开始位置
_this.endIndex = _this.currentIndex + _this.loadCount;
}
}
_this.treeData = [];
_this.flatTreeData = [];
Expand Down
216 changes: 108 additions & 108 deletions build/lib/dragColumn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
Expand Down Expand Up @@ -35,115 +35,115 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"

function dragColumn(Table) {

return function (_Component) {
_inherits(DragColumn, _Component);

function DragColumn(props) {
_classCallCheck(this, DragColumn);

var _this = _possibleConstructorReturn(this, _Component.call(this, props));
return function (_Component) {
_inherits(DragColumn, _Component);

function DragColumn(props) {
_classCallCheck(this, DragColumn);

var _this = _possibleConstructorReturn(this, _Component.call(this, props));

_this.setColumOrderByIndex = function (_column) {
_column.forEach(function (da, i) {
da.dragIndex = i;
da.drgHover = false;
});
return _column;
};

_this.onDragEnd = function (event, data) {
var dragSource = data.dragSource,
dragTarg = data.dragTarg;
var columns = _this.state.columns;

var sourceIndex = -1,
targetIndex = -1;

sourceIndex = columns.findIndex(function (da, i) {
return da.key == dragSource.key;
});
targetIndex = columns.findIndex(function (da, i) {
return da.key == dragTarg.key;
});
// 向前移动
if (targetIndex < sourceIndex) {
targetIndex = targetIndex + 1;
}
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
var _newColumns = [];
columns.forEach(function (da, i) {
var newDate = _extends(da, {});
newDate.title = da.title;
_newColumns.push(newDate);
});
_this.setState({
columns: _newColumns //cloneDeep(columns)
});
if (_this.props.onDragEnd) {
_this.props.onDragEnd(event, data, columns);
}
};

_this.getTarget = function (evt) {
return evt.target || evt.srcElement;
};

_this.state = {
columns: _this.setColumOrderByIndex(props.columns)
};
return _this;
}

_this.setColumOrderByIndex = function (_column) {
_column.forEach(function (da, i) {
da.dragIndex = i;
da.drgHover = false;
DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (nextProps.columns != this.props.columns) {
this.setState({
columns: this.setColumOrderByIndex(nextProps.columns)
});
}
};

DragColumn.prototype.recursion = function (_recursion) {
function recursion(_x) {
return _recursion.apply(this, arguments);
}

recursion.toString = function () {
return _recursion.toString();
};

return recursion;
}(function (obj) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

for (key in obj) {
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
data[key] = recursion(obj[key]);
} else {
data[key] = obj[key];
}
}
return data;
});
return _column;
};

_this.onDragEnd = function (event, data) {
var dragSource = data.dragSource,
dragTarg = data.dragTarg;
var columns = _this.state.columns;

var sourceIndex = -1,
targetIndex = -1;

sourceIndex = columns.findIndex(function (da, i) {
return da.key == dragSource.key;
});
targetIndex = columns.findIndex(function (da, i) {
return da.key == dragTarg.key;
});
// 向前移动
if (targetIndex < sourceIndex) {
targetIndex = targetIndex + 1;
}
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
var _newColumns = [];
columns.forEach(function (da, i) {
var newDate = _extends(da, {});
newDate.title = da.title;
_newColumns.push(newDate);
});
_this.setState({
columns: _newColumns //cloneDeep(columns)
});
if (_this.props.onDragEnd) {
_this.props.onDragEnd(event, data, columns);
}
};

_this.getTarget = function (evt) {
return evt.target || evt.srcElement;
};

_this.state = {
columns: _this.setColumOrderByIndex(props.columns)
};
return _this;
}

DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (nextProps.columns != this.props.columns) {
this.setState({
columns: this.setColumOrderByIndex(nextProps.columns)
});
}
};

DragColumn.prototype.recursion = function (_recursion) {
function recursion(_x) {
return _recursion.apply(this, arguments);
}

recursion.toString = function () {
return _recursion.toString();
};

return recursion;
}(function (obj) {
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

for (key in obj) {
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
data[key] = recursion(obj[key]);
} else {
data[key] = obj[key];
}
}
return data;
});

DragColumn.prototype.render = function render() {
var _props = this.props,
data = _props.data,
dragborder = _props.dragborder,
draggable = _props.draggable,
className = _props.className,
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);

return _react2["default"].createElement(Table, _extends({}, others, {
columns: this.state.columns,
data: data,
className: className + ' u-table-drag-border',
onDragEnd: this.onDragEnd,
draggable: draggable,
dragborder: dragborder
}));
};

return DragColumn;
}(_react.Component);
DragColumn.prototype.render = function render() {
var _props = this.props,
data = _props.data,
dragborder = _props.dragborder,
draggable = _props.draggable,
className = _props.className,
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);

return _react2["default"].createElement(Table, _extends({}, others, {
columns: this.state.columns,
data: data,
className: className + ' u-table-drag-border',
onDragEnd: this.onDragEnd,
draggable: draggable,
dragborder: dragborder
}));
};

return DragColumn;
}(_react.Component);
}
module.exports = exports['default'];
21 changes: 20 additions & 1 deletion build/lib/sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ function sum(Table) {
}
});
var _sum = (0, _utils.DicimalFormater)(count, precision);
if (column.sumThousandth) {
_sum = _this.toThousands(_sum);
}
sumdata[column.dataIndex] = _sum;
if (column.sumRender && typeof column.sumRender == 'function') {
sumdata[column.dataIndex] = column.sumRender(_sum);
Expand All @@ -114,10 +117,26 @@ function sum(Table) {

/**
* 获取当前的表格类型。
*
*
*/


SumTable.prototype.toThousands = function toThousands(num) {
var result = '',
counter = 0;
num = (num || 0).toString();
var numArr = num.split('.');
num = numArr[0];
for (var i = num.length - 1; i >= 0; i--) {
counter++;
result = num.charAt(i) + result;
if (!(counter % 3) && i != 0) {
result = ',' + result;
}
}
return numArr.length === 1 ? result : result + '.' + numArr[1];
};

SumTable.prototype.render = function render() {
return _react2["default"].createElement(Table, _extends({}, this.props, {
columns: this.props.columns,
Expand Down
Loading

0 comments on commit 0a8f8c3

Please sign in to comment.