UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

825 lines (824 loc) 102 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var react_1 = tslib_1.__importDefault(require("react")); var mobx_react_1 = require("mobx-react"); var tableCtxMenuStore_1 = tslib_1.__importDefault(require("../Table/tableCtxMenuStore")); var react_dom_1 = require("react-dom"); var helper_1 = require("../../utils/helper"); var Filter_1 = require("./components/Filter"); var Scoped_1 = require("../../Scoped"); var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); var pick_1 = tslib_1.__importDefault(require("lodash/pick")); var debounce_1 = tslib_1.__importDefault(require("lodash/debounce")); var ExpressPrint_1 = require("../Lion/ExpressPrint/ExpressPrint"); var antd_1 = require("antd"); var Selection_1 = require("./components/Selection"); var CrudBody_1 = require("./components/CrudBody"); var FilterModal_1 = tslib_1.__importDefault(require("./components/Modals/FilterModal")); var SecondFilterDrawer_1 = tslib_1.__importDefault(require("./components/Modals/SecondFilterDrawer")); var components_1 = require("../../components"); var LabelPrint_1 = require("../Lion/LabelPrint"); var Workflow_1 = tslib_1.__importDefault(require("../../components/Mobileprocess/Workflow")); var Offline_1 = tslib_1.__importDefault(require("./components/Offline")); var icons_1 = require("../../components/icons"); var ExportModal_1 = tslib_1.__importDefault(require("./components/Modals/ExportModal")); var types_1 = require("./types"); var defaultProperty_1 = require("./defaultProperty"); var tpl_1 = require("../../utils/tpl"); var api_1 = require("../../utils/api"); var print_1 = require("../../utils/print"); var util_1 = require("../../utils/print/util"); var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual")); var sub_1 = require("../../utils/sub"); var locale_1 = require("../../locale"); var tpl_builtin_1 = require("../../utils/tpl-builtin"); var utils_1 = require("./utils"); var LodopFuncs_1 = require("../../utils/print/LodopFuncs"); var CommonModal_1 = require("./components/Modals/CommonModal"); var __1 = require("../.."); var crud_1 = require("../../store/crud"); var CRUD = /** @class */ (function (_super) { tslib_1.__extends(CRUD, _super); function CRUD(props) { var _this = this; var _a; _this = _super.call(this, props) || this; _this.tableStore = null; _this.crudRef = react_1.default.createRef(); _this.advancedFilterData = new Map(); _this.currentSelectedRow = 0; //离线的原始数据,用于重置按钮 _this.originOfflineData = []; _this.fingerprintModalData = undefined; _this.originFilterData = {}; // 静态的过滤数据备份 _this.hasToolBars = false; //是否有工具栏判断 // 多选按钮是否展示条件 _this.hasBulkActions = function () { var _a = _this.props, headerBulkActions = _a.headerBulkActions, footerBulkActions = _a.footerBulkActions, itemActions = _a.itemActions, store = _a.store; return (0, utils_1.hasBulkActions)({ headerBulkActions: headerBulkActions, footerBulkActions: footerBulkActions, itemActions: itemActions }, store, _this.tableStore); }; _this.getRootClassName = function (isLoading, tableRotate, className) { var cx = _this.props.classnames; return cx('Crud', className, { 'is-loading': isLoading, tableRotate: tableRotate }); }; _this.shouldRenderHeader = function () { var _a = _this.props, header = _a.header, filter = _a.filter; var filtercont = _this.state.filtercont; return (!(0, helper_1.isMobile)() || (0, utils_1.headerCanShow)(header, filter, filtercont, _this.tableStore)); }; // ui控制相关 _this.setLoading = function (loading) { var _a, _b; (_b = (_a = _this.props.store) === null || _a === void 0 ? void 0 : _a.markFetching) === null || _b === void 0 ? void 0 : _b.call(_a, loading); }; _this.controlRef = function (control) { // 因为 control 有可能被 n 层 hoc 包裹。 while (control && control.getWrappedInstance) { control = control.getWrappedInstance(); } _this.control = control; }; _this.setTotal = function (total) { _this.props.store.changeTotal(total); }; _this.showTableEditWarmModal = function () { var _a = _this.props, env = _a.env, __ = _a.translate; antd_1.Modal.warning({ title: (react_1.default.createElement("div", null, "\u63D0\u793A", react_1.default.createElement("div", { style: { position: 'absolute', right: '10px', top: '10px', fontSize: '12px', cursor: 'pointer' }, onClick: function () { antd_1.Modal.destroyAll(); } }, react_1.default.createElement(icons_1.Icon, { icon: "close", className: "icon" })))), content: '当前表格存在已修改的数据,请先提交或放弃,再进行其他操作!', getContainer: env.getModalContainer, zIndex: 1020, okText: __('confirm') }); }; //点击离线按钮,切换离线状态 _this.handleClickOffline = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { var _this = this; return tslib_1.__generator(this, function (_a) { antd_1.Modal.confirm({ content: '是否确认进入离线模式?', okText: '确定', cancelText: '取消', onOk: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { this.setState({ offlineMode: true }); return [2 /*return*/]; }); }); } }); return [2 /*return*/]; }); }); }; // 点击高级查询按钮 _this.handleFilterAdvanced = function () { var _a, _b, _c; if (!(0, helper_1.isMobile)() && !((_c = (_b = (_a = _this.props) === null || _a === void 0 ? void 0 : _a.advancedFilter) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.some(function (item) { return item === null || item === void 0 ? void 0 : item.body; }))) { antd_1.message.error('暂无查询条件'); return; } _this.setState({ advancedFilterVisible: true }); }; _this.openFeedback = function (dialog, ctx) { return new Promise(function (resolve) { var store = _this.props.store; store.setCurrentAction({ type: 'button', actionType: 'dialog', dialog: dialog }); store.openDialog(ctx, undefined, function (confirmed) { resolve(confirmed); }); }); }; _this.search = function (values, silent, clearSelection, forceReload, resolve, reject, isChild, postData, // Jay init) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; if (forceReload === void 0) { forceReload = false; } var _l = _this.props, store = _l.store, api = _l.api, messages = _l.messages, pageField = _l.pageField, perPageField = _l.perPageField, interval = _l.interval, syncLocation = _l.syncLocation, syncResponse2Query = _l.syncResponse2Query, keepItemSelectionOnPageChange = _l.keepItemSelectionOnPageChange, pickerMode = _l.pickerMode, env = _l.env, loadDataOnce = _l.loadDataOnce, loadDataOnceFetchOnFilter = _l.loadDataOnceFetchOnFilter, source = _l.source; // Jay //这里原先的备注是: // Jay Jay, 9个月前 (4 26th, 2022 4:49 下午) // 优化CRUD-filter的submit按钮target重复查询、查询条件问题 //但是实测没有起到优化的效果,并且会导致左右页面的一个bug,回车提交查询主表数据为空时,从表数据没有更新 // if (store.searching) return // reload 需要清空用户选择。 if (keepItemSelectionOnPageChange && clearSelection && !pickerMode) { store.setSelectedItems([]); store.setUnSelectedItems([]); } var loadDataMode = ''; if (values && typeof values.loadDataMode === 'string') { loadDataMode = 'load-more'; delete values.loadDataMode; } clearTimeout(_this.searchTimer); values && store.updateQuery(values, !loadDataMode && syncLocation && env && env.updateLocation ? env.updateLocation : undefined, pageField, perPageField); _this.lastQuery = store.query; var data = postData !== null && postData !== void 0 ? postData : (0, helper_1.createObject)(store.data, store.query); // Jay if (!postData && Object.keys(_this.state.filtercont || {}).length) { data.advancedFilter = (_a = _this.state.filtercont) === null || _a === void 0 ? void 0 : _a.advancedFilter; data.advancedHeader = (_b = _this.state.filtercont) === null || _b === void 0 ? void 0 : _b.advancedHeader; data.advancedFilterSub = (_c = _this.state.filtercont) === null || _c === void 0 ? void 0 : _c.advancedFilterSub; data.optionsParam = (_d = _this.state.filtercont) === null || _d === void 0 ? void 0 : _d.optionsParam; if ((_f = (_e = _this.state.filtercont) === null || _e === void 0 ? void 0 : _e.limitParam) === null || _f === void 0 ? void 0 : _f.limitStatus) { data.topN = _this.state.filtercont.limitParam.topN; } if ((0, helper_1.isMobile)()) { if (init) { data.filterParam = (0, utils_1.getInitParam)(_this.props.translate, (_g = _this.state.filtercont) === null || _g === void 0 ? void 0 : _g.filterParam); if (Object.keys(data.filterParam)) { data.filterParam = (_h = _this.state.filtercont) === null || _h === void 0 ? void 0 : _h.filterParam; } } else { data.filterParam = (_j = _this.state.filtercont) === null || _j === void 0 ? void 0 : _j.filterParam; } } // if (this.state.filtercont?.filterOptionData) { // const { optionsParam } = this.state.filtercont?.filterOptionData; // data.optionsParam = optionsParam // } } else if (postData !== undefined && postData.filterOptionData) { var optionsParam = postData.filterOptionData.optionsParam; data.optionsParam = optionsParam; } if (data.advancedFilterSub) { data.advancedFilterSub = (0, utils_1.dealAdvacedCondition)(data.advancedFilterSub); } if (data.advancedFilter) { data.advancedFilter = (0, utils_1.dealAdvacedCondition)(data.advancedFilter); } try { if (_this.props.isStatic) { store.initStaticData(undefined, values); } else { // ai-tool 的查询条件 _this.props.aiQuery && (data = (0, helper_1.createObject)(data, _this.props.aiQuery)); // 清空子表格的列表宽度 (_k = _this.tableStore) === null || _k === void 0 ? void 0 : _k.setTextWidth({}); (0, api_1.isEffectiveApi)(api, data) ? store .fetchInitData(api, data, { successMessage: messages && messages.fetchSuccess, errorMessage: messages && messages.fetchFailed, autoAppend: true, forceReload: forceReload, loadDataOnce: loadDataOnce, loadDataOnceFetchOnFilter: loadDataOnceFetchOnFilter, source: source, silent: silent, openCache: _this.props.openCache, pageField: pageField, perPageField: perPageField, loadDataMode: loadDataMode, syncResponse2Query: syncResponse2Query }) .then(function (value) { var _a, _b, _c, _d; // Jay // WithStore.tsx: else if (props.data && (props.data as any).__super) 中的 store.hasRemoteData // 若不设置,store.initData不会合并之前的store.data.items(items:请求回来的data.items) _this.setState({ filterData: data }); // this.tableStore?.clearOrderColumn?.(); store.setHasRemoteData(); if (!_this.state.hasFetch) _this.setState({ hasFetch: true }); _this.props.setTotalNum && _this.props.setTotalNum((_a = _this.props.totalTab) === null || _a === void 0 ? void 0 : _a.key, (_b = value === null || value === void 0 ? void 0 : value.data) === null || _b === void 0 ? void 0 : _b.total, _this.props.name, _this.props.bodyName); resolve && resolve(value); (_d = (_c = _this.props).onAiFinished) === null || _d === void 0 ? void 0 : _d.call(_c); interval && _this.mounted && (_this.searchTimer = setTimeout(_this.search.bind(_this, undefined, undefined, undefined, true), Math.max(interval, 1000))); return value; }) : source && store.initFromScope(data, source); } } catch (err) { reject && reject(err); return; } }; _this.afterSearchFn = function () { var _a; var items = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.handleMutilSort(_this.props.loadDataOnce); if (_this.props.loadDataOnce && Array.isArray(items)) _this.setTotal(items.length); }; _this.handleExportDefault = function (keepDataFormat, exportType, exportRangeAll, exportFields) { return (0, utils_1.handleExportDefault)(_this.tableStore, _this.props.aliasTitle, keepDataFormat, exportType, exportRangeAll, exportFields); }; _this.handleAction = function (e, action, ctx, throwErrors, delegate, isItemAction) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; if (throwErrors === void 0) { throwErrors = false; } if (isItemAction === void 0) { isItemAction = false; } var _u = _this.props, onAction = _u.onAction, store = _u.store, messages = _u.messages, pickerMode = _u.pickerMode, env = _u.env, pageField = _u.pageField, columns = _u.columns, data = _u.data; // 如果有有编辑的按钮,并且不是itemaction的action 直接返回 并且展示弹窗 if (((_b = (_a = _this.tableInstance) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.store.modified) > 0 && !isItemAction) { _this.showTableEditWarmModal(); return; } if (['dialog', 'drawer'].includes(action.actionType || '')) { var replace = {}; store.setCurrentAction(action); if ((_c = action.drawer) === null || _c === void 0 ? void 0 : _c.showLoading) store.markBusying(true); var idx = ctx === null || ctx === void 0 ? void 0 : ctx.index; var tableRows = (0, utils_1.getTableRowsData)(store, _this.tableStore); var length = tableRows.length; var openContainerFunction = { dialog: store.openDialog, drawer: store.openDrawer }[action.actionType]; openContainerFunction(ctx, { hasNext: idx < length - 1, nextIndex: idx + 1, hasPrev: idx > 0, prevIndex: idx - 1, index: idx }); if ((_d = action.drawer) === null || _d === void 0 ? void 0 : _d.showLoading) store.markBusying(false); var ctxId = tableRows === null || tableRows === void 0 ? void 0 : tableRows.findIndex(function (item) { return (0, isEqual_1.default)(item, ctx); }); replace.current = ctx; if (ctxId == 0) { replace.next = tableRows[ctxId + 1]; replace.revious = undefined; } else if (ctxId == length) { replace.revious = tableRows[ctxId - 1]; replace.revious = undefined; } else { replace.revious = tableRows[ctxId - 1]; replace.next = tableRows[ctxId + 1]; } if (!(0, isEqual_1.default)(replace, store.replace) && Object.keys(replace).length) { store.replaceDialog(replace); } } else if (action.actionType === 'advanced-filter') { _this.handleFilterAdvanced(); } else if (action.actionType === 'ajax') { store.setCurrentAction(action); var data_1 = ctx; // 由于 ajax 一段时间后再弹出,肯定被浏览器给阻止掉的,所以提前弹。 var redirect = action.redirect && (0, tpl_1.filter)(action.redirect, data_1); redirect && action.blank && env.jumpTo(redirect, action); return store .saveRemote(action.api, data_1, { successMessage: (action.messages && action.messages.success) || (messages && messages.saveSuccess), errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveFailed) }) .then(function (payload) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var data, redirect; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: data = (0, helper_1.createObject)(ctx, payload); // Jay 菜鸟预览 预览按钮是放在操作列,actionType 为 'ajax',根据状态码判断 if ((data === null || data === void 0 ? void 0 : data.status) === 20002) { (0, ExpressPrint_1.expressLabels)(data, env.fetcher, this.props.translate); if (!action.redirect && !action.reload && !action.close) return [2 /*return*/]; } if (!(action.feedback && (0, helper_1.isVisible)(action.feedback, data))) return [3 /*break*/, 2]; return [4 /*yield*/, this.openFeedback(action.feedback, data)]; case 1: _a.sent(); _a.label = 2; case 2: redirect = action.redirect && (0, tpl_1.filter)(action.redirect, data); redirect && !action.blank && env.jumpTo(redirect, action); action.reload ? this.reloadTarget(action.reload, data) : redirect ? null : this.search(undefined, undefined, true, true, this.afterSearchFn); action.close && this.closeTarget(action.close); return [2 /*return*/, null]; } }); }); }) .catch(function () { }); } else if (pickerMode && (action.actionType === 'confirm' || action.actionType === 'submit')) { store.setCurrentAction(action); return Promise.resolve({ items: store.selectedItems.concat() }); } else if (action.onClick) { store.setCurrentAction(action); var onClick = action.onClick; if (typeof onClick === 'string') { onClick = (0, api_1.str2function)(onClick, 'event', 'props', 'data'); } onClick && onClick(e, _this.props, ctx); } else if (action.actionType === 'label-design') { (0, print_1.templateDesign)(ctx, function (value) { antd_1.Modal.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) { if (res.status === 0) { antd_1.message.success(res.msg); // 重新获取数据列表 _this.search(undefined, undefined, true, true); } else { antd_1.message.error(res.msg); } }); } } }); }); } else if (action.actionType === 'export') { if (_this.props.isStatic || _this.props.mode === 'cross') { _this.setState({ staticExportShow: true }); return; } store.setCurrentAction(action); var exportData = {}; var _ids_1 = ''; var _selectedItems = (0, utils_1.getTableSelectedRowsData)(store, _this.tableStore); var optionsParam = (_f = (_e = _this.state.filtercont) === null || _e === void 0 ? void 0 : _e.filterOptionData) === null || _f === void 0 ? void 0 : _f.optionsParam; var advancedFilter = (0, utils_1.dealAdvacedCondition)((_g = _this.state.filtercont) === null || _g === void 0 ? void 0 : _g.advancedFilter); var advancedFilterSub = (0, utils_1.dealAdvacedCondition)((_h = _this.state.filtercont) === null || _h === void 0 ? void 0 : _h.advancedFilterSub); var advancedHeader = (_j = _this.state.filtercont) === null || _j === void 0 ? void 0 : _j.advancedHeader; _selectedItems.map(function (_select) { _ids_1 += _select.hasOwnProperty(_this.props.primaryField) ? _select[_this.props.primaryField] + ',' : ''; }); exportData = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, exportData), (_l = (_k = _this.props) === null || _k === void 0 ? void 0 : _k.store) === null || _l === void 0 ? void 0 : _l.query), { pageId: _this.props.name }); exportData.selectedItems = _selectedItems; exportData.primaryField = _this.props.primaryField; exportData.ids = _ids_1.slice(0, _ids_1.length - 1); exportData.tempIds = ctx[_this.props.primaryField]; if (((_o = (_m = _this.state.filtercont) === null || _m === void 0 ? void 0 : _m.limitParam) === null || _o === void 0 ? void 0 : _o.limitStatus) === true) { exportData.topN = (_q = (_p = _this.state.filtercont) === null || _p === void 0 ? void 0 : _p.limitParam) === null || _q === void 0 ? void 0 : _q.topN; } if (!_this.itemActionData) { exportData.optionsParam = optionsParam; exportData.advancedFilter = advancedFilter; exportData.advancedHeader = advancedHeader; exportData.advancedFilterSub = advancedFilterSub; } var exportSetColumnFields_1 = []; (_r = _this.tableInstance) === null || _r === void 0 ? void 0 : _r.sortCols.forEach(function (col) { if (!(col === null || col === void 0 ? void 0 : col.hidden) && col.name && col.name !== 'operation') { exportSetColumnFields_1.push(col.name); } }); exportData.exportSetColumnFields = exportSetColumnFields_1; var orderBy = (_s = _this.tableStore) === null || _s === void 0 ? void 0 : _s.orderColumnsParam(); orderBy && (exportData.orderBy = orderBy); store.openLionExport(_this.itemActionData ? (0, helper_1.createObject)(_this.itemActionData, tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, exportData), ctx), { handleExportDefault: _this.handleExportDefault }), {}, true) : tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, exportData), ctx), { handleExportDefault: _this.handleExportDefault }), env, undefined, function (isReload) { if (isReload) { action.reload && _this.reloadTarget(action.reload, {}); } }); return false; } else if (action.actionType === 'loginAmazon') { store.setCurrentAction(action); store.openAmazonLoginPage(ctx, env); } else if (action.actionType === 'label-print' || action.actionType === 'bill-print' || action.actionType === 'report-print' || action.actionType === 'batch-print') { // Jay store.setCurrentAction(action); var primaryField_1 = _this.props.primaryField; var __ = _this.props.translate; var LODOP = (0, LodopFuncs_1.getLodop)(); var ids = (0, utils_1.getTableSelectedRowsData)(store, _this.tableStore) .map(function (item) { return item.hasOwnProperty(primaryField_1) ? item[primaryField_1] : null; }) .filter(function (item) { return item; }) .join(','); if (LODOP) { _this.setState({ ModalProps: tslib_1.__assign(tslib_1.__assign({}, action), { show: true, ctx: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, ctx.__super), ctx), { primaryField: primaryField_1, ids: ids || (ctx === null || ctx === void 0 ? void 0 : ctx[primaryField_1]) }) }), printType: action.actionType.slice(0, action.actionType.indexOf('-')) }); } } else if (action.actionType === 'bpm_detail') { if (action.api) { _this.setState({ flowModalVisible: true }); env.fetcher(action.api, ctx).then(function (res) { if (res.status === 0) { _this.setState({ flowModalProps: { flowDetail: res.data, ctx: ctx } }); } else { antd_1.message.error(res.msg); _this.setState({ flowModalVisible: false }); } }); } } else if (action.actionType === 'batch-image-view') { // Aug 批量查看图片 var onImageEnlarge = _this.props.onImageEnlarge; if (!onImageEnlarge) return; if (!(0, helper_1.isMobile)()) { onImageEnlarge({ src: '', originalSrc: '', index: 0, list: [] }); } store.setCurrentAction(action); store .saveRemote(action.api, ctx, { errorMessage: (action.messages && action.messages.failed) || (messages && messages.saveSuccess) }) .then(function (res) { return tslib_1.__awaiter(_this, void 0, void 0, function () { var onImageEnlarge, baseURL, prints; var _a, _b; return tslib_1.__generator(this, function (_c) { onImageEnlarge = this.props.onImageEnlarge; baseURL = ((_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) || ''; prints = []; res.prints.forEach(function (item) { if (item.thumbnailAddr) { prints.push(item); } }); (0, utils_1.openImageEnlarge)(prints, baseURL, onImageEnlarge, env); return [2 /*return*/]; }); }); }) .catch(function () { }); } else if ((_t = action.actionType) === null || _t === void 0 ? void 0 : _t.includes('scale')) { var foldColumns = _this.state.foldColumns; if (foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.includes(action.actionType)) { var newFoldCols = foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.filter(function (col) { return col != action.actionType; }); _this.setState({ foldColumns: newFoldCols }); } else { _this.setState({ foldColumns: tslib_1.__spreadArray(tslib_1.__spreadArray([], foldColumns, true), [action.actionType], false) }); } } else { // 这个就是刷新对应action的方法 onAction(e, action, ctx, throwErrors, delegate || _this.context, _this.props.name, isItemAction); } }; _this.handleFilterReset = function (values, action) { var _a = _this.props, store = _a.store, syncLocation = _a.syncLocation, env = _a.env, pageField = _a.pageField, perPageField = _a.perPageField; store.updateQuery(store.pristineQuery, syncLocation && env && env.updateLocation ? function (location) { return env.updateLocation(location); } : undefined, pageField, perPageField, true); _this.lastQuery = store.query; if (action.type == 'reset') { return; } _this.search(); }; _this.handleFilterSubmit = function (values, jumpToFirstPage, replaceLocation, search, isChild, init) { if (jumpToFirstPage === void 0) { jumpToFirstPage = true; } if (replaceLocation === void 0) { replaceLocation = false; } if (search === void 0) { search = true; } return tslib_1.__awaiter(_this, void 0, void 0, function () { var _a, store, syncLocation, env, pageField, perPageField, loadDataOnceFetchOnFilter, res, _b; var _c; var _d, _e; return tslib_1.__generator(this, function (_f) { switch (_f.label) { case 0: _a = this.props, store = _a.store, syncLocation = _a.syncLocation, env = _a.env, pageField = _a.pageField, perPageField = _a.perPageField, loadDataOnceFetchOnFilter = _a.loadDataOnceFetchOnFilter; if (!(!init && this.filterForm)) return [3 /*break*/, 4]; _f.label = 1; case 1: _f.trys.push([1, 3, , 4]); return [4 /*yield*/, ((_e = (_d = this.filterForm) === null || _d === void 0 ? void 0 : _d.validate) === null || _e === void 0 ? void 0 : _e.call(_d))]; case 2: res = _f.sent(); if (!res) { return [2 /*return*/, Promise.reject()]; } return [3 /*break*/, 4]; case 3: _b = _f.sent(); return [3 /*break*/, 4]; case 4: values = syncLocation ? (0, helper_1.qsparse)((0, helper_1.qsstringify)(values, undefined, true)) : values; if (values.filterParam) { values.filterParam = Object.keys(values.filterParam).reduce(function (acc, key) { if (values.filterParam[key] !== '') { acc[key] = values.filterParam[key]; } return acc; }, {}); } store.updateQuery(tslib_1.__assign(tslib_1.__assign({}, values), (_c = {}, _c[pageField || 'page'] = jumpToFirstPage ? 1 : store.page, _c)), syncLocation && env && env.updateLocation ? function (location) { return env.updateLocation(location, replaceLocation); } : undefined, pageField, perPageField); this.lastQuery = store.query; search && this.search(undefined, undefined, undefined, loadDataOnceFetchOnFilter, this.afterSearchFn, undefined, isChild, undefined, init); return [2 /*return*/]; } }); }); }; _this.handleFilterInit = function (values, isChild, init) { if (isChild === void 0) { isChild = false; } return tslib_1.__awaiter(_this, void 0, void 0, function () { var _a, defaultParams, data, store, _b, pickerMode, options; var _c; return tslib_1.__generator(this, function (_d) { switch (_d.label) { case 0: _a = this.props, defaultParams = _a.defaultParams, data = _a.data, store = _a.store; if (!((_c = this.props) === null || _c === void 0 ? void 0 : _c.advancedFilterApi)) return [3 /*break*/, 2]; return [4 /*yield*/, this.defaultAdvancedQuery(1)]; case 1: _d.sent(); _d.label = 2; case 2: this.handleFilterSubmit(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, defaultParams), values), store.query), false, true, this.props.initFetch !== false, isChild, init); store.setPristineQuery(); _b = this.props, pickerMode = _b.pickerMode, options = _b.options; pickerMode && store.updateData({ items: options || [] }); return [2 /*return*/]; } }); }); }; _this.handleSaveAdvancedFilterData = function (val, cont) { if (val.includes('advancedFilter')) { var name = val.split('.'); if (name[name.length - 1].includes('--')) { if (!!_this.advancedFilterData.set(name[name.length - 1].split('--')[0], cont)) { _this.advancedFilterData.set(name[name.length - 1].split('--')[0], cont); } } else _this.advancedFilterData.set(name[name.length - 1], cont); } else { _this.advancedFilterData.set(val, cont); } }; // 高级查询内容展示 _this.handlefilters = function () { var _a; var _b = _this.props, advancedFilter = _b.advancedFilter, advancedQueryFields = _b.advancedQueryFields; var filtercont = _this.state.filtercont; // 调用纯函数计算 var filtertpl = (0, utils_1.computeFilterTpl)({ advancedFilter: advancedFilter, advancedQueryFields: advancedQueryFields, filtercont: filtercont, advancedFilterData: _this.advancedFilterData, advanceFilterFormState: (_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.state }); _this.setState({ filtertpl: filtertpl }); }; _this.handlePrefix = function (filter) { return (0, utils_1.handlePrefix)(filter, _this.props.advancedQueryFields, _this.props.advancedFilter); }; // 查询1 // selectApi // 修改2 // modifyApi // 删除3 // deleteApi _this.defaultAdvancedQuery = function (val, body, senior) { if (val === void 0) { val = 1 | 2 | 3; } return tslib_1.__awaiter(_this, void 0, void 0, function () { var _a, env, _b, selectApi, modifyApi, deleteApi, _c, defaultTempKey, defaultList, filter_1, list, data, api, res, body_1, options, filterBody, filters_1, defaultBody, data, api, queryParams, rawShowFields, optionsParam, newAdvancedFilter, url, columnInfo, data, msg, res, api, url, res, _d; var _this = this; var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; return tslib_1.__generator(this, function (_y) { switch (_y.label) { case 0: _a = this.props, env = _a.env, _b = _a.advancedFilterApi, selectApi = _b.selectApi, modifyApi = _b.modifyApi, deleteApi = _b.deleteApi; _c = this.state, defaultTempKey = _c.defaultTempKey, defaultList = _c.defaultList; _y.label = 1; case 1: _y.trys.push([1, 13, , 14]); if (!(val == 1)) return [3 /*break*/, 5]; if (!(body && defaultList.some(function (item) { return body.tempKey == item.tempKey; }))) return [3 /*break*/, 2]; filter_1 = defaultList.find(function (item) { return body.tempKey == item.tempKey; }).columnInfo; list = defaultList.find(function (item) { return body.tempKey == item.tempKey; }); this.setState({ filtercont: tslib_1.__assign(tslib_1.__assign({}, this.state.filtercont), filter_1), multipleDefault: list.tempName, defaultTempKey: list.tempKey }, function () { _this.handlefilters(); }); if (this.advancedMode == 'condition' || this.advancedMode == 'popup-condition') { filter_1.optionsParam = undefined; } data = this.handlePrefix(filter_1); (_e = this.advanceFilterForm) === null || _e === void 0 ? void 0 : _e.handleFiltersArr(data); return [3 /*break*/, 4]; case 2: api = selectApi; if (!api) return [2 /*return*/, true]; return [4 /*yield*/, env.fetcher(api)]; case 3: res = _y.sent(); if (res.status == 0 && res.data) { body_1 = res.data; if (Array.isArray(body_1)) { filter_1 = (0, cloneDeep_1.default)(body_1[0].columnInfo); options = filter_1.optionsParam; //过滤掉不存在的字段 if (Array.isArray(filter_1.advancedFilter)) { filterBody = (_f = this.props.advancedFilter) === null || _f === void 0 ? void 0 : _f.body; filterBody = Array.isArray(filterBody) ? filterBody : filterBody ? [filterBody] : []; filters_1 = (_g = filterBody.find(function (item) { return item.name === 'advancedFilter'; })) === null || _g === void 0 ? void 0 : _g.body; filter_1.advancedFilter = filter_1.advancedFilter.filter(function (item) { var isInside = !!filters_1.find(function (col) { return col.name === "advancedFilter.".concat(item.field); }); return isInside; }); filter_1.advancedFilterSub = filter_1.advancedFilterSub.filter(function (item) { var isInside = !!filters_1.find(function (col) { return col.name === "advancedFilterSub.".concat(item.field); }); return isInside; }); } if (this.advancedMode == 'condition' || this.advancedMode == 'popup-condition') { filter_1.optionsParam = undefined; } else if (options) { if (options.itemCount === false && options.itemRepeat === false && options.itemSumCount === false && options.section === false && ((_h = options.showFields) === null || _h === void 0 ? void 0 : _h.length) === 0 && ((_j = options.sortFields) === null || _j === void 0 ? void 0 : _j.length) === 0 && ((_k = options.groupByFields) === null || _k === void 0 ? void 0 : _k.length) === 0) { filter_1.optionsParam = undefined; } } defaultBody = body_1.map(function (item) { var _a, _b; if (!(item === null || item === void 0 ? void 0 : item.tempKey)) { return { columnInfo: item, tempKey: (_a = item === null || item === void 0 ? void 0 : item.tempKey) !== null && _a !== void 0 ? _a : (0, helper_1.uuid)(), tempName: (_b = item === null || item === void 0 ? void 0 : item.tempName) !== null && _b !== void 0 ? _b : '默认设置' }; } return item; }); this.setState({ defaultList: defaultBody, multipleDefault: body_1[0].tempName, defaultTempKey: body_1[0].tempKey, defaultTempValue: (_l = body_1[0].tempKey) !== null && _l !== void 0 ? _l : 'defaultQuery' }); } else { if ((_m = res.data) === null || _m === void 0 ? void 0 : _m.columnInfo) { filter_1 = (0, cloneDeep_1.default)(res.data.columnInfo); } else { filter_1 = (0, cloneDeep_1.default)(res.data); this.setState({ defaultList: [] }); } if (this.advancedMode == 'condition' || this.advancedMode == 'popup-condition') { filter_1.optionsParam = undefined; } this.setState({ defaultList: [ { columnInfo: filter_1, tempKey: (_p = (_o = res.data) === null || _o === void 0 ? void 0 : _o.tempKey) !== null && _p !== void 0 ? _p : (0, helper_1.uuid)(), tempName: (_r = (_q = res.data) === null || _q === void 0 ? void 0 : _q.tempName) !== null && _r !== void 0 ? _r : '默认设置' } ] }); } // const filter = cloneDeep(res.data.columnInfo) this.setState({ filtercont: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, this.state.filtercont), filter_1), { optionsParam: filter_1.optionsParam }) }, function () { _this.handlefilters(); }); data = (0, utils_1.handlePrefix)(filter_1, this.props.advancedQueryFields, this.props.advancedFilter); (_s = this.advanceFilterForm) === null || _s === void 0 ? void 0 : _s.handleFiltersArr(data); } else { this.setState({ defaultTempValue: 'defaultQuery' }, (_t = this.advanceFilterForm) === null || _t === void 0 ? void 0 : _t.resetDefaultQuery()); } _y.label = 4; case 4: return [3 /*break*/, 12];