1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | 1× 5× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 16× 1× 1200× 464× 464× 1× 1× 1× 1× 1× 464× 464× 464× 464× 464× 1× 204× 204× 204× 75× 129× 645× 129× 129× 516× 61× 129× 1× 5× 5× 5× 5× 1× 4× 3× 1× 1× 5× 1× 31× 31× 31× 31× 1× 1104× 1104× 1104× 1104× 1× 4× 4× 1× 1× 1× 1× 1× 1× 1× 1× 1× 5× 5× 10× 5× 5× 10× 10× 10× 5× 1× 4× 4× 4× 1× 600× 600× 600× 600× 600× 600× 600× 600× 600× 600× 5× 5× 595× 12× 12× 12× 12× 12× 12× 12× 583× 4× 4× 4× 4× 4× 4× 4× 579× 4× 4× 575× 31× 31× 31× 1× 30× 31× 544× 3× 541× 541× 600× 600× 1× 1× 1× 1× 1× 1× | 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _uxcoreConst = require('uxcore-const'); var _uxcoreConst2 = _interopRequireDefault(_uxcoreConst); var _classnames2 = require('classnames'); var _classnames3 = _interopRequireDefault(_classnames2); var _cloneDeep = require('lodash/cloneDeep'); var _cloneDeep2 = _interopRequireDefault(_cloneDeep); var _isEqual = require('lodash/isEqual'); var _isEqual2 = _interopRequireDefault(_isEqual); var _uxcoreDateCellField = require('uxcore-date-cell-field'); var _uxcoreDateCellField2 = _interopRequireDefault(_uxcoreDateCellField); var _uxcoreCheckboxCellField = require('uxcore-checkbox-cell-field'); var _uxcoreCheckboxCellField2 = _interopRequireDefault(_uxcoreCheckboxCellField); var _uxcoreButton = require('uxcore-button'); var _uxcoreButton2 = _interopRequireDefault(_uxcoreButton); var _uxcoreButtonGroup = require('uxcore-button-group'); var _uxcoreButtonGroup2 = _interopRequireDefault(_uxcoreButtonGroup); var _CheckBox = require('./CheckBox'); var _CheckBox2 = _interopRequireDefault(_CheckBox); var _Radio = require('./Radio'); var _Radio2 = _interopRequireDefault(_Radio); var _TextField = require('../CellField/TextField'); var _TextField2 = _interopRequireDefault(_TextField); var _SelectField = require('../CellField/SelectField'); var _SelectField2 = _interopRequireDefault(_SelectField); var _RadioField = require('../CellField/RadioField'); var _RadioField2 = _interopRequireDefault(_RadioField); var _util = require('../util'); var _util2 = _interopRequireDefault(_util); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _defineProperty(obj, key, value) { Iif (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } /** * Created by xy on 15/4/13. */ var fieldsMap = { select: _SelectField2['default'], text: _TextField2['default'], radio: _RadioField2['default'], date: _uxcoreDateCellField2['default'], check: _uxcoreCheckboxCellField2['default'] }; var Cell = function (_React$Component) { _inherits(Cell, _React$Component); function Cell(props) { _classCallCheck(this, Cell); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.showSubComp = _this.showSubComp.bind(_this); _this.handleCheckChange = _this.handleCheckChange.bind(_this); return _this; } Cell.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { // 需要考虑的 prop 包括 // column, rowData, rowIndex(s), index(s), cellIndex(s), hasSubComp(s) // rowSelection, actions, mode(s) var me = this; var shouldUpdate = false; // only tree mode has children if ('children' in nextProps) { return true; } ['rowIndex', 'index', 'cellIndex', 'hasSubComp', 'mode'].forEach(function (item) { Iif (me.props[item] !== nextProps[item]) { shouldUpdate = true; } }); Eif (!shouldUpdate) { ['column', 'rowSelection', 'rowData', 'actions'].forEach(function (item) { if (!(0, _isEqual2['default'])(me.props[item], nextProps[item])) { shouldUpdate = true; } }); } return shouldUpdate; }; /** * @param actions {Array|Object|Function} */ Cell.prototype.getActionItems = function getActionItems(actions) { Iif ((typeof actions === 'undefined' ? 'undefined' : _typeof(actions)) !== 'object' && typeof actions !== 'function') { console.error('Table: Actions should be an object/array/function'); return []; } var me = this; me.items = []; if (typeof actions === 'function') { me.items = actions(me.props.rowData); } else if (actions instanceof Array) { me.items = actions; } else { Object.keys(actions).forEach(function (item) { me.items.push({ title: item, callback: actions[item] }); }); } return me.items; }; Cell.prototype.getEditData = function getEditData() { var me = this; var column = me.props.column; var editKey = column.editKey || column.dataKey; return me.props.rowData[editKey]; }; Cell.prototype.getCellData = function getCellData(nextProps) { var props = nextProps || this.props; var column = props.column; var cellData = props.rowData[column.dataKey]; return cellData; }; Cell.prototype.handleCheckChange = function handleCheckChange(e) { var me = this; me.props.changeSelected(e.target.checked, me.props.rowIndex, false); }; Cell.prototype.handleActionClick = function handleActionClick(cb, e) { e.stopPropagation(); e.preventDefault(); if (cb) { cb(); } }; Cell.prototype.handleCellClick = function handleCellClick(e) { var me = this; var _me$props = me.props, column = _me$props.column, toggleSubCompOnRowClick = _me$props.toggleSubCompOnRowClick; var type = column.type; Iif (type === 'action' && toggleSubCompOnRowClick) { e.stopPropagation(); } }; Cell.prototype.showSubComp = function showSubComp() { this.props.showSubCompCallback.apply(); }; /** * @param {Object} column current column config * @param {Object} rowData current row data * @param {String} mode current row mode: edit or view, same as rowData['__mode__'] */ Cell.prototype.renderActionItems = function renderActionItems(column, rowData, mode) { var me = this; var actions = me.getActionItems(column.actions).filter(function (item) { return !('mode' in item) || item.mode === mode; }); var items = []; actions.forEach(function (action, index) { var content = action.render ? action.render(action.title, (0, _cloneDeep2['default'])(me.props.rowData)) : action.title; Eif (content) { items.push(_react2['default'].createElement( _uxcoreButton2['default'], { buttonType: action.buttonType, type: 'outline', key: index, disabled: typeof action.isDisable === 'function' ? action.isDisable(rowData) : false, onClick: me.handleActionClick.bind(me, (action.callback || function () {}).bind(me, rowData, me.props.root)) }, content )); } }); return _react2['default'].createElement( _uxcoreButtonGroup2['default'], { separated: true, size: 'small', maxLength: column.collapseNum, actionType: column.actionType || 'link', locale: me.props.locale }, items ); }; Cell.prototype.renderTreeIcon = function renderTreeIcon() { Eif (this.props.cellIndex === 0 && this.props.hasSubComp) { var open = this.props.rowData.showSubComp; return _react2['default'].createElement( 'span', { className: 'kuma-uxtable-tree-icon', onClick: this.showSubComp }, _react2['default'].createElement('i', { className: (0, _classnames3['default'])({ 'kuma-icon': true, 'kuma-icon-triangle-right': true, 'kuma-icon-triangle-right__open': open }) }) ); } return null; }; Cell.prototype.render = function render() { var _classnames, _this2 = this; var me = this; var props = me.props; var column = props.column; var width = column.width; var mode = props.rowData.__mode__; var style = { width: width || '100px', textAlign: props.column.align ? props.column.align : 'left' }; var content = (0, _cloneDeep2['default'])(props.rowData); var renderProps = void 0; if (column.type === 'action') { content = _react2['default'].createElement( 'div', { className: 'action-container' }, me.renderActionItems(column, content, mode) ); style.cursor = 'default'; } else if (column.type === 'checkbox' || column.type === 'checkboxSelector') { style.paddingRight = '4px'; style.paddingLeft = '12px'; var checked = me.getCellData(); var disable = props.rowSelection.isDisabled ? props.rowSelection.isDisabled(props.rowData) : false; Iif ('disable' in column) { disable = column.disable; } else Iif ('isDisable' in column) { disable = !!column.isDisable(props.rowData); } content = _react2['default'].createElement(_CheckBox2['default'], { disable: disable, mode: props.mode, align: props.column.align, checked: checked, onChange: me.handleCheckChange }); } else if (column.type === 'radioSelector') { style.paddingRight = '4px'; style.paddingLeft = '12px'; var _checked = me.getCellData(); var _disable = props.rowSelection.isDisabled ? props.rowSelection.isDisabled(props.rowData) : false; Iif ('disable' in column) { _disable = column.disable; } else Iif ('isDisable' in column) { _disable = !!column.isDisable(props.rowData); } content = _react2['default'].createElement(_Radio2['default'], { disable: _disable, mode: props.mode, align: props.column.align, checked: _checked, onChange: me.handleCheckChange }); } else if (column.type === 'treeIcon') { content = me.renderTreeIcon(); style.borderRight = 'none'; } else if ((column.type === 'custom' || column.type in fieldsMap) && mode === _uxcoreConst2['default'].MODE.EDIT && (!('canEdit' in column) || column.canEdit(props.rowData))) { // inline edit mode renderProps = { value: me.getEditData(), rowData: props.rowData, index: props.index, column: column, getTooltipContainer: function getTooltipContainer() { return props.bodyNode; }, handleDataChange: props.handleDataChange, attachCellField: props.attachCellField, detachCellField: props.detachCellField }; var Field = void 0; if (column.type === 'custom') { Field = props.column.customField; } else { Field = fieldsMap[column.type]; } content = _react2['default'].createElement(Field, renderProps); } else if (column.type === 'money' || column.type === 'card' || column.type === 'cnmobile') { content = _react2['default'].createElement( 'div', { className: 'default-cell', title: me.getCellData() }, _util2['default'].formatValue(me.getCellData(), column.type, column.delimiter) ); } else Iif (column.render) { content = column.render.apply(null, [me.getCellData(), content]); } else { content = _react2['default'].createElement( 'div', { className: 'default-cell', title: me.getCellData() }, me.getCellData() ); } var child = me.props.children; return _react2['default'].createElement( 'div', { className: (0, _classnames3['default'])((_classnames = {}, _defineProperty(_classnames, props.jsxprefixCls, true), _defineProperty(_classnames, 'last', props.last), _classnames)), style: style, onClick: function onClick(e) { _this2.handleCellClick(e); } }, child, content ); }; return Cell; }(_react2['default'].Component); Cell.propTypes = { cellIndex: _propTypes2['default'].number, hasSubComp: _propTypes2['default'].bool, rowData: _propTypes2['default'].object, jsxprefixCls: _propTypes2['default'].string, showSubCompCallback: _propTypes2['default'].func }; Cell.defaultProps = { jsxprefixCls: 'kuma-uxtable-cell', rowSelection: {} }; exports['default'] = Cell; module.exports = exports['default']; |