UNPKG

nsn-comp

Version:

NSN核心组件

149 lines (121 loc) 5.86 kB
function ownKeys(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(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(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(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(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; } import { StatusEnum } from 'nsn-enum'; import { NLocale, NType } from 'nsn-util'; import React from 'react'; import { OptionsColumn, StatusColumn } from '../_comp'; /** * 表格列 * * @param comp 页面组件对象 */ var getColumns = function getColumns(comp) { var table = comp.props.table; var columns = table.columns, _table$columnsProps = table.columnsProps, columnsProps = _table$columnsProps === void 0 ? {} : _table$columnsProps, tree = table.tree; var index = columnsProps.index, status = columnsProps.status, option = columnsProps.option, fixIndex = columnsProps.fixIndex, fixOption = columnsProps.fixOption; // 序号列 var indexColumnTitle = NLocale.getText('common.index'); var indexColumnWidth = 80; if (index) { indexColumnTitle = index.title || indexColumnTitle; indexColumnWidth = index.width || indexColumnWidth; } var indexColumn = { title: indexColumnTitle, dataIndex: 'index', valueType: 'index', width: indexColumnWidth, fixed: fixIndex ? 'left' : undefined }; // 状态列 var statusColumnTitle = NLocale.getText('common.status'); var statusColumnWidth = 120; if (status && !NType.isString(status)) { statusColumnTitle = status.title || statusColumnTitle; statusColumnWidth = status.width || statusColumnWidth; } var statusColumn = { title: statusColumnTitle, dataIndex: 'status', width: statusColumnWidth, search: false, hideInForm: true, align: 'center', filters: [{ text: NLocale.getText('common.enable'), value: StatusEnum.NORMAL }, { text: NLocale.getText('common.disable'), value: StatusEnum.DISABLE }], render: function render(_, record) { return React.createElement(StatusColumn, Object.assign({}, { comp: comp, record: record })); } }; // 操作列 var optionColumnTitle = NLocale.getText('common.option'); var optionColumnWidth = 100; if (option && !NType.isArray(option)) { optionColumnTitle = option.title || optionColumnTitle; optionColumnWidth = option.width || optionColumnWidth; } var optionColumn = { title: optionColumnTitle, dataIndex: 'option', valueType: 'option', width: optionColumnWidth, align: 'center', render: function render(_, record) { return React.createElement(OptionsColumn, Object.assign({}, { comp: comp, record: record })); }, fixed: fixOption ? 'right' : undefined }; // 组合 var allColumns = []; if (index !== false && !tree) { allColumns.push(indexColumn); } var newColumns = []; if (NType.isArray(columns)) { newColumns.push.apply(newColumns, _toConsumableArray(columns)); } else if (NType.isFunction(columns)) { newColumns.push.apply(newColumns, _toConsumableArray(columns(comp))); } allColumns.push.apply(allColumns, _toConsumableArray(newColumns.map(function (col) { var _col$fieldProps = col.fieldProps, fieldProps = _col$fieldProps === void 0 ? {} : _col$fieldProps; var _fieldProps$style = fieldProps.style, style = _fieldProps$style === void 0 ? {} : _fieldProps$style; return _objectSpread(_objectSpread({}, col), {}, { fieldProps: _objectSpread(_objectSpread({}, fieldProps), {}, { style: _objectSpread({ width: '100%' }, style) }) }); }))); if (status) { allColumns.push(statusColumn); } if (option !== false) { allColumns.push(optionColumn); } return allColumns; }; export { getColumns };