新增特性产出

This commit is contained in:
huayj 2019-08-23 13:48:27 +08:00
parent 3a7d33cdc0
commit 4825c40c4b
11 changed files with 464 additions and 169 deletions

View File

@ -29,7 +29,8 @@ var propTypes = {
fixed: _propTypes2["default"].oneOf([true, 'left', 'right']),
render: _propTypes2["default"].func,
onCellClick: _propTypes2["default"].func,
ifshow: _propTypes2["default"].bool
ifshow: _propTypes2["default"].bool,
fieldType: _propTypes2["default"].string // 类型
};
var Column = function (_Component) {

View File

@ -30,10 +30,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
//行控制管理
var ColumnManager = function () {
function ColumnManager(columns, elements, originWidth, rowDraggAble) {
function ColumnManager(columns, elements, originWidth, rowDraggAble, showRowNum) {
_classCallCheck(this, ColumnManager);
this._cached = {};
_initialiseProps.call(this);
//判断是否使用行拖拽
if (rowDraggAble) {
@ -50,10 +50,16 @@ var ColumnManager = function () {
}];
columns = dragHandleColumn.concat(columns);
}
columns = this.addOrderColumn(columns, showRowNum);
this.columns = columns || this.normalize(elements);
this.originWidth = originWidth;
}
// 向数据列中添加一列:序号
ColumnManager.prototype.isAnyColumnsFixed = function isAnyColumnsFixed() {
var _this = this;
@ -226,7 +232,8 @@ var ColumnManager = function () {
return element && (element.type === _Column2["default"] || element.type === _ColumnGroup2["default"]);
};
ColumnManager.prototype.reset = function reset(columns, elements) {
ColumnManager.prototype.reset = function reset(columns, elements, showRowNum) {
columns = this.addOrderColumn(columns, showRowNum);
this.columns = columns || this.normalize(elements);
this._cached = {};
};
@ -327,5 +334,29 @@ var ColumnManager = function () {
return ColumnManager;
}();
var _initialiseProps = function _initialiseProps() {
this._cached = {};
this.addOrderColumn = function (columns, showRowNum) {
if (!showRowNum) {
return columns;
}
var order = {
dataIndex: showRowNum.key || '_index',
key: '_index',
fixed: showRowNum.fixed || 'left',
width: showRowNum.width || 50,
title: showRowNum.name || '序号'
};
if (columns.length > 0 && columns[0].dataIndex !== 'checkbox' && columns[0].dataIndex !== 'radio') {
// 多选表格/单选表格时放在第二列,其他情况放到第一列
columns = [order].concat(columns);
} else {
columns.splice(1, 0, order); // splice方法改变原数组,返回切割出的数组,此处为[]
}
return columns;
};
};
exports["default"] = ColumnManager;
module.exports = exports['default'];

View File

@ -438,8 +438,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; }
@ -599,6 +599,11 @@
.u-table .u-table-drag-hidden-cont {
width: 100px;
height: 40px; }
.u-table .u-table-link {
cursor: pointer;
color: #0073E1; }
.u-table .u-table-link-underline:hover {
text-decoration: underline; }
.u-table:focus {
outline: none;

View File

@ -114,7 +114,10 @@ var propTypes = {
size: _propTypes2["default"].oneOf(['sm', 'md', 'lg']),
rowDraggAble: _propTypes2["default"].bool,
onDropRow: _propTypes2["default"].func,
onDragRowStart: _propTypes2["default"].func
onDragRowStart: _propTypes2["default"].func,
bodyDisplayInRow: _propTypes2["default"].bool, // 表格内容超出列宽度时进行换行 or 以...形式展现
headerDisplayInRow: _propTypes2["default"].bool, // 表头内容超出列宽度时进行换行 or 以...形式展现
showRowNum: _propTypes2["default"].object // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
};
var defaultProps = {
@ -161,7 +164,10 @@ var defaultProps = {
size: 'md',
rowDraggAble: false,
onDropRow: function onDropRow() {},
onDragRowStart: function onDragRowStart() {}
onDragRowStart: function onDragRowStart() {},
bodyDisplayInRow: true,
headerDisplayInRow: true,
showRowNum: false
};
var Table = function (_Component) {
@ -292,7 +298,7 @@ var Table = function (_Component) {
var expandedRowKeys = [];
var rows = [].concat(_toConsumableArray(props.data));
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, props.rowDraggAble);
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数
_this.store = (0, _createStore2["default"])({ currentHoverKey: null });
_this.firstDid = true;
if (props.defaultExpandAllRows) {
@ -376,12 +382,12 @@ var Table = function (_Component) {
});
}
if (nextProps.columns && nextProps.columns !== this.props.columns) {
this.columnManager.reset(nextProps.columns);
this.columnManager.reset(nextProps.columns, null, this.props.showRowNum); // 加入this.props.showRowNum参数
if (nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable) {
this.scrollTop = this.bodyTable.scrollTop;
}
} else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children);
this.columnManager.reset(null, nextProps.children, this.porps.showRowNum); // 加入this.props.showRowNum参数
}
//适配lazyload
if (nextProps.scrollTop > -1) {
@ -429,6 +435,7 @@ var Table = function (_Component) {
};
Table.prototype.componentWillUnmount = function componentWillUnmount() {
// 移除绑定事件,避免内存泄漏
this.contentTable = null;
_utils.EventUtil.removeHandler(this.contentTable, 'keydown', this.onKeyDown);
_utils.EventUtil.removeHandler(this.contentTable, 'focus', this.onFocus);
@ -830,6 +837,9 @@ var Table = function (_Component) {
var lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ? props.lazyLoad.endIndex : -1;
for (var i = 0; i < data.length; i++) {
var isHiddenExpandIcon = void 0;
if (props.showRowNum) {
data[i][props.showRowNum.key || '_index'] = i + (props.showRowNum.base || 0);
}
var record = data[i];
var key = this.getRowKey(record, i);
var childrenColumn = record[childrenColumnName];
@ -1041,7 +1051,7 @@ var Table = function (_Component) {
useFixedHeader = _props4.useFixedHeader,
data = _props4.data;
var bodyStyle = _extends({}, this.props.bodyStyle);
var bodyStyle = _extends({}, this.props.bodyStyle); // 这里为什么不写在上面?
var headStyle = {};
var innerBodyStyle = {};
var leftFixedWidth = this.columnManager.getLeftColumnsWidth(this.contentWidth);

View File

@ -44,6 +44,55 @@ var TableCell = function (_Component) {
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.renderLinkType = function (data, record) {
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var index = arguments[3];
var url = config.url,
urlIndex = config.urlIndex,
linkType = config.linkType,
className = config.className,
underline = config.underline,
descIndex = config.descIndex,
desc = config.desc,
linkColor = config.linkColor;
var linkUrl = '';
if (url) {
linkUrl = url(data, record, index);
} else if (urlIndex) {
linkUrl = record[urlIndex];
}
if (linkUrl) {
var link = function link() {
window.open(linkUrl, linkType || '_blank');
};
var cls = 'u-table-link ';
if (className) {
cls += className + ' ';
}
if (underline) {
cls += 'u-table-link-underline ';
}
var title = '';
if (desc === true) {
title = linkUrl;
} else if (typeof desc === 'string') {
title = desc;
} else if (typeof desc === 'function') {
title = desc(data, record, index);
} else if (descIndex) {
title = record[descIndex];
}
return _react2["default"].createElement(
'span',
{ onClick: link, className: cls, style: { color: linkColor || '' }, title: title },
data
);
}
return data;
};
_this.isInvalidRenderCellText = _this.isInvalidRenderCellText.bind(_this);
_this.handleClick = _this.handleClick.bind(_this);
return _this;
@ -63,6 +112,9 @@ var TableCell = function (_Component) {
}
};
// 渲染链接类型
TableCell.prototype.render = function render() {
var _props2 = this.props,
record = _props2.record,
@ -78,7 +130,9 @@ var TableCell = function (_Component) {
lazyStartIndex = _props2.lazyStartIndex,
lazyEndIndex = _props2.lazyEndIndex;
var dataIndex = column.dataIndex,
render = column.render;
render = column.render,
fieldType = column.fieldType,
linkConfig = column.linkConfig;
var _column$className = column.className,
className = _column$className === undefined ? '' : _column$className;
@ -99,6 +153,21 @@ var TableCell = function (_Component) {
}
}
// 根据 fieldType 来渲染数据
if (!render) {
switch (column.fieldType) {
case 'link':
{
text = this.renderLinkType(text, record, column.linkConfig, index);
break;
}
default:
{
break;
}
}
}
if (this.isInvalidRenderCellText(text)) {
text = null;
}

View File

@ -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; };
@ -35,115 +35,115 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
function dragColumn(Table) {
return function (_Component) {
_inherits(DragColumn, _Component);
return function (_Component) {
_inherits(DragColumn, _Component);
function DragColumn(props) {
_classCallCheck(this, DragColumn);
function DragColumn(props) {
_classCallCheck(this, DragColumn);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
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.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;
_this.onDragEnd = function (event, data) {
var dragSource = data.dragSource,
dragTarg = data.dragTarg;
var columns = _this.state.columns;
var sourceIndex = -1,
targetIndex = -1;
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;
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;
}
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);
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;
});
_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;
};
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']);
_this.state = {
columns: _this.setColumOrderByIndex(props.columns)
};
return _this;
}
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
}));
};
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);
return DragColumn;
}(_react.Component);
}
module.exports = exports['default'];

View File

@ -121,11 +121,14 @@ function multiSelect(Table, Checkbox) {
return Object.prototype.toString.call(o) == '[object Array]';
};
// 实现行点击时触发多选框勾选的需求
MultiSelect.prototype.render = function render() {
var columns = this.props.columns;
var data = this.state.data;
return _react2["default"].createElement(Table, _extends({}, this.props, { columns: this.getDefaultColumns(columns), data: data }));
return _react2["default"].createElement(Table, _extends({}, this.props, { columns: this.getDefaultColumns(columns), data: data, onRowClick: this.onRowClick }));
};
return MultiSelect;
@ -240,6 +243,13 @@ function multiSelect(Table, Checkbox) {
}];
return _defaultColumns.concat(columns);
};
this.onRowClick = function (record, index, event) {
_this2.onCheckboxChange('', record, index)();
if (_this2.props.onRowClick) {
_this2.props.onRowClick(record, index, event);
}
};
}, _temp;
}
module.exports = exports["default"];

