UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

234 lines (199 loc) 7.39 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import { __decorate } from "tslib"; import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { action } from 'mobx'; import KeyCode from '../../../es/_util/KeyCode'; import { getConfig } from '../../../es/configure'; import pick from 'lodash/pick'; import Table from '../table/Table'; import TableProfessionalBar from '../table/query-bar/TableProfessionalBar'; import { SelectionMode, TableMode, TableQueryBarType } from '../table/enum'; import { DataSetSelection } from '../data-set/enum'; var LovView = /*#__PURE__*/ function (_Component) { _inherits(LovView, _Component); var _super = _createSuper(LovView); function LovView() { var _this; _classCallCheck(this, LovView); _this = _super.apply(this, arguments); /* istanbul ignore next */ _this.handleKeyDown = function (e) { if (e.keyCode === KeyCode.ENTER) { var onEnterDown = _this.props.onEnterDown; onEnterDown(); } }; /** * 单选 onRow 处理 * @param props */ _this.handleRow = function (props) { var _this$props = _this.props, onDoubleClick = _this$props.onDoubleClick, tableProps = _this$props.tableProps; var tablePropsOnRow; if (tableProps === null || tableProps === void 0 ? void 0 : tableProps.onRow) tablePropsOnRow = tableProps.onRow(props); return _objectSpread({ onDoubleClick: onDoubleClick }, tablePropsOnRow); }; return _this; } _createClass(LovView, [{ key: "componentWillMount", value: function componentWillMount() { var _this$props2 = this.props, dataSet = _this$props2.dataSet, selection = _this$props2.dataSet.selection, multiple = _this$props2.multiple; this.selection = selection; dataSet.selection = multiple ? DataSetSelection.multiple : DataSetSelection.single; } }, { key: "componentWillUnmount", value: function componentWillUnmount() { var dataSet = this.props.dataSet; dataSet.selection = this.selection; } /* istanbul ignore next */ }, { key: "getColumns", value: function getColumns() { var _this$props3 = this.props, lovItems = _this$props3.config.lovItems, tableProps = _this$props3.tableProps; return lovItems ? lovItems.filter(function (_ref) { var gridField = _ref.gridField; return gridField === 'Y'; }).sort(function (_ref2, _ref3) { var seq1 = _ref2.gridFieldSequence; var seq2 = _ref3.gridFieldSequence; return seq1 - seq2; }).map(function (_ref4) { var display = _ref4.display, gridFieldName = _ref4.gridFieldName, gridFieldWidth = _ref4.gridFieldWidth, gridFieldAlign = _ref4.gridFieldAlign; var column = {}; if (tableProps && tableProps.columns) { column = tableProps.columns.find(function (c) { return c.name === gridFieldName; }); } return _objectSpread({}, column, { key: gridFieldName, header: display, name: gridFieldName, width: gridFieldWidth, align: gridFieldAlign, editor: false }); }) : undefined; } }, { key: "getQueryBar", value: function getQueryBar() { var _this$props4 = this.props, queryBar = _this$props4.config.queryBar, tableProps = _this$props4.tableProps; if (queryBar) { return queryBar; } if (tableProps && tableProps.queryBar) { return tableProps.queryBar; } } }, { key: "render", value: function render() { var _this$props5 = this.props, dataSet = _this$props5.dataSet, _this$props5$config = _this$props5.config, height = _this$props5$config.height, treeFlag = _this$props5$config.treeFlag, queryColumns = _this$props5$config.queryColumns, configTableProps = _this$props5$config.tableProps, multiple = _this$props5.multiple, tableProps = _this$props5.tableProps; var lovTableProps = _objectSpread({ customizable: getConfig('lovTableCustomizable'), autoFocus: true, mode: treeFlag === 'Y' ? TableMode.tree : TableMode.list, onKeyDown: this.handleKeyDown, dataSet: dataSet, columns: this.getColumns(), queryFieldsLimit: queryColumns, queryBar: this.getQueryBar() }, configTableProps, {}, tableProps); if (multiple) { lovTableProps.selectionMode = SelectionMode.rowbox; } else { lovTableProps.selectionMode = (tableProps === null || tableProps === void 0 ? void 0 : tableProps.selectionMode) ? tableProps.selectionMode : SelectionMode.none; lovTableProps.onRow = this.handleRow; } if (height) { lovTableProps.style = _objectSpread({}, lovTableProps.style, { height: height }); } var isProfessionalBar = getConfig('queryBar') === TableQueryBarType.professionalBar; if (!lovTableProps.queryBar && isProfessionalBar) { lovTableProps.queryBar = function (props) { return React.createElement(TableProfessionalBar, _extends({}, props, { queryBarProps: { labelWidth: 80 } })); }; } // 优化优先级 让 部分tableProps属性 的优先级大于dataSet的设置 // 目前需要处理 selectionMode _extends(lovTableProps, pick(_objectSpread({}, tableProps), ['selectionMode'])); return React.createElement(Table, _extends({}, lovTableProps)); } }]); return LovView; }(Component); export { LovView as default }; LovView.propTypes = { dataSet: PropTypes.object.isRequired, config: PropTypes.object.isRequired, tableProps: PropTypes.object, onDoubleClick: PropTypes.func.isRequired, onEnterDown: PropTypes.func.isRequired }; __decorate([action], LovView.prototype, "componentWillMount", null); __decorate([action], LovView.prototype, "componentWillUnmount", null); //# sourceMappingURL=LovView.js.map