UNPKG

ming-demo1

Version:
264 lines (222 loc) 9.79 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireWildcard(require("react")); var _env = _interopRequireDefault(require("../../helpers/env")); var Table = null; var TableContainer = function (_Component) { (0, _inherits2["default"])(TableContainer, _Component); function TableContainer(props) { var _this; (0, _classCallCheck2["default"])(this, TableContainer); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(TableContainer).call(this, props)); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "calcHeight", function () { var height = _this.initialHeight - _this.footerHeight - _this.cardHeaderHeight - _this.containersHeight - _this.listHeaderHeight; _this.setState({ height: height }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "recalcTableHeight", function (substractHeight, key) { var parents = _this.props.parents; if (parents && parents.key === key) _this.setState({ substractHeight: substractHeight }); }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getTableWidth", function (style, width) { var tableWidth = width; if (style.width) { tableWidth = style.width; } else if (style.diffWidth) { tableWidth = tableWidth - style.diffWidth; } else if (style.widthPercent) { tableWidth = tableWidth * style.widthPercent - (style.substractWidth || 0); } return tableWidth; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getBCalcHeight", function () { if (_this.listHeaderHeight || _this.containersHeight || _this.cardHeaderHeight || _this.footerHeight) return true;else return false; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getTableHeight", function (style, height) { var tableHeight = height; if (style.substract) { var substract = style.substract.split(','); substract.map(function (item) { if (!cb.utils.isEmpty(_this.substractMaps[item])) tableHeight = tableHeight - _this.substractMaps[item]; }); } var parents = _this.props.parents && _this.props.parents.type.trim().toLocaleLowerCase(); if (parents == 'linetabs') tableHeight = tableHeight - _this.substractMaps['linetabs']; if (style.substractHeight) tableHeight = tableHeight - style.substractHeight;else if (_this.state.substractHeight) tableHeight = _this.initialHeight - _this.state.substractHeight; if (!cb.utils.isEmpty(style.heightPercent)) tableHeight = tableHeight * parseFloat(style.heightPercent) / 100; if (_this.state.mode == 'browse') tableHeight = tableHeight - 30; return tableHeight; }); Table = _env["default"].INTERACTIVE_MODE === 'touch' ? require('../grid-touch')["default"] : require('../basic/table')["default"]; var meta = props.meta, viewModel = props.viewModel; var controls = meta.controls, cGroupCode = meta.cGroupCode, containers = meta.containers, childrenField = meta.childrenField, cCode = meta.cCode; var actions = containers && containers.length ? containers[0] : null; if (actions && actions.controls) { actions.controls.forEach(function (item) { if (!item.cParameter) return; try { var config = JSON.parse(item.cParameter); config.model = viewModel.get(item.cItemName); Object.assign(item, config); } catch (e) {} }); } var columns = {}; if (controls) { var _viewModel$getParams = viewModel.getParams(), billNo = _viewModel$getParams.billNo; controls.forEach(function (column) { var cItemName = column.cItemName, cStyle = column.cStyle; column.index = "".concat(billNo, "|").concat(cGroupCode, "|").concat(cItemName); columns[cItemName] = column; if (!cStyle || !actions || !actions.controls) return; try { var _JSON$parse = JSON.parse(cStyle), related = _JSON$parse.related; if (!related) return; var relatedActions = []; if (cb.utils.isArray(related)) { related.forEach(function (field) { var actionIndex = actions.controls.findIndex(function (item) { return item.cItemName === field; }); if (actionIndex === -1) return; relatedActions.push(actions.controls[actionIndex]); actions.controls.splice(actionIndex, 1); }); } else { var actionIndex = actions.controls.findIndex(function (item) { return item.cItemName === related; }); if (actionIndex === -1) return; relatedActions.push(actions.controls[actionIndex]); actions.controls.splice(actionIndex, 1); } column.relatedActions = relatedActions; } catch (e) {} }); } var controlModel = viewModel.get(childrenField || cCode); if (controlModel) { controlModel.setCache('actions', actions && actions.controls || []); controlModel.setCache('groupCode', cGroupCode); if (_env["default"].INTERACTIVE_MODE === 'touch') controlModel.setState('override', false); } else { cb.utils.alert('元数据配置有误', 'error'); } _this.initialHeight = props.height || document.body.clientHeight; _this.state = Object.assign({ controlModel: controlModel, columns: columns, actions: actions, height: _this.initialHeight, max: false }, viewModel.getParams()); _this.cardHeaderHeight = 0; _this.containersHeight = 0; _this.listHeaderHeight = 0; _this.footerHeight = 0; _this.GroupContainerHeights = {}; _this.substractMaps = { linetabs: 46 }; viewModel.on('listHeaderHeightUpdate', function (height) { _this.listHeaderHeight = height; _this.calcHeight(); }); viewModel.on('groupContainerHeightUpdate', function (args) { var height = args.height, cGroupCode = args.cGroupCode; _this.GroupContainerHeights[cGroupCode] = height; _this.containersHeight = 0; for (var key in _this.GroupContainerHeights) { _this.containersHeight += _this.GroupContainerHeights[key]; } _this.calcHeight(); }); viewModel.on('cardHeaderHeightUpdate', function (height) { _this.cardHeaderHeight = height; _this.calcHeight(); }); viewModel.on('footerHeightUpdate', function (height) { _this.footerHeight = height; _this.calcHeight(); }); return _this; } (0, _createClass2["default"])(TableContainer, [{ key: "componentDidMount", value: function componentDidMount() { this.props.viewModel.on('recalcTableHeight', this.recalcTableHeight); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this.props.viewModel.un('recalcTableHeight', this.recalcTableHeight); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if (this.props.height != nextProps.height) { this.initialHeight = nextProps.height; this.calcHeight(); } } }, { key: "render", value: function render() { var _this$props = this.props, meta = _this$props.meta, width = _this$props.width, viewModel = _this$props.viewModel; var style = meta.cStyle ? JSON.parse(meta.cStyle) : {}; var tableWidth = this.getTableWidth(style, width); var _this$state = this.state, controlModel = _this$state.controlModel, columns = _this$state.columns, actions = _this$state.actions, height = _this$state.height; var tableHeight = this.getTableHeight(style, height); var bCalcHeight = this.getBCalcHeight(); var extraConfig = {}; if (style.substractHeight || this.state.substractHeight) extraConfig.autoHeight = false; return _react["default"].createElement(Table, (0, _extends2["default"])({ width: tableWidth, height: tableHeight, bCalcHeight: bCalcHeight, code: meta.cGroupCode, viewModel: viewModel, action: actions, columns: columns, style: style, model: controlModel, meta: this.props.meta }, extraConfig)); } }]); return TableContainer; }(_react.Component); exports["default"] = TableContainer; //# sourceMappingURL=TableContainer.js.map