View File

@ -125,6 +125,11 @@ function sort(Table, Icon) {
//点击置为“”时动态的设置相关column的orderNum值。并排序
// 默认的比较函数,即字符串比较函数
// 数值比较函数
SortTable.prototype._flatToColumn = function _flatToColumn(flatColumns) {
var colLen = flatColumns.length;
var parentIndex = void 0,
@ -335,8 +340,13 @@ function sort(Table, Icon) {
}
var sortButton = void 0;
if (column.sorter) {
// sorter和sortEnable均可触发排序,且sorter优先级更高
if (column.sorter || column.sortEnable) {
//大于0说明不是升序就是降序判断orderNum有没有值没有值赋值
if (column.sortEnable && !column.sorter) {
column.sorter = column.fieldType === 'number' ? _this3.numberSortFn(column.dataIndex) : _this3.defaultSortFn(column.dataIndex);
}
if (iconTypeIndex > 0 && !column.orderNum && mode == "multiple") {
column.orderNum = _this3.getOrderNum();
}
@ -369,6 +379,20 @@ function sort(Table, Icon) {
);
return column;
};
this.defaultSortFn = function (key) {
return function (a, b) {
return a[key] > b[key] ? 1 : -1;
};
};
this.numberSortFn = function (key) {
return function (a, b) {
var numberA = parseFloat(a[key]);
var numberB = parseFloat(b[key]);
return numberA > numberB ? 1 : -1;
};
};
}, _temp;
}
module.exports = exports['default'];

View File

@ -1,7 +1,7 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
@ -20,29 +20,29 @@ exports.ObjectAssign = ObjectAssign;
*/
function sortBy(arr, prop, desc) {
var props = [],
ret = [],
i = 0,
len = arr.length;
if (typeof prop == 'string') {
for (; i < len; i++) {
var oI = arr[i];
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
}
} else if (typeof prop == 'function') {
for (; i < len; i++) {
var _oI = arr[i];
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
}
} else {
throw '参数类型错误';
var props = [],
ret = [],
i = 0,
len = arr.length;
if (typeof prop == 'string') {
for (; i < len; i++) {
var oI = arr[i];
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
}
props.sort();
for (i = 0; i < len; i++) {
ret[i] = props[i]._obj;
} else if (typeof prop == 'function') {
for (; i < len; i++) {
var _oI = arr[i];
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
}
if (desc) ret.reverse();
return ret;
} else {
throw '参数类型错误';
}
props.sort();
for (i = 0; i < len; i++) {
ret[i] = props[i]._obj;
}
if (desc) ret.reverse();
return ret;
};
/**
@ -51,11 +51,11 @@ function sortBy(arr, prop, desc) {
* @param {} property
*/
function compare(property) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
};
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
};
}
/**
@ -63,17 +63,17 @@ function compare(property) {
* @param {*} obj 要拷贝的对象
*/
function ObjectAssign(obj) {
var b = obj instanceof Array;
var tagObj = b ? [] : {};
if (b) {
//数组
obj.forEach(function (da) {
var _da = {};
_extends(_da, da);
tagObj.push(_da);
});
} else {
_extends(tagObj, obj);
}
return tagObj;
var b = obj instanceof Array;
var tagObj = b ? [] : {};
if (b) {
//数组
obj.forEach(function (da) {
var _da = {};
_extends(_da, da);
tagObj.push(_da);
});
} else {
_extends(tagObj, obj);
}
return tagObj;
}

