@aliretail/react-materials-components
Version:
104 lines (85 loc) • 4.66 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import * as React from 'react';
import * as R from 'ramda';
import cx from 'classnames';
import { AliretailTableContainer, AliretailTable, AliretailTableActionBar, AliretailTableDefaultPageSizeList, AliretailTableSetting, AliretailTableZebra, AliretailTableCompact, AliretailTableFullscreen, AliretailTablePagination } from "../../Tablex";
import WhaleButtonGroup from '@aliretail/react-whale-button-group';
import { SchemaField, FormPath } from '@formily/next';
import { toArr } from '@formily/shared';
export { AliretailTableDefaultPageSizeList };
export var TableX = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(TableX, _React$Component);
function TableX() {
return _React$Component.apply(this, arguments) || this;
}
var _proto = TableX.prototype;
// ArrayTable 折叠模式不可以销毁值,所以需要关闭 formily 的自动销毁状态开关
_proto.componentDidMount = function componentDidMount() {
var form = this.props.form;
form.disableUnmountClearStates();
};
_proto.actionBarRender = function actionBarRender() {
var _schema$properties;
var schema = this.props.schema;
var _ref = schema.getExtendsComponentProps() || {},
_ref$showTableSetting = _ref.showTableSetting,
showTableSetting = _ref$showTableSetting === void 0 ? false : _ref$showTableSetting;
var actionBarProperties;
if ((_schema$properties = schema.properties) !== null && _schema$properties !== void 0 && _schema$properties.actionBar) {
actionBarProperties = schema.properties.actionBar;
}
if (actionBarProperties || showTableSetting) {
return /*#__PURE__*/React.createElement(AliretailTableActionBar, null, /*#__PURE__*/React.createElement(WhaleButtonGroup, null, actionBarProperties && /*#__PURE__*/React.createElement(SchemaField, {
onlyRenderProperties: true,
schema: actionBarProperties
})), showTableSetting && /*#__PURE__*/React.createElement(WhaleButtonGroup, null, /*#__PURE__*/React.createElement(AliretailTableCompact, null), /*#__PURE__*/React.createElement(AliretailTableZebra, null), /*#__PURE__*/React.createElement(AliretailTableFullscreen, null), /*#__PURE__*/React.createElement(AliretailTableSetting, null)));
}
};
_proto.paginationRender = function paginationRender(paginationProps) {
if (paginationProps) {
return /*#__PURE__*/React.createElement(AliretailTablePagination, null);
}
};
_proto.render = function render() {
var _cx;
var _this$props = this.props,
className = _this$props.className,
schema = _this$props.schema,
value = _this$props.value,
props = _this$props.props,
path = _this$props.path;
var paginationProps = props.paginationProps;
var _ref2 = schema.getExtendsComponentProps() || {},
propClassName = _ref2.className,
dataSource = _ref2.dataSource,
defaultPaginationProps = _ref2.paginationProps,
expandedRowKey = _ref2.expandedRowKey;
var tableProps = R.omit(['className', 'dataSource', 'paginationProps', 'showTableSetting', 'expandedRowKey'], schema.getExtendsComponentProps() || {});
var classes = cx((_cx = {}, _cx[className] = !!className, _cx[propClassName] = !!propClassName, _cx));
var tableProperties = {
className: classes,
dataSource: toArr(value || dataSource),
expandedIndexSimulate: true,
paginationProps: defaultPaginationProps || paginationProps ? _extends({}, defaultPaginationProps, paginationProps) : false // 当出现锁列时通过 expandedRowIndent 来防止被锁列覆盖下层样式
// expandedRowIndent: [1, 1],
};
if (schema.properties) {
var childrenProperties = schema.properties;
if (childrenProperties.expandedRow) {
tableProperties.expandedRowRender = function (record, index) {
return /*#__PURE__*/React.createElement(SchemaField, {
key: FormPath.parse(path).concat(index, expandedRowKey || 'children').toString(),
path: FormPath.parse(path).concat(index, expandedRowKey || 'children'),
schema: childrenProperties.expandedRow
});
};
}
}
return /*#__PURE__*/React.createElement( // @ts-ignore
AliretailTableContainer, _extends({}, tableProperties, tableProps), // children
this.actionBarRender(), /*#__PURE__*/React.createElement(AliretailTable, null), this.paginationRender(tableProperties.paginationProps));
};
return TableX;
}(React.Component);
TableX.isFieldComponent = true;