@ttk/component
Version:
ttk组件库
1,470 lines (1,211 loc) • 163 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _extends = require('../extends-63327b06.js');
var defineProperty = require('../defineProperty-ad97b418.js');
var React = require('react');
var toConsumableArray = require('../toConsumableArray-27824572.js');
var getPrototypeOf = require('../getPrototypeOf-3a7a3df9.js');
var objectWithoutProperties = require('../objectWithoutProperties-2d29a867.js');
var ReactDOM = require('react-dom');
var antd = require('antd');
var immutable = require('immutable');
var reactResizable = require('react-resizable');
var Checkbox = require('../checkbox');
var NoData = require('../noData');
var classNames = require('classnames');
var _commonjsHelpers = require('../_commonjsHelpers-badc9712.js');
require('../unsupportedIterableToArray-94a305c4.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
var Checkbox__default = /*#__PURE__*/_interopDefaultLegacy(Checkbox);
var NoData__default = /*#__PURE__*/_interopDefaultLegacy(NoData);
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
}
function DecorateTable(target) {
target.prototype.getAppData = function (path, col) {
if (!path) {
return null;
}
var app;
if (!app) {
app = target.prototype.getDataFromLocalStorage(path); // this.contaienr.set(path, app)
}
if (!col) {
return app;
} else {
return app[col];
}
};
target.prototype.setAppData = function (path, data, col) {
if (!path || !data) {
return null;
}
var app = target.prototype.getAppData(path);
if (col) {
app[col] = data;
} else {
app = data;
} // this.contaienr.set(path, data)
target.prototype.setDataToLocalStorage(path, app);
};
target.prototype.clearAppData = function (path) {
localStorage.removeItem(path);
};
target.prototype.getDataFromLocalStorage = function (path) {
var appStr = localStorage.getItem(path);
if (!appStr) {
var obj = {};
target.prototype.setDataToLocalStorage(path, obj);
return obj;
}
var data = {};
try {
data = JSON.parse(appStr);
} catch (err) {
console.log(err);
}
return data;
};
target.prototype.setDataToLocalStorage = function (path, data) {
if (!path || !data || Object.prototype.toString.call(data) != '[object Object]') {
return;
}
localStorage.setItem(path, JSON.stringify(data));
};
return target;
}
var _class$2, _class2$2, _temp$2;
var _excluded$2 = ["onResize", "width"],
_excluded2 = ["noDataProps"],
_excluded3 = ["style"];
function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { defineProperty._defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var ResizeableTitle$2 = function ResizeableTitle(props) {
var onResize = props.onResize,
width = props.width,
restProps = objectWithoutProperties._objectWithoutProperties(props, _excluded$2);
if (!onResize) {
return /*#__PURE__*/React__default["default"].createElement("th", restProps);
}
return /*#__PURE__*/React__default["default"].createElement(reactResizable.Resizable, {
width: width ? width : 100,
height: 0,
onResize: onResize
}, /*#__PURE__*/React__default["default"].createElement("th", restProps));
};
var AntTable = DecorateTable(_class$2 = (_temp$2 = _class2$2 = /*#__PURE__*/function (_PureComponent) {
getPrototypeOf._inherits(AntTable, _PureComponent);
var _super = _createSuper$3(AntTable);
function AntTable(_props) {
var _this;
getPrototypeOf._classCallCheck(this, AntTable);
_this = _super.call(this, _props);
_this.memoryWidth = function (props) {
var remberName = props.remberName;
if (!remberName) {
return {};
}
var memoryWidth = _this.getAppData(remberName);
return memoryWidth;
};
_this.removeDom = function () {
var me = $(ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this)));
var table = me.find('table');
var point = table.find('.table-needDel');
var noDelCheckbox = _this.props.noDelCheckbox;
point.each(function (index, obj) {
var num = $(obj).attr('data-rol');
var sign = $(obj).parents('tr').find('.table-needDel2').attr('data-sign');
if (!sign) {
sign = $(obj).parents('tr').find('.table-needDel').attr('data-sign');
}
var backgroundColor = index % 2 == 0 ? '#fff' : '#F9F8FA ';
$(obj).parents('tr').css('background', backgroundColor).attr('data-background', backgroundColor).attr('data-hover', sign).find('td');
var next = $(obj).parents('tr');
for (var i = 0; i < num - 1; i++) {
if (!noDelCheckbox) {
next.eq(0).next().css('background', backgroundColor).attr('data-hover', sign).find('td');
} else {
next.eq(0).next().css('background', backgroundColor).attr('data-hover', sign).find('td').eq(0);
}
next = next.eq(0).next();
}
$(obj).parents('tbody').find("tr[data-hover=".concat(sign, "]")).hover(function () {
$(obj).parents('tbody').find("tr[data-hover=".concat(sign, "]")).addClass('mk-active');
$(".ant-table-fixed tbody").find("tr[data-hover=".concat(sign, "]")).addClass('mk-active');
}, function () {
$(obj).parents('tbody').find("tr[data-hover=".concat(sign, "]")).removeClass('mk-active');
$(".ant-table-fixed tbody").find("tr[data-hover=".concat(sign, "]")).removeClass('mk-active');
});
});
try {
var fixedTable = me.find('.ant-table-fixed');
var _point = table.find('.table-needDel2');
var num = _point.attr('data-rol');
_point.each(function (index, obj) {
var num = $(obj).attr('data-rol');
var sign = $(obj).attr('data-sign');
var backgroundColor = table.find("tr[data-hover=".concat(sign, "]")).eq(0).attr('data-background');
$(obj).parents('tr').attr('data-hover', sign).css('background', backgroundColor);
var next = $(obj).parents('tr').attr('data-hover', sign).find(".table-needDel2[data-sign=".concat(sign, "]"));
for (var i = 0; i < num - 1; i++) {
next.eq(0).next().attr('data-hover', sign).css('background', backgroundColor);
next = next.eq(0).next();
}
$(obj).parents('tr').hover(function () {
table.find("tr[data-hover=".concat(sign, "]")).addClass('mk-active');
fixedTable.find("tr[data-hover=".concat(sign, "]")).addClass('mk-active');
}, function () {
table.find("tr[data-hover=".concat(sign, "]")).removeClass('mk-active');
fixedTable.find("tr[data-hover=".concat(sign, "]")).removeClass('mk-active');
});
});
} catch (err) {}
};
_this.components = _this.props.components && _this.props.components instanceof Object ? _objectSpread$3(_objectSpread$3({}, _this.props.components), {}, {
header: {
cell: ResizeableTitle$2
}
}) : {
header: {
cell: ResizeableTitle$2
}
};
_this.handleResize = function (index) {
return function (e, _ref) {
var size = _ref.size;
var _this$state = _this.state,
columns = _this$state.columns;
_this$state.appContainerWidth; //删除操作列 key == 'voucherState'
columns.map(function (item, index) {
if (item.key && item.key == 'voucherState') {
columns.splice(index, 1);
} else {
columns = columns;
}
});
var Index = columns.findIndex(function (item) {
return item && item.dataIndex == index;
});
if (Index == -1) {
//index是-1代表拖拽的元素是子集
columns.map(function (m) {
if (m.children) {
m.children.map(function (n) {
if (n.dataIndex == index) {
n.width = size.width;
m.width += size.width - n.width;
}
});
} else {
return;
}
});
} else {
//拖拽的元素是父级
columns[Index].width;
columns[Index].width = size.width;
if (columns[Index].children) {
columns[Index].children.forEach(function (item) {
item.width = size.width / columns[Index].children.length;
});
}
}
var sumWidth = 0,
columnDetails = [],
param = {};
columns.forEach(function (item) {
if (!item.children) {
if (item.dataIndex) {
if (_this.props.NosaveWidth) {
columnDetails.push({
id: item.id,
fieldName: item.dataIndex,
width: item.width,
title: item.title,
isVisible: true,
customDecideVisible: true //控制哪一列显示隐藏
});
} else {
columnDetails.push({
id: item.id,
fieldName: item.dataIndex,
width: item.width,
isVisible: true,
customDecideVisible: true //控制哪一列显示隐藏
});
}
sumWidth = sumWidth + item.width;
}
} else {
item.width = 0;
item.children.forEach(function (child) {
item.width += child.width;
columnDetails.push(child);
});
columnDetails.push(item);
}
});
param.columnDetails = columnDetails;
_this.setState({
columns: columns,
sumWidth: _this.initStateWidth(columnDetails).sumWidth
});
var that = getPrototypeOf._assertThisInitialized(_this);
_this.onResizend(function () {
that.props.onResizeEnd(param);
});
};
};
_this.showTheadTitle = function (title) {
if (Object.prototype.toString.call(title) == "[object String]") {
return /*#__PURE__*/React__default["default"].createElement("span", {
title: title
}, title);
} else {
return title;
}
};
_this.onResizend = function (onResizend) {
/**
* <<<算法说明>>>
* ---------------------------------------------------------------------------------
* 1. 默认窗口状态 normal.
* 2. 调整窗口大小时状态 resizing.
* 3. 调整窗口大小时设置动作状态为 resizing, 并设置延时任务. 若已存在延时任务,则重新设置.
* 4. 若500毫秒后没有断续调整大小,则认为调整结束,执行resizend事件.
*/
var that = getPrototypeOf._assertThisInitialized(_this),
timeOutTask = function timeOutTask() {
that.state.taskPtr && clearTimeout(that.state.taskPtr);
var taskPtr = setTimeout(function () {
onResizend && onResizend();
}, 500);
that.setState({
taskPtr: taskPtr
});
};
timeOutTask();
};
_this.initStateWidth = function (data, columns, memoryWidth) {
if (!data) {
return [];
}
data.forEach(function (item) {
if (item.width) ;
});
var appContainerWidth = null;
try {
var dom;
if ($) {
dom = $('.edfx-app-portal-content-main')[0];
} else {
dom = document.getElementsByClassName('edfx-app-portal-content-main')[0];
}
if (dom) {
if (_this.props.id == 'app-detailaccount-rpt-Body-id') {
//明细账滚动条特殊处理
appContainerWidth = dom.offsetWidth - 160 + 80 - _this.props.subjectWidth - 120;
} else if (_this.props.id == 'app-sumaccount-rpt-Body-id' || _this.props.id == 'app-balancesum-rpt-Body-id') {
//总账和余额表滚动条做特殊处理
appContainerWidth = dom.offsetWidth - 160 + 80 - 120;
} else {
appContainerWidth = dom.offsetWidth - 160 + 80;
}
} else {
appContainerWidth = window.innerWidth - 100 - 160 + 80;
}
} catch (err) {
appContainerWidth = 1090;
}
Math.ceil(appContainerWidth / (data.length - 1));
var sumWidth1 = 0;
data.map(function (item) {
if (item.width) {
sumWidth1 = sumWidth1 + parseFloat(item.width);
}
});
var newCol = data.map(function (item) {
item.title = _this.showTheadTitle(item.title);
return item;
});
_this.state.appContainerWidth = appContainerWidth;
return {
newCol: newCol,
sumWidth: sumWidth1 > appContainerWidth ? sumWidth1 : appContainerWidth + 50
};
};
_this.winResize = function () {
if (_this.tid) clearTimeout(_this.tid); //防止执行两次
_this.tid = setTimeout(_this.setTableHeight, 300);
_this.getTableScroll();
};
_this.getTableScroll = function () {
// if ((!this.props.scroll || !this.props.scroll.y) && (this.props.dataSource && this.props.dataSource.length)) {
// return
// }
if (!_this.props.scroll || _this.props.scroll.hasOwnProperty('y') && !_this.props.scroll.y) {
return;
}
if (_this.timeId) clearTimeout(_this.timeId);
_this.timeId = setTimeout(function () {
try {
var container = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
var thead = container.getElementsByClassName('ant-table-thead')[0];
var tbody = container.getElementsByClassName('ant-table-tbody')[0];
var y = container.offsetHeight - thead.offsetHeight;
if (y > tbody.offsetHeight) {
y = undefined;
} // console.log(y, 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyy')
_this.setState({
y: y
});
} catch (err) {
console.log(err);
}
}, 300);
};
_this.setTableHeight = function () {
// 增加dynamicHeight的配置,是否动态控制高度
if (!_this.props.dynamicHeight) {
return;
} // if (this.tid) clearTimeout(this.tid)
// this.tid = setTimeout(() => {
try {
var container = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
var tableBody;
if ($) {
tableBody = $(container).find('.ant-table-body')[0];
} else {
tableBody = container.getElementsByClassName('ant-table-body')[0];
} // console.log(this.props.scroll, 'scroll')
// if (!this.props.dataSource || !this.props.dataSource.length) {
// // tableBody.style.height = container.offsetHeight + 'px'
// return
// }
if (!_this.props.scroll || _this.props.scroll.hasOwnProperty('y') && !_this.props.scroll.y) {
tableBody.style.height = 'auto'; //兼容清册申报表
return;
}
if (container.offsetHeight > 0) {
_this.setState({
height: container.offsetHeight
});
}
tableBody.style.height = container.offsetHeight === 0 ? '100%' : container.offsetHeight + 'px';
} catch (err) {
console.log(err);
} // }, 300);
};
_this.componentWillUnmount = function () {
if (_this.props.tableIsNotRefreshKey) {
var key = _this.props.tableIsNotRefreshKey;
var me = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
var dom = me.querySelector('.ant-table-body');
dom.removeEventListener('scroll', function (e) {
sessionStorage.setItem("".concat(key, "ScrollTop"), e.target.scrollTop); // window.tableScrollTop = e.target.scrollTop
}, false);
sessionStorage.setItem("".concat(key, "ScrollTop"), dom.scrollTop); // window.tableScrollTop = dom.scrollTop
}
var win = window;
if (win.removeEventListener) {
win.removeEventListener('resize', _this.winResize, false);
} else if (win.detachEvent) {
win.detachEvent('onresize', _this.winResize);
} else {
win.onresize = undefined;
}
if (_this.tid) clearTimeout(_this.tid);
if (_this.timeId) clearTimeout(_this.timeId);
};
_this.AjaxLoadJquerylibrary = function () {
var d = document;
if (d) {
var s = d.getElementById('jqscript');
if (s != null) return;
s = d.createElement('script');
s.type = 'text/javascript';
s.src = './vendor/jquery.min.js';
d.body.appendChild(s);
}
};
_this.getColumns = function () {
var columns;
if (_this.state.allowColResize) {
columns = _this.state.columns;
} else {
columns = _this.props.columns;
}
var children = immutable.fromJS(columns),
renderColumns = [];
if (!children || children.size == 0) {
return [];
}
for (var i = 0; i < children.size; i++) {
var child = children.get(i);
var column = _this.getColumnByMeta(child);
if (column) renderColumns.push(column);
}
return renderColumns;
};
_this.getColumnByMeta = function (meta) {
var children = meta.get('children'),
ret = _objectSpread$3({}, meta.toJS());
if (ret._visible === false) return undefined;
if (children && children.size > 0) {
ret.children = [];
children.map(function (sub) {
var o = _this.getColumnByMeta(sub);
if (!o) return;
if (!ret.children) ret.children = [];
ret.children.push(o);
});
}
return ret;
};
_this.initSelectValue = function (selcted, all) {
var selectValue = new immutable.Map();
var checkboxKey = _this.props.checkboxKey;
selcted.forEach(function (item) {
var i = all.find(function (key) {
return key[checkboxKey] == item;
});
selectValue = selectValue.set(item, i);
});
return selectValue;
};
_this.showCheckboxType = function () {
_this.state.selectValue;
var checkboxId = _this.initCheckboxId(_this.props.dataSource, 'get');
var obj = {};
if (!checkboxId.size) {
obj.checked = false;
} else if (_this.checkAllItem()) {
obj.checked = true;
} else if (_this.noCheckItem()) {
obj.checked = false;
} else {
obj.checked = false;
obj.indeterminate = true;
}
return obj;
};
_this.noCheckItem = function () {
var selectValue = _this.state.selectValue,
checkboxId = _this.initCheckboxId(_this.props.dataSource, 'get');
var flag = true;
checkboxId.map(function (item, key) {
if (selectValue.has(key)) {
flag = false;
}
}); // for (const key of checkboxId.keys()) {
// if (selectValue.has(key)) {
// flag = false
// }
// }
return flag;
};
_this.checkAllItem = function () {
var selectValue = _this.state.selectValue,
checkboxId = _this.initCheckboxId(_this.props.dataSource, 'get');
var flag = true;
checkboxId.map(function (item, key) {
if (!selectValue.has(key) && typeof key != "undefined") {
flag = false;
}
}); // for (const key of checkboxId.keys()) {
// if (!selectValue.has(key) && typeof key != "undefined") {
// flag = false
// }
// }
return flag;
};
_this.checkboxAllClick = function (e) {
var selectValue = _this.state.selectValue;
if (_this.initCheckboxId) {
var checkboxId = _this.initCheckboxId(_this.props.dataSource, 'get');
if (selectValue.size == 0) {
checkboxId.map(function (value, key) {
selectValue = selectValue.set(key, value);
});
} else if (_this.checkAllItem()) {
selectValue = new immutable.Map();
} else {
checkboxId.map(function (value, key) {
selectValue = selectValue.set(key, value);
});
}
_this.setState({
selectValue: selectValue
});
_this.update(selectValue);
}
};
_this.checkboxItemClick = function (e, key, record) {
var map = _this.state.selectValue;
if (!map.has(key)) {
map = map.set(key, record);
} else map = map.delete(key);
_this.setState({
selectValue: map
});
_this.update(map, record);
};
_this.initCheckboxId = function (data, type) {
if (!data) {
return;
}
data = data.filter(function (o) {
return o && o.batchcheckboxDisabled == false || o && o.batchcheckboxDisabled == undefined;
});
var map = new immutable.Map();
var checkboxKey = _this.props.checkboxKey;
data.forEach(function (item) {
if (item[checkboxKey] && !map.has(item[checkboxKey])) {
map = map.set(item[checkboxKey], item);
}
});
if (type == 'get') {
return map;
}
_this.setState({
checkboxId: map
});
};
_this.rowSpan = function (text, record, index) {
var checkboxKey = _this.props.checkboxKey;
var dataSource = _this.props.dataSource;
if (!record[checkboxKey]) return 1;
var key = dataSource.findIndex(function (item) {
return item[checkboxKey] == record[checkboxKey];
});
var num = 1;
if (key == index) {
var i = 0;
while (dataSource[index + i] && dataSource[index + i][checkboxKey] && dataSource[key] && dataSource[key][checkboxKey] && dataSource[index + i][checkboxKey] == dataSource[key][checkboxKey]) {
i++;
}
num = i;
} else {
num = 0;
}
return num;
};
_this.getcheckboxAllDisabled = function () {
var dataSource = _this.props.dataSource,
disabled = true;
var item = dataSource.find(function (o) {
if (!(o && o.batchcheckboxDisabled)) {
return o;
}
});
if (item) {
disabled = false;
}
return disabled;
};
_this.renderChekbox = function (type) {
var _this$props = _this.props,
checkboxKey = _this$props.checkboxKey,
checkboxFixed = _this$props.checkboxFixed;
var _this$state2 = _this.state,
selectValue = _this$state2.selectValue,
columns = _this$state2.columns;
if (type == 1) {
return {
title: /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], _extends._extends({}, _this.showCheckboxType(), {
onClick: _this.checkboxAllClick
})),
dataIndex: 'checkboxKey',
key: 'checkboxKey',
className: "mk-table-checkbox",
width: 34,
fixed: checkboxFixed ? checkboxFixed : '',
render: function render(text, record, index) {
var obj = {
children: record[checkboxKey] ? /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], {
checked: selectValue.has(record[checkboxKey]),
disabled: record['checkboxDisabled'],
onClick: function onClick(e) {
return _this.checkboxItemClick(e, record[checkboxKey], record);
}
}) : null,
props: {
rowSpan: _this.rowSpan(text, record, index)
}
};
return obj;
}
};
} else {
return [{
title: /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], _extends._extends({}, _this.showCheckboxType(), {
onClick: _this.checkboxAllClick
})),
dataIndex: 'checkboxKey',
key: 'checkboxKey',
width: 34,
className: "mk-table-checkbox",
render: function render(text, record, index) {
var obj = {
children: /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], {
checked: selectValue.has(record[checkboxKey]),
disabled: record['checkboxDisabled'],
onClick: function onClick(e) {
return _this.checkboxItemClick(e, record[checkboxKey], record);
}
}),
props: {
rowSpan: _this.rowSpan(text, record, index)
}
};
return obj;
}
}].concat(toConsumableArray._toConsumableArray(columns));
}
};
_this.update = function (data, record) {
if (_this.props.checkboxChange) {
var arr = [];
var arrValue = [];
_this.state.selectValue;
data.map(function (value, key) {
arr.push(key);
if (value && value.batchcheckboxDisabled == false || value && value.batchcheckboxDisabled == undefined) {
arrValue.push(value);
}
}); // for (const [key, value] of data.entries()) {
// arr.push(key)
// arrValue.push(value)
// }
_this.props.checkboxChange(arr, arrValue, record);
}
};
_this.rnederTitle = function (text) {
return /*#__PURE__*/React__default["default"].createElement("span", {
title: text
}, text);
};
_this.decorateColumns = function (columns) {
return columns.map(function (col, index) {
if (!(col.tip == false) && !col.render && col.dataIndex) {
col.render = _this.rnederTitle;
}
if (col.children) {
col.children.map(function (o) {
o.onHeaderCell = function (column) {
return {
width: column.width,
onResize: _this.handleResize(column.dataIndex)
};
};
});
}
if (_this.state.resizeColumn) {
return _objectSpread$3(_objectSpread$3({}, col), {}, {
onHeaderCell: function onHeaderCell(column) {
return {
width: column.width,
onResize: _this.handleResize(column.dataIndex)
};
}
});
} else {
return col;
}
});
};
_this.getChildrenTitle = function (item) {
var obj = _objectSpread$3(_objectSpread$3({}, item), {}, {
title: _this.showTheadTitle(item.title)
});
if (item.children) {
var arr = [];
if (typeof item.children.values == 'function') {
var _iterator = _createForOfIteratorHelper$2(item.children.values()),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var value = _step.value;
arr.push(_this.getChildrenTitle(value));
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
} else {
var _iterator2 = _createForOfIteratorHelper$2(item.children),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _value = _step2.value;
arr.push(_this.getChildrenTitle(_value));
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
}
obj.children = arr;
}
return obj;
};
_this.decorateHeaderTitle = function (column) {
if (!column) {
return undefined;
}
return column.map(function (item) {
return _this.getChildrenTitle(item);
});
};
_this.addColumn = function (data) {
var me = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
if (!me) {
return data;
}
var containerWidth = me.offsetWidth;
var setWidthSum = 0;
data.forEach(function (item) {
if (item.width) {
setWidthSum = setWidthSum + parseFloat(item.width);
}
});
if (setWidthSum > containerWidth) {
return data;
}
var remain = containerWidth - setWidthSum - 10;
if (_this.props.rowSelection) {
var columnWidth = _this.props.rowSelection.columnWidth;
if (typeof columnWidth === 'string') {
columnWidth = Number(columnWidth.replace(/px/g, ''));
}
columnWidth = columnWidth || 60;
remain -= columnWidth;
}
if (remain < 0) remain = 0;
var operateIndex = data.findIndex(function (item) {
return item.key && item.key == 'voucherState';
}); //找到操作列,把空白列插入到操作列之前
if (_this.props.id && _this.props.id !== 'app-detailaccount-rpt-Body-id' && _this.props.id !== 'app-sumaccount-rpt-Body-id' && _this.props.id !== 'app-balancesum-rpt-Body-id' || !_this.props.id) {
//明细账,总账和余额表不额外增加空白列
if (operateIndex != -1) {
data.splice(data.length - 1, 0, {
dataIndex: 'remain',
title: /*#__PURE__*/React__default["default"].createElement("span", null),
key: 'remain',
width: remain
});
} else {
data.splice(data.length, 0, {
dataIndex: 'remain',
title: /*#__PURE__*/React__default["default"].createElement("span", null),
key: 'remain',
width: remain
});
}
}
return data;
};
var memoryWidthLocalSotrage = _this.memoryWidth(_props);
_this.state = {
resizeColumn: _this.props.allowColResize,
selectValue: _props.checkboxValue ? _this.initSelectValue(_props.checkboxValue, _props.dataSource) : new immutable.Map(),
checkboxAllStatus: null,
checkboxId: new immutable.Map(),
columns: [],
memoryWidth: memoryWidthLocalSotrage,
sumWidth: 1090,
height: 0,
y: undefined
};
if (_this.props.allowColResize) {
var _this$initStateWidth = _this.initStateWidth(_props.columns, [], memoryWidthLocalSotrage),
newCol = _this$initStateWidth.newCol,
sumWidth = _this$initStateWidth.sumWidth;
_this.state.columns = newCol;
_this.state.sumWidth = sumWidth;
} // this.initCheckboxId(props.dataSource)
return _this;
}
getPrototypeOf._createClass(AntTable, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
var _this2 = this;
var memoryWidth = this.state.memoryWidth;
if (nextProps.checkboxKey) {
this.initCheckboxId(nextProps.dataSource);
}
if (nextProps.checkboxValue) {
var selectValue = this.initSelectValue(nextProps.checkboxValue, nextProps.dataSource);
this.setState({
selectValue: selectValue
});
}
if (nextProps.allowColResize) {
setTimeout(function () {
var _this2$initStateWidth = _this2.initStateWidth(nextProps.columns, _this2.state.columns, memoryWidth),
newCol = _this2$initStateWidth.newCol,
sumWidth = _this2$initStateWidth.sumWidth;
_this2.setState({
columns: newCol,
sumWidth: sumWidth
});
}, 20);
}
this.winResize();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
// this.removeDom()
if (this.state.resizeColumn) {
if (typeof $ == 'undefined' || $ == null) {
this.AjaxLoadJquerylibrary(); // window.setTimeout(function () {
// }, 100)
}
var me = $(ReactDOM__default["default"].findDOMNode(this));
var table = me.find('table');
var id = uuid();
table.attr('id', id); // changeColSize(id, this.onResize)
// 去掉所有col上面的width
// this.setColumnsWidth(id)
}
try {
var container = ReactDOM__default["default"].findDOMNode(this);
var header = container.getElementsByClassName('ant-table-header')[0];
var body = container.getElementsByClassName('ant-table-body')[0];
if (header && body && header.scrollLeft !== body.scrollLeft) {
header.scrollLeft = body.scrollLeft;
}
} catch (e) {}
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
var win = window;
if (win.addEventListener) {
win.addEventListener('resize', this.winResize, false);
} else if (win.attachEvent) {
win.attachEvent('onresize', this.winResize);
} else {
win.onresize = this.winResize;
} //tableIsNotRefreshKey为table组件记忆滚动条位置的标志
if (this.props.tableIsNotRefreshKey) {
var key = this.props.tableIsNotRefreshKey;
var me = ReactDOM__default["default"].findDOMNode(this);
var dom = me.querySelector('.ant-table-body');
dom.addEventListener('scroll', function (e) {
// console.log(e.target.scrollTop)
sessionStorage.setItem("".concat(key, "ScrollTop"), e.target.scrollTop); // window.tableScrollTop = e.target.scrollTop
}, false);
dom.scrollTop = sessionStorage.getItem("".concat(key, "ScrollTop")); // dom.scrollTop = window.tableScrollTop
} // 设置列表可拖动
// this.removeDom()
this.setTableHeight();
this.getTableScroll();
if (this.state.resizeColumn) {
if (typeof $ == 'undefined' || $ == null) {
this.AjaxLoadJquerylibrary(); // window.setTimeout(function () {
// }, 100)
}
var _me = $(ReactDOM__default["default"].findDOMNode(this));
var table = _me.find('table');
var id = uuid();
table.attr('id', id); // changeColSize(id)
// 去掉所有col上面的width
// this.setColumnsWidth(id)
}
try {
var height = ReactDOM__default["default"].findDOMNode(this).offsetHeight;
var titleHeight;
if ($) {
titleHeight = $('.ant-table-thead')[0].clientHeight;
} else {
titleHeight = document.getElementsByClassName('ant-table-thead')[0].clientHeight;
}
if (height !== this.state.height) {
this.setState({
height: height - titleHeight - 32,
titleHeight: titleHeight
});
}
} catch (err) {}
/**
* 合并首列包含CHECKBOX的情况
*/
}
}, {
key: "tBobyRect",
value: function tBobyRect() {
try {
var container = ReactDOM__default["default"].findDOMNode(this);
var tableBody = container.getElementsByClassName('ant-table-body')[0];
var titleHeight = container.getElementsByClassName('ant-table-fixed')[0].clientHeight;
return tableBody.clientHeight - titleHeight;
} catch (error) {
return 0;
}
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
_this$props2$noDataPr = _this$props2.noDataProps,
noDataProps = _this$props2$noDataPr === void 0 ? {} : _this$props2$noDataPr,
otherProps = objectWithoutProperties._objectWithoutProperties(_this$props2, _excluded2);
var noDataStyle = noDataProps.style,
restNoDataProps = objectWithoutProperties._objectWithoutProperties(noDataProps, _excluded3);
var _this$state3 = this.state;
_this$state3.columns;
var sumWidth = _this$state3.sumWidth,
y = _this$state3.y,
children = immutable.fromJS(this.props.columns),
height = this.state.height,
titleHeight = this.state.titleHeight,
size = undefined,
loading;
var bodyHeight = height - titleHeight;
if (bodyHeight >= 238) ; else if (bodyHeight <= 170) {
size = 'mini';
} else {
size = 'small';
} // if (otherProps.loading != undefined) {
loading = {
size: 'large',
delay: otherProps.delay || 30,
spinning: otherProps.loading || false,
tip: "数据加载中..."
}; // }
//table 控件自定义空数据描述
var emptyText = /*#__PURE__*/React__default["default"].createElement(NoData__default["default"], _extends._extends({
style: _objectSpread$3({}, noDataStyle),
size: size
}, restNoDataProps), this.props.emptyText || '暂无数据');
if (this.props.pureText) {
emptyText = this.props.pureText;
} // let locale = { 'emptyText': emptyText }
var scroll = {
y: y
};
if (this.props.scroll) {
if (this.props.scroll.hasOwnProperty('y') && (!this.props.scroll.y || this.props.scroll.y === true)) delete this.props.scroll.y;
scroll = _objectSpread$3(_objectSpread$3({}, scroll), this.props.scroll);
} //if (scroll.y === true || !this.props.dataSource || !this.props.dataSource.length) scroll.y = y
// if (!scroll.x) scroll.x = 1 // 金财管家使用,后续自行设置,其他项目默认关闭
if (children && children.size > 0) {
var _renderColumn = this.getColumns();
if (this.props.checkboxKey) {
_renderColumn = [this.renderChekbox(1)].concat(toConsumableArray._toConsumableArray(_renderColumn));
}
var columns3 = this.decorateColumns(_renderColumn);
this.decorateHeaderTitle(columns3);
var scrollX = this.props.dataSource && this.props.dataSource.length > 0 ? sumWidth : null;
if (this.props.emptyShowScroll) {
scrollX = sumWidth;
}
if (this.state.resizeColumn) {
return /*#__PURE__*/React__default["default"].createElement(antd.Table, _extends._extends({}, this.props, {
scroll: _objectSpread$3(_objectSpread$3({}, this.props.scroll), {}, {
y: y,
x: scrollX
}),
components: this.components,
columns: this.addColumn(this.decorateHeaderTitle(columns3)),
locale: {
'emptyText': emptyText
},
loading: loading
}));
} else {
return /*#__PURE__*/React__default["default"].createElement(antd.Table, _extends._extends({}, this.props, {
scroll: scroll,
components: this.components,
columns: this.decorateHeaderTitle(columns3),
locale: {
'emptyText': emptyText
},
loading: loading
}));
}
} else {
return /*#__PURE__*/React__default["default"].createElement(antd.Table, _extends._extends({}, this.props, {
scroll: scroll,
columns: this.decorateHeaderTitle(this.props.columns),
locale: {
'emptyText': emptyText
},
loading: loading
}));
}
}
}]);
return AntTable;
}(React.PureComponent), _class2$2.defaultProps = {
resizeColumn: true,
dynamicHeight: true
}, _temp$2)) || _class$2;
AntTable.Column = antd.Table.Column;
AntTable.ColumnGroup = antd.Table.ColumnGroup;
AntTable.rowSelection = antd.Table.rowSelection;
AntTable.selection = antd.Table.selection;
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { defineProperty._defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var TableLarge$1 = /*#__PURE__*/function (_PureComponent) {
getPrototypeOf._inherits(TableLarge, _PureComponent);
var _super = _createSuper$2(TableLarge);
function TableLarge(props) {
var _this;
getPrototypeOf._classCallCheck(this, TableLarge);
_this = _super.call(this, props);
_this.componentDidMount = function () {
var me = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
if (_this.props.scroll && _this.props.scroll.y === true) {
var tableThead = me.getElementsByClassName('ant-table-thead')[0];
var scorllY = me.offsetHeight - tableThead.offsetHeight;
_this.setState({
scorllY: scorllY
});
}
var dom = me.querySelector('.ant-table-body');
dom.addEventListener('scroll', function (e) {
var tr = me.querySelector('.ant-table-body table .lazy_table_last');
var top = me.querySelector('.ant-table-body').scrollTop;
if (!tr) {
me.querySelector('.ant-table-body table').offsetHeight;
var _this$state = _this.state;
_this$state.scorllY;
var scrollTop = _this$state.scrollTop,
rowHeight = _this$state.rowHeight;
if (Math.abs(scrollTop - top) < rowHeight) return;
}
_this.setState({
scrollTop: top
});
}, false);
};
_this.componentWillReceiveProps = function (nextProps) {
var scorllY = nextProps.scroll && nextProps.scroll.y || 300;
if (nextProps.scroll && nextProps.scroll.y === true) {
var me = ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
var tableThead = me.getElementsByClassName('ant-table-thead')[0];
scorllY = me.offsetHeight - tableThead.offsetHeight;
}
_this.setState({
rowHeight: nextProps.rowHeight || 36.8,
showRows: nextProps.showRows || 20,
scorllY: scorllY
});
};
_this.getDataSource = function (data) {
if (!data) {
return [];
}
ReactDOM__default["default"].findDOMNode(getPrototypeOf._assertThisInitialized(_this));
var _this$state2 = _this.state,
scrollTop = _this$state2.scrollTop,
rowHeight = _this$state2.rowHeight,
showRows = _this$state2.showRows,
scorllY = _this$state2.scorllY,
lens = data.length,
sumHeight = rowHeight * lens,
dataHeight = showRows * rowHeight,
polyFillHeight = (dataHeight - scorllY) / 2;
var firstHeight = 0,
lastHeight = 0;
if (scrollTop <= polyFillHeight) {
lastHeight = sumHeight - dataHeight;
} else {
firstHeight = scrollTop - polyFillHeight;
lastHeight = sumHeight - firstHeight - dataHeight;
}
var data2 = JSON.parse(JSON.stringify(data));
var dataStart = Math.floor(firstHeight / rowHeight);
_this.dataStart = dataStart;
_this.lastHeight = lastHeight;
var dataEnd = dataStart + showRows;
data2 = data2.slice(dataStart, dataEnd);
if (firstHeight > 0) {
data2.unshift({
name: 'first',
height: firstHeight
});
}
if (lastHeight > 0) {
data2.push({
name: 'last',
height: lastHeight
});
}
return data2;
};
_this.onRow = function (record, index) {
var style = {};
if (record.height) {
style.height = record.height + 'px';
}
var onRowByProps = _this.props.onRow ? _this.props.onRow(record, index) : {};
return _objectSpread$2({
className: record.height ? "lazy_table_tr lazy_table_".concat(record.name) : null,
style: style,
key: Math.random()
}, onRowByProps);
};
_this.renderColumns = function (data) {
var count = 0;
if (_this.dataStart == 0) {
count = 0;
} else {
count = _this.dataStart - 1;
}
return data.map(function (item) {
return item.render ? _objectSpread$2(_objectSpread$2({}, item), {}, {
render: function render(text, record, index) {
return item.render(text, record, index + count);
}
}) : _objectSpread$2({}, item);
});
};
_this.state = {
scrollTop: 0,
rowHeight: props.rowHeight || 36.8,
showRows: props.showRows || 20,
scorllY: props.scroll && props.scroll.y || 300
};
return _this;
}
getPrototypeOf._createClass(TableLarge, [{
key: "render",
value: function render() {
var scorllY = this.state.scorllY;
return /*#__PURE__*/React__default["default"].createElement(antd.Table, _extends._extends({}, this.props, {
onRow: this.onRow,
scroll: {
y: scorllY
},
pagination: false,
dataSource: this.getDataSource(this.props.dataSource),
columns: this.renderColumns(this.props.columns)
}));
}
}]);
return TableLarge;
}(React.PureComponent);
var _class$1, _class2$1, _temp$1;
var _excluded$1 = ["onResize", "width"];
function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, v