171
dist/demo.js vendored
View File

@ -37593,7 +37593,10 @@
size: _propTypes2['default'].oneOf(['sm', 'md', 'lg']),
rowDraggAble: _propTypes2['default'].bool,
onDropRow: _propTypes2['default'].func,
onDragRowStart: _propTypes2['default'].func
onDragRowStart: _propTypes2['default'].func,
bodyDisplayInRow: _propTypes2['default'].bool, // 表格内容超出列宽度时进行换行 or 以...形式展现
headerDisplayInRow: _propTypes2['default'].bool, // 表头内容超出列宽度时进行换行 or 以...形式展现
showRowNum: _propTypes2['default'].object // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
};
var defaultProps = {
@ -37640,7 +37643,10 @@
size: 'md',
rowDraggAble: false,
onDropRow: function onDropRow() {},
onDragRowStart: function onDragRowStart() {}
onDragRowStart: function onDragRowStart() {},
bodyDisplayInRow: true,
headerDisplayInRow: true,
showRowNum: false
};
var Table = function (_Component) {
@ -37771,7 +37777,7 @@
var expandedRowKeys = [];
var rows = [].concat(_toConsumableArray(props.data));
_this.columnManager = new _ColumnManager2['default'](props.columns, props.children, props.originWidth, props.rowDraggAble);
_this.columnManager = new _ColumnManager2['default'](props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数
_this.store = (0, _createStore2['default'])({ currentHoverKey: null });
_this.firstDid = true;
if (props.defaultExpandAllRows) {
@ -37855,12 +37861,12 @@
});
}
if (nextProps.columns && nextProps.columns !== this.props.columns) {
this.columnManager.reset(nextProps.columns);
this.columnManager.reset(nextProps.columns, null, this.props.showRowNum); // 加入this.props.showRowNum参数
if (nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable) {
this.scrollTop = this.bodyTable.scrollTop;
}
} else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children);
this.columnManager.reset(null, nextProps.children, this.porps.showRowNum); // 加入this.props.showRowNum参数
}
//适配lazyload
if (nextProps.scrollTop > -1) {
@ -37908,6 +37914,7 @@
};
Table.prototype.componentWillUnmount = function componentWillUnmount() {
// 移除绑定事件,避免内存泄漏
this.contentTable = null;
_utils.EventUtil.removeHandler(this.contentTable, 'keydown', this.onKeyDown);
_utils.EventUtil.removeHandler(this.contentTable, 'focus', this.onFocus);
@ -38309,6 +38316,9 @@
var lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ? props.lazyLoad.endIndex : -1;
for (var i = 0; i < data.length; i++) {
var isHiddenExpandIcon = void 0;
if (props.showRowNum) {
data[i][props.showRowNum.key || '_index'] = i + (props.showRowNum.base || 0);
}
var record = data[i];
var key = this.getRowKey(record, i);
var childrenColumn = record[childrenColumnName];
@ -38520,7 +38530,7 @@
useFixedHeader = _props4.useFixedHeader,
data = _props4.data;
var bodyStyle = _extends({}, this.props.bodyStyle);
var bodyStyle = _extends({}, this.props.bodyStyle); // 这里为什么不写在上面?
var headStyle = {};
var innerBodyStyle = {};
var leftFixedWidth = this.columnManager.getLeftColumnsWidth(this.contentWidth);
@ -40505,6 +40515,55 @@
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.renderLinkType = function (data, record) {
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var index = arguments[3];
var url = config.url,
urlIndex = config.urlIndex,
linkType = config.linkType,
className = config.className,
underline = config.underline,
descIndex = config.descIndex,
desc = config.desc,
linkColor = config.linkColor;
var linkUrl = '';
if (url) {
linkUrl = url(data, record, index);
} else if (urlIndex) {
linkUrl = record[urlIndex];
}
if (linkUrl) {
var link = function link() {
window.open(linkUrl, linkType || '_blank');
};
var cls = 'u-table-link ';
if (className) {
cls += className + ' ';
}
if (underline) {
cls += 'u-table-link-underline ';
}
var title = '';
if (desc === true) {
title = linkUrl;
} else if (typeof desc === 'string') {
title = desc;
} else if (typeof desc === 'function') {
title = desc(data, record, index);
} else if (descIndex) {
title = record[descIndex];
}
return _react2['default'].createElement(
'span',
{ onClick: link, className: cls, style: { color: linkColor || '' }, title: title },
data
);
}
return data;
};
_this.isInvalidRenderCellText = _this.isInvalidRenderCellText.bind(_this);
_this.handleClick = _this.handleClick.bind(_this);
return _this;
@ -40524,6 +40583,9 @@
}
};
// 渲染链接类型
TableCell.prototype.render = function render() {
var _props2 = this.props,
record = _props2.record,
@ -40539,7 +40601,9 @@
lazyStartIndex = _props2.lazyStartIndex,
lazyEndIndex = _props2.lazyEndIndex;
var dataIndex = column.dataIndex,
render = column.render;
render = column.render,
fieldType = column.fieldType,
linkConfig = column.linkConfig;
var _column$className = column.className,
className = _column$className === undefined ? '' : _column$className;
@ -40560,6 +40624,21 @@
}
}
// 根据 fieldType 来渲染数据
if (!render) {
switch (column.fieldType) {
case 'link':
{
text = this.renderLinkType(text, record, column.linkConfig, index);
break;
}
default:
{
break;
}
}
}
if (this.isInvalidRenderCellText(text)) {
text = null;
}
@ -85057,10 +85136,10 @@
//行控制管理
var ColumnManager = function () {
function ColumnManager(columns, elements, originWidth, rowDraggAble) {
function ColumnManager(columns, elements, originWidth, rowDraggAble, showRowNum) {
_classCallCheck(this, ColumnManager);
this._cached = {};
_initialiseProps.call(this);
//判断是否使用行拖拽
if (rowDraggAble) {
@ -85077,10 +85156,16 @@
}];
columns = dragHandleColumn.concat(columns);
}
columns = this.addOrderColumn(columns, showRowNum);
this.columns = columns || this.normalize(elements);
this.originWidth = originWidth;
}
// 向数据列中添加一列:序号
ColumnManager.prototype.isAnyColumnsFixed = function isAnyColumnsFixed() {
var _this = this;
@ -85253,7 +85338,8 @@
return element && (element.type === _Column2['default'] || element.type === _ColumnGroup2['default']);
};
ColumnManager.prototype.reset = function reset(columns, elements) {
ColumnManager.prototype.reset = function reset(columns, elements, showRowNum) {
columns = this.addOrderColumn(columns, showRowNum);
this.columns = columns || this.normalize(elements);
this._cached = {};
};
@ -85354,6 +85440,30 @@
return ColumnManager;
}();
var _initialiseProps = function _initialiseProps() {
this._cached = {};
this.addOrderColumn = function (columns, showRowNum) {
if (!showRowNum) {
return columns;
}
var order = {
dataIndex: showRowNum.key || '_index',
key: '_index',
fixed: showRowNum.fixed || 'left',
width: showRowNum.width || 50,
title: showRowNum.name || '序号'
};
if (columns.length > 0 && columns[0].dataIndex !== 'checkbox' && columns[0].dataIndex !== 'radio') {
// 多选表格/单选表格时放在第二列,其他情况放到第一列
columns = [order].concat(columns);
} else {
columns.splice(1, 0, order); // splice方法改变原数组,返回切割出的数组,此处为[]
}
return columns;
};
};
exports['default'] = ColumnManager;
module.exports = exports['default'];
@ -85392,7 +85502,8 @@
fixed: _propTypes2['default'].oneOf([true, 'left', 'right']),
render: _propTypes2['default'].func,
onCellClick: _propTypes2['default'].func,
ifshow: _propTypes2['default'].bool
ifshow: _propTypes2['default'].bool,
fieldType: _propTypes2['default'].string // 类型
};
var Column = function (_Component) {
@ -295324,11 +295435,14 @@
return Object.prototype.toString.call(o) == '[object Array]';
};
// 实现行点击时触发多选框勾选的需求
MultiSelect.prototype.render = function render() {
var columns = this.props.columns;
var data = this.state.data;
return _react2["default"].createElement(Table, _extends({}, this.props, { columns: this.getDefaultColumns(columns), data: data }));
return _react2["default"].createElement(Table, _extends({}, this.props, { columns: this.getDefaultColumns(columns), data: data, onRowClick: this.onRowClick }));
};
return MultiSelect;
@ -295443,6 +295557,13 @@
}];
return _defaultColumns.concat(columns);
};
this.onRowClick = function (record, index, event) {
_this2.onCheckboxChange('', record, index)();
if (_this2.props.onRowClick) {
_this2.props.onRowClick(record, index, event);
}
};
}, _temp;
}
module.exports = exports["default"];
@ -295662,6 +295783,11 @@
//点击置为“”时动态的设置相关column的orderNum值。并排序
// 默认的比较函数,即字符串比较函数
// 数值比较函数
SortTable.prototype._flatToColumn = function _flatToColumn(flatColumns) {
var colLen = flatColumns.length;
var parentIndex = void 0,
@ -295872,8 +295998,13 @@
}
var sortButton = void 0;
if (column.sorter) {
// sorter和sortEnable均可触发排序,且sorter优先级更高
if (column.sorter || column.sortEnable) {
//大于0说明不是升序就是降序判断orderNum有没有值没有值赋值
if (column.sortEnable && !column.sorter) {
column.sorter = column.fieldType === 'number' ? _this3.numberSortFn(column.dataIndex) : _this3.defaultSortFn(column.dataIndex);
}
if (iconTypeIndex > 0 && !column.orderNum && mode == "multiple") {
column.orderNum = _this3.getOrderNum();
}
@ -295906,6 +296037,20 @@
);
return column;
};
this.defaultSortFn = function (key) {
return function (a, b) {
return a[key] > b[key] ? 1 : -1;
};
};
this.numberSortFn = function (key) {
return function (a, b) {
var numberA = parseFloat(a[key]);
var numberB = parseFloat(b[key]);
return numberA > numberB ? 1 : -1;
};
};
}, _temp;
}
module.exports = exports['default'];

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long