UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

180 lines (179 loc) 8.47 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import * as React from 'react'; import { get, isNumber, set } from 'lodash'; import { observer } from 'mobx-react'; import { computed } from 'mobx'; import classnames from 'classnames'; import { Table as BaseTable } from '@qn-pandora/pandora-component'; import { ThresholdColorScope } from '../../../constants/table-style'; import { getColor } from '../../../components/Charts/TableChart/transform'; import bind from '../../../utils/bind'; import { EThemeTypes, ChartType } from '../../../constants'; import BasicComponent from '../BasicComponent'; import 'react-resizable/css/styles.css'; import * as styles from './style.mless'; var AntdTable = /** @class */ (function (_super) { __extends(AntdTable, _super); function AntdTable() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(AntdTable.prototype, "tableHeaderStyle", { get: function () { var _a = this.props, tableTitleFont = _a.tableTitleFont, tableTitleBgColor = _a.tableTitleBgColor, tableTitle = _a.tableOption.tableTitle; var settingTableTitle = __assign(__assign({}, tableTitleFont), { backgroundColor: tableTitleBgColor }); for (var key in tableTitle) { if (Object.prototype.hasOwnProperty.call(tableTitle, key) && (!get(settingTableTitle, key) || get(settingTableTitle, 'backgroundColor') === 'inherit')) { set(settingTableTitle, key, get(tableTitle, key)); } } return settingTableTitle; }, enumerable: false, configurable: true }); Object.defineProperty(AntdTable.prototype, "hasBgColorColumns", { get: function () { // 树形图不支持配置颜色 if (this.props.chartType === ChartType.TreeTable) return []; var columns = this.props.columns; return columns.filter(function (item) { if (item.showColor && item.thresholdColorScope === ThresholdColorScope.RowBg && item.splitter && ((item.splitter.rules || []).length > 0 || item.splitter.colorPalette.type)) { return true; } return false; }); }, enumerable: false, configurable: true }); Object.defineProperty(AntdTable.prototype, "trDisplayStyle", { get: function () { var _this = this; var hasFrColumn = false; var widths = this.props.columns.map(function (item, index) { var isLast = index === _this.props.columns.length - 1; // 如果配置项都是固定宽度,调整最后一列的样式,使其可以充满剩余空间 if (isLast && item.width && isNumber(item.width) && !hasFrColumn) { return "minmax(" + item.width + "px, 1fr)"; } if (item.width && isNumber(item.width)) { return item.width + "px"; } hasFrColumn = true; return '1fr'; }); // 注意最后一列设置为0px return { display: 'grid', gridTemplateColumns: "" + widths.join(' ') }; }, enumerable: false, configurable: true }); AntdTable.prototype.handleTableChange = function (_, filters) { var _a, _b; var res = []; for (var key in filters) { res.push({ key: key, value: filters[key] || [] }); } (_b = (_a = this.props).onColumnsFiltersChange) === null || _b === void 0 ? void 0 : _b.call(_a, res); }; AntdTable.prototype.render = function () { var _a; var _this = this; var _b = this.props, className = _b.className, columns = _b.columns, bordered = _b.bordered, dataSource = _b.dataSource, pagination = _b.pagination, _c = _b.theme, theme = _c === void 0 ? EThemeTypes.Light : _c, onSettingChange = _b.onSettingChange, size = _b.size, draggable = _b.draggable, tableOption = _b.tableOption; return (React.createElement(BaseTable, { className: classnames(styles.ketaPvTable, styles[theme], (_a = {}, _a[styles.bordered] = bordered, _a), className), columns: columns, dataSource: dataSource, rowKey: function (_, index) { return "row_" + index; }, pagination: pagination, draggable: draggable, scroll: { x: '100%' }, onChange: this.handleTableChange, onHeaderRow: function (_) { return { style: __assign(__assign({}, _this.trDisplayStyle), _this.tableHeaderStyle) }; }, onRow: function (record) { for (var i = _this.hasBgColorColumns.length - 1; i >= 0; i--) { var column = _this.hasBgColorColumns[i]; var color = getColor(column.thresholdType, 'inherit', column.isNumeric, column.splitter, get(record, [column.dataIndex, 'current'])); if (color !== 'inherit') { return { style: __assign(__assign({}, _this.trDisplayStyle), { backgroundColor: color, color: get(tableOption, 'color') }) }; } } return { style: __assign(__assign({}, _this.trDisplayStyle), { color: get(tableOption, 'color') }) }; }, onSettingChange: onSettingChange, size: size, needEmptyColumn: false })); }; AntdTable.defaultProps = { columns: [], dataSource: [], bordered: false, tableOption: {}, theme: EThemeTypes.Light }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], AntdTable.prototype, "tableHeaderStyle", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], AntdTable.prototype, "hasBgColorColumns", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], AntdTable.prototype, "trDisplayStyle", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], AntdTable.prototype, "handleTableChange", null); AntdTable = __decorate([ observer ], AntdTable); return AntdTable; }(BasicComponent)); export default AntdTable;