UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

162 lines (161 loc) 12.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableRow = void 0; var tslib_1 = require("tslib"); var mobx_react_1 = require("mobx-react"); var react_1 = (0, tslib_1.__importDefault)(require("react")); var helper_1 = require("../../utils/helper"); var SimpleSpan_1 = (0, tslib_1.__importDefault)(require("../Table/simpleTableCell/SimpleSpan")); var tpl_builtin_1 = require("../../utils/tpl-builtin"); var tpl_1 = require("../../utils/tpl"); var TableRow = /** @class */ (function (_super) { (0, tslib_1.__extends)(TableRow, _super); function TableRow(props) { var _this = _super.call(this, props) || this; // reaction?: () => void; _this.dom = react_1.default.createRef(); _this.handleAction = _this.handleAction.bind(_this); _this.handleQuickChange = _this.handleQuickChange.bind(_this); _this.handleChange = _this.handleChange.bind(_this); _this.handleItemClick = _this.handleItemClick.bind(_this); return _this; } TableRow.prototype.componentDidMount = function () { var _a = this.props, item = _a.item, headCurrentRows = _a.headCurrentRows, itemAction = _a.itemAction; if (item.index === 0 && itemAction) { headCurrentRows === null || headCurrentRows === void 0 ? void 0 : headCurrentRows(item.index, this.dom); } }; // 定义点击一行的行为,通过 itemAction配置 TableRow.prototype.handleItemClick = function (e) { if ((0, helper_1.isClickOnInput)(e)) { return; } var _a = this.props, itemAction = _a.itemAction, onAction = _a.onAction, item = _a.item, headCurrentRows = _a.headCurrentRows, checkOnItemClick = _a.checkOnItemClick, onCheck = _a.onCheck; headCurrentRows === null || headCurrentRows === void 0 ? void 0 : headCurrentRows(item.index, this.dom); if (itemAction) { onAction === null || onAction === void 0 ? void 0 : onAction(e, itemAction, item === null || item === void 0 ? void 0 : item.data); } if (checkOnItemClick) { onCheck === null || onCheck === void 0 ? void 0 : onCheck(item); } }; TableRow.prototype.handleAction = function (e, action, ctx) { var _a = this.props, onAction = _a.onAction, item = _a.item; onAction && onAction(e, action, ctx || item.data); }; TableRow.prototype.handleQuickChange = function (values, saveImmediately, savePristine, resetOnFailed) { var _a = this.props, onQuickChange = _a.onQuickChange, item = _a.item; onQuickChange && onQuickChange(item, values, saveImmediately, savePristine, resetOnFailed); }; TableRow.prototype.handleChange = function (value, name, submit, changePristine) { var _a; if (!name || typeof name !== 'string') { return; } var _b = this.props, item = _b.item, onQuickChange = _b.onQuickChange; onQuickChange === null || onQuickChange === void 0 ? void 0 : onQuickChange(item, (_a = {}, _a[name] = value, _a), submit, changePristine); }; TableRow.prototype.render = function () { var _a, _b; var _this = this; var _c, _d; var _e = this.props, itemClassName = _e.itemClassName, itemIndex = _e.itemIndex, item = _e.item, columns = _e.columns, renderCell = _e.renderCell, children = _e.children, footableMode = _e.footableMode, ignoreFootableContent = _e.ignoreFootableContent, footableColSpan = _e.footableColSpan, regionPrefix = _e.regionPrefix, checkOnItemClick = _e.checkOnItemClick, ns = _e.classPrefix, render = _e.render, cx = _e.classnames, parent = _e.parent, itemAction = _e.itemAction, headCurrentRows = _e.headCurrentRows, itemHighlight = _e.itemHighlight, currentHighlight = _e.currentHighlight, rest = (0, tslib_1.__rest)(_e, ["itemClassName", "itemIndex", "item", "columns", "renderCell", "children", "footableMode", "ignoreFootableContent", "footableColSpan", "regionPrefix", "checkOnItemClick", "classPrefix", "render", "classnames", "parent", "itemAction", "headCurrentRows", "itemHighlight", "currentHighlight"]); if (footableMode) { if (!item.expanded) { return null; } return (react_1.default.createElement("tr", { "data-id": item.id, "data-index": item.newIndex, onClick: checkOnItemClick || itemAction ? this.handleItemClick : undefined, className: cx(itemClassName, (_a = { // 'is-hovered': item.isHover, 'is-checked': item.checked, 'is-modified': item.modified, 'is-moved': item.moved }, _a["Table-tr--hasItemAction"] = itemAction, _a["Table-tr--odd"] = itemIndex % 2 === 0, _a["Table-tr--even"] = itemIndex % 2 === 1, _a)) }, react_1.default.createElement("td", { className: cx("Table-foot"), colSpan: footableColSpan }, react_1.default.createElement("table", { className: cx("Table-footTable") }, react_1.default.createElement("tbody", null, ignoreFootableContent ? columns.map(function (column) { return (react_1.default.createElement("tr", { key: column.index }, column.label !== false ? react_1.default.createElement("th", null) : null, react_1.default.createElement("td", null))); }) : columns.map(function (column) { return (react_1.default.createElement("tr", { key: column.index }, column.label !== false ? (react_1.default.createElement("th", null, render("" + regionPrefix + itemIndex + "/" + column.index + "/tpl", column.label))) : null, renderCell("" + regionPrefix + itemIndex + "/" + column.index, column, item, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, rest), { width: null, rowIndex: itemIndex, colIndex: column.index, key: column.index, onAction: _this.handleAction, onQuickChange: _this.handleQuickChange, onChange: _this.handleChange })))); })))))); } if (parent && !parent.expanded) { return null; } // Jay var _f = this.props, store = _f.store, stickyWidths = _f.stickyWidths; var leftFixedColumns = store.leftFixedColumns; var lastLeftFixedIndex = (_c = leftFixedColumns[leftFixedColumns.length - 1]) === null || _c === void 0 ? void 0 : _c.index; var rightFixedColumns = store.rightFixedColumns; var firstRightFixedIndex = (_d = rightFixedColumns[0]) === null || _d === void 0 ? void 0 : _d.index; return (react_1.default.createElement("tr", { ref: this.dom, style: { cursor: "pointer" }, "data-index": item.depth === 1 ? item.newIndex : undefined, "data-id": item.id, className: cx(itemClassName, (_b = { // 'is-hovered': item.isHover, 'is-checked': item.checked, 'is-Highlight': itemHighlight, 'is-current': currentHighlight, 'is-modified': item.modified, 'is-moved': item.moved, 'is-expanded': item.expanded, 'is-expandable': item.expandable }, _b["Table-tr--hasItemAction"] = itemAction, _b["Table-tr--odd"] = itemIndex % 2 === 0, _b["Table-tr--even"] = itemIndex % 2 === 1, _b), "Table-tr--" + item.depth + "th") }, columns.map(function (column, index) { var _a, _b, _c, _d; if (!(0, helper_1.isMobile)() && !column.pristine.linkUrl && !column.pristine.format && (['plain', 'static-text'].includes(column.type) || !column.type)) { if (column.name && item.rowSpans[column.name] === 0) { return null; } var classNameExpr = column.pristine.classNameExpr; var tdClassName = itemClassName + " " + cx(column.pristine.className, _this.props.setBorder ? 'td-border' : '', { 'fixed-left-last': column.index === lastLeftFixedIndex, 'fixed-right-first': column.index === firstRightFixedIndex }, classNameExpr ? (0, tpl_1.filter)(classNameExpr.replaceAll("." + column.pristine.rawName, "['" + column.name + "']"), item.data) : null); var itemValue = column.name ? (0, tpl_builtin_1.resolveVariable)(column.name, _this.props.canAccessSuperData ? item.locals : item.data) : column.value; var tdStyle = { position: column.fixed && "sticky", left: column.fixed === 'left' && (stickyWidths === null || stickyWidths === void 0 ? void 0 : stickyWidths["" + column.index]), right: column.fixed === 'right' && (stickyWidths === null || stickyWidths === void 0 ? void 0 : stickyWidths["" + column.index]), zIndex: column.fixed && 1, textAlign: column.align, }; tdStyle.maxWidth = column.pristine.width || "200px"; tdStyle.width = column.pristine.width || '200px'; var itemKey = item.id + '-' + index; return react_1.default.createElement("td", { rowSpan: item.rowSpans[column.name], key: itemKey, "table-name": _this.props.tableName, "column-name": column.name, className: tdClassName, style: (0, tslib_1.__assign)({}, tdStyle) }, react_1.default.createElement(SimpleSpan_1.default, { env: _this.props.env, primaryField: _this.props.store.primaryField, checked: item.checked, tableId: _this.props.tableId, key: itemKey, prefix: column.pristine.prefix, suffix: column.pristine.suffix, multiple: _this.props.multiple, ns: ns, value: itemValue, column: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, column), { pristine: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, column.pristine), { quickEdit: undefined }) }), render: render, cx: _this.props.classnames, item: item, itemIndex: itemIndex, className: tdClassName })); } else return renderCell(itemIndex + "/" + column.index, column, item, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, rest), { rowIndex: itemIndex, colIndex: column.index, key: column.index, onAction: _this.handleAction, onQuickChange: _this.handleQuickChange, onChange: _this.handleChange, canDelete: column.type == 'lion-upload' ? false : (_b = (_a = column.pristine) === null || _a === void 0 ? void 0 : _a.quickEdit) === null || _b === void 0 ? void 0 : _b.canDelete, canUpload: column.type == 'lion-upload' ? false : (_d = (_c = column.pristine) === null || _c === void 0 ? void 0 : _c.quickEdit) === null || _d === void 0 ? void 0 : _d.canUpload, // Jay className: cx(itemClassName, { 'fixed-left-last': column.index === lastLeftFixedIndex, 'fixed-right-first': column.index === firstRightFixedIndex, 'fixed': column.fixed ? true : false, 'td-border': _this.props.setBorder }), style: { position: column.fixed && "sticky", left: column.fixed === 'left' && (stickyWidths === null || stickyWidths === void 0 ? void 0 : stickyWidths["" + column.index]), right: column.fixed === 'right' && (stickyWidths === null || stickyWidths === void 0 ? void 0 : stickyWidths["" + column.index]), zIndex: column.fixed && 1, } })); }))); }; TableRow = (0, tslib_1.__decorate)([ mobx_react_1.observer, (0, tslib_1.__metadata)("design:paramtypes", [Object]) ], TableRow); return TableRow; }(react_1.default.Component)); exports.TableRow = TableRow; //# sourceMappingURL=./renderers/FieldTableHorizontal/TableRow.js.map