UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

891 lines (890 loc) 63.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LionTestTableRenderer = exports.LionTestTable = exports.LionTestTableContext = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importDefault)(require("react")); var pagination_1 = (0, tslib_1.__importDefault)(require("antd/lib/pagination")); var spin_1 = (0, tslib_1.__importDefault)(require("antd/lib/spin")); var message_1 = (0, tslib_1.__importDefault)(require("antd/lib/message")); var button_1 = (0, tslib_1.__importDefault)(require("antd/lib/button")); var modal_1 = (0, tslib_1.__importDefault)(require("antd/lib/modal")); var index_1 = require("../../../../index"); var factory_1 = require("../../../../factory"); var tpl_1 = require("../../../../utils/tpl"); var Scoped_1 = require("../../../../Scoped"); var pagination_2 = require("./locale/pagination"); var react_dom_1 = require("react-dom"); var liontable_1 = require("../../../../store/liontable"); var tpl_2 = require("../../../../utils/tpl"); var LodopFuncs_1 = require("../../../../utils/print/LodopFuncs"); var print_1 = require("../../../../utils/print"); var util_1 = require("../../../../utils/print/util"); var LabelPrint_1 = require("../../LabelPrint"); var index_2 = require("./assembly/generic/index"); var index_3 = require("./assembly/table/header/index"); var index_4 = require("./assembly/table/leftArea/index"); var index_5 = require("./assembly/table/rightArea/index"); var index_6 = require("./assembly/table/intermediateArea/index"); var index_7 = (0, tslib_1.__importDefault)(require("./assembly/Interrogator/index")); var index_8 = (0, tslib_1.__importDefault)(require("./assembly/spreadSelection/index")); var placeHolder_1 = (0, tslib_1.__importDefault)(require("./assembly/placeHolder")); var omit_1 = (0, tslib_1.__importDefault)(require("lodash/omit")); require("./style/baseCss/popover.css"); require("./style/baseCss/index.css"); require("./components/MainExport/MainExport.css"); require("./scss/toolbar.scss"); require("./scss/table.scss"); require("./scss/tbody.scss"); require("./scss/fixTbody.scss"); exports.LionTestTableContext = react_1.default.createContext({}); var calcGap = function (rest) { if (rest === void 0) { rest = 0; } // window.document.documentElement.clientHeight - 20 - (document.querySelector('.ant-tabs-content')?.querySelector('.antd-Tabs-links') ? 32 : 0), var rootDom = document.querySelector('.ant-tabs-content'); var height = (rootDom === null || rootDom === void 0 ? void 0 : rootDom.clientHeight) - 20; return height - rest; }; var calcInnerWidth = function () { var _a; var clientWidth = (_a = document.querySelector('.ant-tabs-content')) === null || _a === void 0 ? void 0 : _a.clientWidth; // document.documentElement.clientWidth || document.body.clientWidth 直接获取耗时差距太大,暂不使用 return clientWidth > 1680 ? clientWidth : 1680; }; var antiShake = function (callBack, wait, rest) { if (wait === void 0) { wait = 0; } var timer = null; return function () { if (timer) { clearTimeout(timer); timer = null; } timer = setTimeout(function () { callBack(rest); }, wait); }; }; var LionTestTable = /** @class */ (function (_super) { (0, tslib_1.__extends)(LionTestTable, _super); function LionTestTable(props, context) { var _a, _b; var _this = _super.call(this, props) || this; _this.rawTableData = { items: [], total: 0 }; _this._bindRef = function (ref) { _this._uploadRef = ref; }; _this.requestFilterSource = function (paramsField, isFilter, load, asynsUpdateState) { var _a; if (isFilter === void 0) { isFilter = false; } if (asynsUpdateState === void 0) { asynsUpdateState = {}; } var _b = _this.props, env = _b.env, data = _b.data; var updateState = asynsUpdateState; var _data = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, paramsField), data), data === null || data === void 0 ? void 0 : data.__super); _this.setState({ loading: true }); try { env.fetcher((_a = _this.props) === null || _a === void 0 ? void 0 : _a.api, _data).then(function (res) { var _a, _b, _c, _d, _e; if (!_this.state.hasFetch) { updateState.hasFetch = true; } if ((res === null || res === void 0 ? void 0 : res.status) === 0) { _this.rawTableData = res === null || res === void 0 ? void 0 : res.data; if (load === 'ui') { _this.generatePageConfig((res === null || res === void 0 ? void 0 : res.data) ? res === null || res === void 0 ? void 0 : res.data : {}, updateState); } else { _this.extractDataSource((res === null || res === void 0 ? void 0 : res.data) ? res === null || res === void 0 ? void 0 : res.data : {}, updateState); } } else { _this.setState({ loading: false }); throw new Error(res === null || res === void 0 ? void 0 : res.msg); } ((_a = _this.props) === null || _a === void 0 ? void 0 : _a.setTotalNum) && ((_b = _this.props) === null || _b === void 0 ? void 0 : _b.setTotalNum((_c = _this.props.totalTab) === null || _c === void 0 ? void 0 : _c.key, (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.total, (_e = _this.props) === null || _e === void 0 ? void 0 : _e.name)); }).catch(function (e) { env === null || env === void 0 ? void 0 : env.notify("error", e.message); }); } catch (err) { message_1.default.error(err); _this.setState({ loading: false }); } }; // 表头选择框选中 _this.onCheckAllChange = function (e, isClear) { e.preventDefault(); var pageSelectList = _this.state.pageSelectList; var selectList = _this.state.selectList; var checkAll = _this.state.checkAll; var _checkAll = isClear ? false : !checkAll; Object.keys(pageSelectList).forEach(function (item) { selectList[item] = _checkAll; pageSelectList[item] = _checkAll; }); _this.setState({ selectList: selectList, checkAll: _checkAll, pageSelectList: pageSelectList }); }; _this.handleSectionChange = function (e, current, isClear) { e.preventDefault(); if (isClear) { _this.onCheckAllChange(e, isClear); } else { _this.handleMasterChange(e, current); } }; // 主表选择框被选中时 _this.handleMasterChange = function (e, current) { e.preventDefault(); // 点击时阻止默认事件 var pageSelectList = _this.state.pageSelectList; var selectList = _this.state.selectList; var checkAll; // 选中所有数据 selectList[current] = !selectList[current]; pageSelectList[current] = selectList[current]; // 判断是否所有从表数据均被选中,若被选中则给表头选择框添加选中效果 checkAll = Object.values(pageSelectList).every(function (item) { if (item === false) { return false; } return true; }); _this.setState({ selectList: selectList, checkAll: checkAll, pageSelectList: pageSelectList }); }; // 表格滚动条拖动时给固定的列添加或删除阴影效果 _this.handleScroll = function (e) { var currentTarget = e.currentTarget; var scrollLeft = currentTarget.scrollLeft, scrollTop = currentTarget.scrollTop; _this.initScrollShadow(currentTarget); var fixBodyers = currentTarget.parentElement.parentElement.getElementsByClassName('lion-table-container-fixed-body'); var tableHeaders = currentTarget.parentElement.parentElement.getElementsByClassName('lion-table-header'); for (var i = 0; i < fixBodyers.length; i++) { fixBodyers[i].scrollTop = scrollTop; } if (tableHeaders.length > 0) { tableHeaders[0].scrollLeft = scrollLeft; } }; _this.showTotal = function () { var _a = _this.state, page = _a.page, pageSize = _a.pageSize, totalSize = _a.totalSize; var _page = totalSize === 0 ? 0 : page; var total = totalSize; var currentTotal = total === 0 ? 0 : Math.ceil(total / pageSize); return _page + "/" + currentTotal + " \u603B\u5171\uFF1A" + totalSize + " \u9879"; }; // 点击展开或收起操作 _this.handleOpenCol = function (primaryField) { var _a; var colHideList = _this.state.colHideList; _this.setState({ colHideList: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, colHideList), (_a = {}, _a[primaryField] = !colHideList[primaryField], _a)), }); }; _this.handleAddClass = function (arr, tabIndex) { Array.from(arr).forEach(function (_node) { if ((_node === null || _node === void 0 ? void 0 : _node.attributes.tabindex.nodeValue) === tabIndex) { _node.className += ' tr--hover'; } }); }; _this.handleTrMouseOver = function (e) { if (e.currentTarget.className.indexOf('tr--hover') !== -1) { return; } var _body = (0, react_dom_1.findDOMNode)(_this); var bodyTable = _body.querySelector('.lion-table-body'); // 左侧固定表格 var fixLeftTable = _body.querySelector('.lion-table-container-fixed-wrapper--left'); // 右侧固定表格 var fixRightTable = _body.querySelector('.lion-table-container-fixed-wrapper--right'); var bodyTr = bodyTable.getElementsByClassName('tbody-tr--column--white'); var fixLeftTr = fixLeftTable.getElementsByClassName('tbody-tr--column--white'); var fixRightTr = fixRightTable.getElementsByClassName('tbody-tr--column--white'); _this.handleAddClass(bodyTr, e.currentTarget.attributes.tabindex.nodeValue); _this.handleAddClass(fixLeftTr, e.currentTarget.attributes.tabindex.nodeValue); _this.handleAddClass(fixRightTr, e.currentTarget.attributes.tabindex.nodeValue); }; _this.handleTrMouseOut = function (e) { var _body = (0, react_dom_1.findDOMNode)(_this); var bodyTable = _body === null || _body === void 0 ? void 0 : _body.querySelector('.lion-table-body'); // 左侧固定表格 var fixLeftTable = _body === null || _body === void 0 ? void 0 : _body.querySelector('.lion-table-container-fixed-wrapper--left'); // 右侧固定表格 var fixRightTable = _body === null || _body === void 0 ? void 0 : _body.querySelector('.lion-table-container-fixed-wrapper--right'); var bodyTr = bodyTable.getElementsByClassName('tbody-tr--column--white'); var fixLeftTr = fixLeftTable.getElementsByClassName('tbody-tr--column--white'); var fixRightTr = fixRightTable.getElementsByClassName('tbody-tr--column--white'); _this.handleRemoveClass(bodyTr); _this.handleRemoveClass(fixLeftTr); _this.handleRemoveClass(fixRightTr); }; _this.handleRemoveClass = function (arr) { Array.from(arr).forEach(function (_node) { _node.className = _node.className.replace('tr--hover', ''); }); }; _this.handlePageSizeChange = function (page, pageSize) { var _a; if (!_this.props.keepItemSelectionOnPageChange) { _this.setState({ selectList: [] }); } if (_this._uploadRef) { (_a = _this._uploadRef) === null || _a === void 0 ? void 0 : _a.handleBulkChange({ perPage: pageSize, page: page }); } _this.requestFilterSource({ perPage: pageSize, page: page }, false, 'data', { page: page, pageSize: pageSize, checkAll: false // pageSelectList: {} }); }; _this.MonitorPageChanges = function (e) { var _a; var _b = _this.props, isDialogMode = _b.isDialogMode, checkbox = _b.checkbox, list_columns = _b.list_columns, columns = _b.columns; var wrapper = calcInnerWidth(); if (isDialogMode) { var thisParent = (_a = (0, react_dom_1.findDOMNode)(_this)) === null || _a === void 0 ? void 0 : _a.parentElement; wrapper = ((thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth) > 500 ? thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth : 500); } var _wrapper = Math.ceil(wrapper); var _c = _this.calcHeight(), _container_height = _c._container_height, table_height = _c.table_height; if (_wrapper > 1680) { _this.uiWorker.postMessage({ message: "screenTurn", data: { checkbox: checkbox, list_columns: list_columns, columns: columns, wrapper: _wrapper, primaryTdSize: _this.surfaceWidth, _container_height: _container_height, table_height: table_height }, willUpdateState: null }); } }; _this.MonitorTableChanges = function (e) { var _a = _this.calcHeight(), _container_height = _a._container_height, table_height = _a.table_height; _this.setState({ _container_height: _container_height, table_height: table_height }); }; _this.handleAction = function (e, action, ctx, callBack, throwErrors, delegate) { if (throwErrors === void 0) { throwErrors = false; } return (0, tslib_1.__awaiter)(_this, void 0, Promise, function () { var _a, env, store, messages, onAction, res, exportData, primaryField, __, LODOP; var _this = this; var _b, _c, _d; return (0, tslib_1.__generator)(this, function (_e) { switch (_e.label) { case 0: _a = this.props, env = _a.env, store = _a.store, messages = _a.messages, onAction = _a.onAction; if (!(action.actionType === 'ajax')) return [3 /*break*/, 2]; store.setCurrentAction(action); return [4 /*yield*/, store .lionSaveRemote(action.api, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, store.data), ctx), { successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess), errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveSuccess) }).then(function (response) { var redirect = action.redirect && (0, tpl_1.filter)(action.redirect, store.data); redirect && env.jumpTo(redirect, action); action.reload && _this.reloadTarget(action.reload, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, store.data), ctx)); return false; }).catch(function (error) { console.info(error); })]; case 1: res = _e.sent(); return [2 /*return*/, res]; case 2: if (action.actionType === 'export') { store.setCurrentAction(action); exportData = (action === null || action === void 0 ? void 0 : action.exportType) === 2 ? ctx : {}; exportData = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, exportData), (_d = (_c = (_b = this === null || this === void 0 ? void 0 : this._uploadRef) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.store) === null || _d === void 0 ? void 0 : _d.data); exportData.primaryField = this.props.primaryField; exportData.selectedItems = this.checkList; exportData.ids = ((action === null || action === void 0 ? void 0 : action.exportType) && (action === null || action === void 0 ? void 0 : action.exportType) === 2 ? ctx[this.props.primaryField] : this.ids); store.openLionExport(exportData, env); return [2 /*return*/, false]; } else if (action.actionType === 'loginAmazon') { store.setCurrentAction(action); store.openAmazonLoginPage(ctx, env); return [2 /*return*/, false]; } else if (action.actionType === 'label-design') { (0, print_1.templateDesign)(ctx, function (value) { modal_1.default.confirm({ title: '确认提交该模板吗?', okText: '确认', cancelText: '取消', getContainer: env.getModalContainer, onOk: function () { if (action.api) { var labelTemplate = (0, util_1.buildLabelTemplate)(value); var tableFields = labelTemplate.labelTables.map(function (table) { var _a; return (_a = table.fieldName) !== null && _a !== void 0 ? _a : ''; }).join(','); env.fetcher(action.api, { tableFields: tableFields, tempId: ctx.TEMP_ID, content: value }).then(function (res) { var _a, _b; if (res.status === 0) { message_1.default.success(res.msg); var _c = _this.state, page = _c.page, pageSize = _c.pageSize; var filterParams = _this._uploadRef ? (_b = (_a = _this._uploadRef) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.data : { perPage: pageSize, page: page }; _this.requestFilterSource(filterParams, false, 'data'); } else { message_1.default.error(res.msg); } }); } } }); }); } else if (action.actionType === 'label-print' || action.actionType === 'bill-print' || action.actionType === 'report-print') { // Jay store.setCurrentAction(action); primaryField = this.props.primaryField; __ = this.props.translate; LODOP = (0, LodopFuncs_1.getLodop)(); if (LODOP) { this.setState({ ModalProps: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, action), { title: __('CRUD.printOptions'), show: true, isFilePrint: false, isRow: true, ctx: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, ctx), { primaryField: primaryField }), data: this.rawTableData, onHide: function () { _this.setState({ printType: undefined }); } }), printType: action.actionType.slice(0, action.actionType.indexOf('-')) }); } } else { onAction === null || onAction === void 0 ? void 0 : onAction(e, action, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, store.data), ctx), throwErrors, delegate || this.context); return [2 /*return*/, false]; } _e.label = 3; case 3: return [2 /*return*/]; } }); }); }; _this.state = { fixLeft: 0, tableBody: react_1.default.createRef(), fixColumns: [], selectList: {}, pageSelectList: {}, SonList: {}, checkAll: false, loading: true, pageData: [], totalSize: 0, pageSize: props.perPage || 10, page: 1, storageSource: {}, colHideList: {}, wrapper: calcInnerWidth(), _container_height: calcGap(), table_height: calcGap(40 + 46 + ((props === null || props === void 0 ? void 0 : props.filter) ? 50 : 0) + ((((_a = props === null || props === void 0 ? void 0 : props.headerToolbar) === null || _a === void 0 ? void 0 : _a.length) > 0 || ((_b = props === null || props === void 0 ? void 0 : props.bulkActions) === null || _b === void 0 ? void 0 : _b.length) > 0) ? 40 : 10)), hasFetch: false, ModalProps: { title: '打印选项', show: false, onHide: null }, printType: undefined, surfaceItemWidth: 0, colSpan: 0, primaryElevae: 0, subordinateElevae: 0, toolSwitch: false, }; _this.handleAction = _this.handleAction.bind(_this); var scoped = context; scoped.registerComponent(_this); return _this; } Object.defineProperty(LionTestTable.prototype, "baseUrl", { get: function () { var _a, _b; var env = this.props.env; return ((_b = (_a = env === null || env === void 0 ? void 0 : env.axiosInstance) === null || _a === void 0 ? void 0 : _a.defaults) === null || _b === void 0 ? void 0 : _b.baseURL) || (env === null || env === void 0 ? void 0 : env.ajaxApi); }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "uiWorker", { get: function () { var _this = this; var url = !this.baseUrl ? (location.href.includes('localhost') ? '/public/worker/index.js' : '/worker/index.js') : './public/worker/index.js'; var worker = new Worker(url); worker.onmessage = function (e) { _this.receiveMessage(e.data.data); }; return worker; }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "dataWorker", { get: function () { var _this = this; var url = !this.baseUrl ? (location.href.includes('localhost') ? '/public/worker/dataWorker.js' : '/worker/dataWorker.js') : './public/worker/dataWorker.js'; var worker = new Worker(url); worker.onmessage = function (e) { _this.receiveMessage(e.data.data); }; return worker; }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "dataSource", { get: function () { return this.state.pageData; }, enumerable: false, configurable: true }); LionTestTable.prototype.receiveMessage = function (content) { // let union = {}; // if (this.props.keepItemSelectionOnPageChange) { // const { SonList, pageData, storageSource, colHideList, pageSelectList } = this.state; // union = { // SonList: { ...SonList, ...content.SonList }, // pageData: [...pageData, ...content.pageata], // storageSource: { ...storageSource, ...content.storageSource }, // colHideList: { ...colHideList, ...content.colHideList }, // pageSelectList: { ...pageSelectList, ...content.pageSelectList } // } // } this.setState((0, tslib_1.__assign)({}, content)); }; Object.defineProperty(LionTestTable.prototype, "checkList", { // 主表选中行 get: function () { var _a = this.state, selectList = _a.selectList, storageSource = _a.storageSource; var _checkList = Object.entries(selectList).filter(function (item) { return item[1] === true; }).map(function (item) { return item[0]; }); var newList = []; _checkList.forEach(function (item) { if (storageSource[item]) newList.push(storageSource[item]); }); return newList; }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "record_ids", { get: function () { var primaryField = this.props.primaryField; var pageData = this.state.pageData; var _ids = ''; pageData.forEach(function (record) { _ids += record.hasOwnProperty(primaryField) ? record[primaryField] + ',' : ''; }); return _ids.slice(0, _ids.length - 1); }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "ids", { get: function () { var _ids = ''; var primaryField = this.props.primaryField; this.checkList.map(function (_select) { _ids += _select.hasOwnProperty(primaryField) ? _select[primaryField] + ',' : ''; }); return _ids.slice(0, _ids.length - 1); }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "leftTableWidth", { // 计算左侧固定表格的宽度 get: function () { var fixColumns = this.state.fixColumns; var count = 0; fixColumns.forEach(function (item, index) { if ((item === null || item === void 0 ? void 0 : item.fixed) === 'left') { count += item === null || item === void 0 ? void 0 : item.width; } }); return count; }, enumerable: false, configurable: true }); Object.defineProperty(LionTestTable.prototype, "rightTableWidth", { // 计算右侧固定表格的宽度 get: function () { var fixColumns = this.state.fixColumns; var count = 0; fixColumns.forEach(function (item, index) { if ((item === null || item === void 0 ? void 0 : item.fixed) === 'right') { count += item === null || item === void 0 ? void 0 : item.width; } }); return count; }, enumerable: false, configurable: true }); LionTestTable.prototype.calcSubordinateSize = function (columns) { var count = columns.reduce(function (prev, current, index) { var _a; return prev + ((_a = current === null || current === void 0 ? void 0 : current.width) !== null && _a !== void 0 ? _a : 0); }, 0); return count; }; Object.defineProperty(LionTestTable.prototype, "surfaceWidth", { get: function () { var list_columns = this.props.list_columns; var count = list_columns.reduce(function (prev, current, index) { var _a; return prev + ((_a = current === null || current === void 0 ? void 0 : current.width) !== null && _a !== void 0 ? _a : 0); }, 0); return count; }, enumerable: false, configurable: true }); LionTestTable.prototype.initSource = function (paramsField) { var _this = this; var _a; var _b = this.props, env = _b.env, data = _b.data, _c = _b.initFetch, initFetch = _c === void 0 ? true : _c; var _data = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, paramsField), data), data === null || data === void 0 ? void 0 : data.__super); var updateState = {}; if (!initFetch) { this.generateUI((0, tslib_1.__assign)({ loading: false }, updateState)); return; } try { env.fetcher((_a = this.props) === null || _a === void 0 ? void 0 : _a.api, _data).then(function (res) { var _a, _b, _c, _d, _e; if (!_this.state.hasFetch) { updateState.hasFetch = true; } if ((res === null || res === void 0 ? void 0 : res.status) === 0) { _this.rawTableData = res === null || res === void 0 ? void 0 : res.data; _this.generatePageConfig((res === null || res === void 0 ? void 0 : res.data) ? res === null || res === void 0 ? void 0 : res.data : {}, updateState); } else { _this.setState({ loading: false }); throw new Error(res === null || res === void 0 ? void 0 : res.msg); } ((_a = _this.props) === null || _a === void 0 ? void 0 : _a.setTotalNum) && ((_b = _this.props) === null || _b === void 0 ? void 0 : _b.setTotalNum((_c = _this.props.totalTab) === null || _c === void 0 ? void 0 : _c.key, (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.total, (_e = _this.props) === null || _e === void 0 ? void 0 : _e.name)); }).catch(function (e) { env === null || env === void 0 ? void 0 : env.notify("error", e.message); }); } catch (err) { message_1.default.error(err); this.setState({ loading: false }); } }; LionTestTable.prototype.initScrollShadow = function (target) { // 滚动主体 var scrollBody = target ? target : (0, react_dom_1.findDOMNode)(this); var fixColumns = this.state.fixColumns; var scrollClientWidth = this.state.wrapper > this.calcSubordinateSize(fixColumns) ? this.state.wrapper : this.calcSubordinateSize(fixColumns); // 左侧固定表格 var fixLeftTable = target ? target.parentElement.parentElement.querySelector('.lion-table-container-fixed-wrapper--left') : scrollBody.querySelector('.lion-table-container-fixed-wrapper--left'); // 右侧固定表格 var fixRightTable = target ? target.parentElement.parentElement.querySelector('.lion-table-container-fixed-wrapper--right') : scrollBody.querySelector('.lion-table-container-fixed-wrapper--right'); // 滚动主体的向左滚动距离大于0且左侧固定表格不存在阴影class时,添加阴影效果 if (scrollBody.scrollLeft > 0 && (fixLeftTable === null || fixLeftTable === void 0 ? void 0 : fixLeftTable.className.indexOf('lion-talbe--fix--left--shadow')) === -1) { fixLeftTable.className = fixLeftTable.className + ' lion-talbe--fix--left--shadow'; } // 滚动主体的向左滚动距离小于等于0,移除左侧表格的阴影class if ((scrollBody === null || scrollBody === void 0 ? void 0 : scrollBody.scrollLeft) <= 0) { fixLeftTable.className = fixLeftTable === null || fixLeftTable === void 0 ? void 0 : fixLeftTable.className.replace(' lion-talbe--fix--left--shadow', ''); } if (target) { // 滚动主体的clientWidth + scrollLeft 大于等于 滚动主体的滚动条长度,说明到最右边 if (Math.floor(scrollBody.clientWidth + scrollBody.scrollLeft) >= scrollBody.scrollWidth) { fixRightTable.className = fixRightTable.className.replace(' lion-talbe--fix--right--shadow', ''); } // 滚动主体的clientWidth + scrollLeft 小于 滚动主体的滚动条长度 if ((Math.floor(scrollBody.clientWidth + scrollBody.scrollLeft) < scrollBody.scrollWidth && fixRightTable.className.indexOf('lion-talbe--fix--right--shadow') === -1)) { fixRightTable.className = fixRightTable.className + ' lion-talbe--fix--right--shadow'; } return; } // 滚动主体的clientWidth + scrollLeft 大于等于 滚动主体的滚动条长度,说明到最右边 if (scrollBody.scrollWidth >= scrollClientWidth) { fixRightTable.className = fixRightTable.className.replace(' lion-talbe--fix--right--shadow', ''); } // 滚动主体的clientWidth + scrollLeft 小于 滚动主体的滚动条长度 if (scrollBody.scrollWidth < scrollClientWidth && fixRightTable.className.indexOf('lion-talbe--fix--right--shadow') === -1) { fixRightTable.className = fixRightTable.className + ' lion-talbe--fix--right--shadow'; } }; LionTestTable.prototype.extractDataSource = function (data, willUpdateState) { if (willUpdateState === void 0) { willUpdateState = null; } var _a = this.props, source = _a.source, primaryField = _a.primaryField, keepItemSelectionOnPageChange = _a.keepItemSelectionOnPageChange, detailTableField = _a.detailTableField; this.dataWorker.postMessage({ message: "generateData", data: { data: data, source: source, primaryField: primaryField, keepItemSelectionOnPageChange: keepItemSelectionOnPageChange, detailTableField: detailTableField, selectList: this.state.selectList }, willUpdateState: willUpdateState }); }; LionTestTable.prototype.generateUI = function (willUpdateState) { var _a; if (willUpdateState === void 0) { willUpdateState = null; } var _b = this.props, checkbox = _b.checkbox, list_columns = _b.list_columns, isDialogMode = _b.isDialogMode, columns = _b.columns; var adaptiveWidth = this.state.wrapper; if (isDialogMode) { var thisParent = (_a = (0, react_dom_1.findDOMNode)(this)) === null || _a === void 0 ? void 0 : _a.parentElement; adaptiveWidth = ((thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth) > 500 ? thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth : 500); } var _c = this.calcHeight(), _container_height = _c._container_height, table_height = _c.table_height; this.uiWorker.postMessage({ message: "createUI", data: { checkbox: checkbox, list_columns: list_columns, columns: columns, wrapper: adaptiveWidth, primaryTdSize: this.surfaceWidth, table_height: table_height, _container_height: _container_height }, willUpdateState: willUpdateState }); }; LionTestTable.prototype.generatePageConfig = function (data, willUpdateState) { var _a; if (willUpdateState === void 0) { willUpdateState = null; } var _b = this.props, checkbox = _b.checkbox, source = _b.source, list_columns = _b.list_columns, isDialogMode = _b.isDialogMode, columns = _b.columns, primaryField = _b.primaryField, keepItemSelectionOnPageChange = _b.keepItemSelectionOnPageChange, detailTableField = _b.detailTableField; // 自适应宽度。屏幕宽度小于1680时按1680算,其他情况按屏幕宽度算 var adaptiveWidth = this.state.wrapper; if (isDialogMode) { var thisParent = (_a = (0, react_dom_1.findDOMNode)(this)) === null || _a === void 0 ? void 0 : _a.parentElement; adaptiveWidth = ((thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth) > 500 ? thisParent === null || thisParent === void 0 ? void 0 : thisParent.clientWidth : 500); } var _c = this.calcHeight(), _container_height = _c._container_height, table_height = _c.table_height; this.uiWorker.postMessage({ message: "generateUI", data: { checkbox: checkbox, list_columns: list_columns, columns: columns, wrapper: adaptiveWidth, primaryTdSize: this.surfaceWidth, data: data, source: source, primaryField: primaryField, keepItemSelectionOnPageChange: keepItemSelectionOnPageChange, detailTableField: detailTableField, selectList: this.state.selectList, _container_height: _container_height, table_height: table_height }, willUpdateState: willUpdateState }); }; LionTestTable.prototype.calcHeight = function () { var _a, _b, _c; var isTab = this.props.totalTab; var _dis = 10; if (this.props.filter) _dis += 52; if ((((_a = this.props.headerToolbar) === null || _a === void 0 ? void 0 : _a.length) > 0 || ((_c = (_b = this.props) === null || _b === void 0 ? void 0 : _b.bulkActions) === null || _c === void 0 ? void 0 : _c.length) > 0)) _dis += 30; if (isTab) _dis += 32; // if (this.props.keepItemSelectionOnPageChange) _dis += 35 var _page_height = calcGap(); var table_height = _page_height - 46 - 40 - _dis; if (this.props.isDialogMode) { table_height -= 110; } return { _container_height: _page_height, table_height: table_height }; }; LionTestTable.prototype.handleFilterParams = function (value) { var _a, _b, _c; var _d = this.state, page = _d.page, pageSize = _d.pageSize; (_a = this._uploadRef) === null || _a === void 0 ? void 0 : _a.handleBulkChange({ perPage: pageSize, page: page }); var filterParams = this._uploadRef ? (_c = (_b = this._uploadRef) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.data : { perPage: pageSize, page: page }; this.requestFilterSource((0, tslib_1.__assign)((0, tslib_1.__assign)({}, value), filterParams), true, 'data'); }; LionTestTable.prototype.reloadTarget = function (reload, ctx, callBack) { var scoped = this.context; // callBack && callBack(); scoped.reload(reload, ctx); // 用于刷新目标组件 }; LionTestTable.prototype.closeTarget = function (target) { var scoped = this.context; scoped.close(target); }; LionTestTable.prototype.reload = function (subPath, query, ctx) { this.handleFilterParams(ctx); }; LionTestTable.prototype.receive = function (value, subPath) { this.handleFilterParams(value); }; LionTestTable.prototype.doAction = function (query, ctx) { this.handleFilterParams(ctx); }; /** * Jay * 标签、文件打印 */ LionTestTable.prototype.renderPrint = function (ctx, schema, isFilePrint) { var _this = this; var _a = this.props, __ = _a.translate, nx = _a.classnames; // const { selectedItems } = ctx var disabled = schema.disabled || (0, tpl_2.evalExpression)(schema.disabledOn, ctx); return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(button_1.default, { type: "primary", className: nx(schema._className, { 'is-disabled': disabled }), disabled: disabled, onClick: function () { var _a, _b, _c; var LODOP = (0, LodopFuncs_1.getLodop)(); if (LODOP) { _this.setState({ ModalProps: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, schema), { title: __('CRUD.printOptions'), show: true, ctx: ctx, onHide: function () { _this.setState({ printType: undefined }); }, query: (_c = (_b = (_a = _this._uploadRef) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.store) === null || _c === void 0 ? void 0 : _c.data }), printType: isFilePrint ? 'file' : schema.actionType === 'label-print' ? 'label' : 'bill' }); } } }, __(schema.label ? schema.label : !isFilePrint ? 'CRUD.labelPrint' : 'CRUD.filePrint')))); }; // 渲染头部按钮及批量按钮 LionTestTable.prototype.renderToolBars = function (toolBars, type) { var _this = this; var _a, _b; if (!(toolBars === null || toolBars === void 0 ? void 0 : toolBars.length)) return []; var _className = type === 'header' ? 'blukAction' : (((_a = this.checkList) === null || _a === void 0 ? void 0 : _a.length) > 0 ? "blukAction" : "blukAction is-disabled"); var _disabled = type === 'header' ? false : (((_b = this.checkList) === null || _b === void 0 ? void 0 : _b.length) > 0 ? false : true); var toolBarList = []; (toolBars === null || toolBars === void 0 ? void 0 : toolBars.length) > 0 && (toolBars === null || toolBars === void 0 ? void 0 : toolBars.forEach(function (_toolBar, _toolIndex) { var align = _toolBar.align; var _data = {}; _data.selectedItems = _this.checkList; _data.ids = _this.ids; _data.items = _this.dataSource; _data.record_ids = _this.record_ids; if (_toolBar.type === 'label-print') { toolBarList.push([_this.renderPrint(_data, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, _toolBar), { _className: _className })), align]); } else if (_toolBar.type === 'file-print') { toolBarList.push([_this.renderPrint(_data, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, _toolBar), { _className: _className }), true), align]); } else if (_toolBar.type === 'reload') { var _a = _this.props, render = _a.render, __ = _a.translate; var reloadButton = { label: _toolBar.label || '', icon: _toolBar.icon || 'fa fa-sync', tooltip: __('reload'), tooltipPlacement: 'top', type: 'button' }; if (typeof toolbar === 'object') { reloadButton = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, reloadButton), (0, omit_1.default)(toolbar, ['type', 'align'])); } toolBarList.push([render("toolbar/" + 1, reloadButton, { onAction: function () { var _a, _b; var _c = _this.state, page = _c.page, pageSize = _c.pageSize; var filterParams = _this._uploadRef ? (_b = (_a = _this._uploadRef) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.data : { perPage: pageSize, page: page }; _this.requestFilterSource(filterParams, false, 'data'); } }), align]); } else { toolBarList.push([(0, index_1.render)(_toolBar, { className: _className, key: _toolIndex, disabled: _disabled, data: _data, onAction: _this.handleAction }), align]); } })); return toolBarList; }; // 表格头部工具栏渲染 LionTestTable.prototype.renderHeaderToolbars = function () { var _this = this; var _a = this.props, headerToolbar = _a.headerToolbar, bulkActions = _a.bulkActions; var headers = this.renderToolBars(headerToolbar, 'header'); var bulks = this.renderToolBars(bulkActions, 'bulk'); var toolBars = headers.concat(bulks); var left = []; var right = []; toolBars.forEach(function (toolBar) { var element = toolBar[0], align = toolBar[1]; if (align !== 'right') { left.push(element); } else { right.push(element); } }); return react_1.default.createElement("div", { className: "lion-table-header-toolbar" }, react_1.default.createElement("div", { className: "lion-nav-operate-group" }, react_1.default.createElement("div", { className: 'lion-nav-operate-group-left' }, left), react_1.default.createElement("div", { className: 'lion-nav-operate-group-right' }, right.length > 0 && react_1.default.createElement("div", { className: 'lion-nav-operate-group-right-content', style: { width: this.state.toolSwitch ? 18 : "calc(" + right.length + " * 55px + 18px)" } }, react_1.default.createElement("div", { className: 'lion-nav-operate-group-right-content-body', style: { width: "calc(" + right.length + " * 55px)" } }, right), react_1.default.createElement("div", { className: 'lion-nav-operate-group-right-content-icon', onClick: function () { _this.setState({ toolSwitch: !_this.state.toolSwitch }); } }, react_1.default.createElement(index_1.Icon, { icon: '#icon-tooltool_pickup', className: "icon", symbol: true })))))); }; // 加载表格数据区域 LionTestTable.prototype.renderTable = function () { var _this = this; var _a = this.state, primaryElevae = _a.primaryElevae, subordinateElevae = _a.subordinateElevae, pageData = _a.pageData, fixColumns = _a.fixColumns, surfaceItemWidth = _a.surfaceItemWidth, SonList = _a.SonList, colHideList = _a.colHideList, colSpan = _a.colSpan; var _b = this.props, list_columns = _b.list_columns, primaryField = _b.primaryField, columns = _b.columns; //没有操作列的时候多合并一列 var calcColSpan = columns.find(function (item) { return (item === null || item === void 0 ? void 0 : item.type) === 'operation'; }) ? colSpan : colSpan + 1; return pageData.map(function (source) { /** * @description: 主体表格渲染逻辑 * @param {any} source 主表项 * @param {number} 主表项索引 * @return {JSXElement} */ var primaryKey = source[primaryField]; var subordinateQuantity = SonList[source.id].length; var colHide = colHideList[primaryKey]; var subSource = SonList[source.id]; return react_1.default.createElement(index_6.IntermediateArea, { primaryElevae: primaryElevae, colSpan: calcColSpan, fixColumns: fixColumns, subordinateElevae: subordinateElevae, list_columns: list_columns, colHide: colHide, subordinateQuantity: subordinateQuantity, subSource: subSource, source: source, surfaceItemWidth: surfaceItemWidth, trClick: _this.handleOpenCol }); }); }; // 加载左固定列 LionTestTable.prototype.renderFixLeftTable = function () { var _this = this; var _a = this.state, pageData = _a.pageData, selectList = _a.selectList, SonList = _a.SonList, colHideList = _a.colHideList, colSpan = _a.colSpan, subordinateElevae = _a.subordinateElevae, primaryElevae = _a.primaryElevae; var _b = this.props, primaryField = _b.primaryField, subSchemaApi = _b.subSchemaApi;