fastlion-amis
Version:
一种MIS页面生成工具
4,261 lines • 277 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CRUDRenderer = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var factory_1 = require("../factory");
var crud_1 = require("../store/crud");
var helper_1 = require("../utils/helper");
var Scoped_1 = require("../Scoped");
var Button_1 = tslib_1.__importDefault(require("../components/Button"));
var filter_schema_1 = tslib_1.__importDefault(require("../utils/filter-schema"));
var pick_1 = tslib_1.__importDefault(require("lodash/pick"));
var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
var react_dom_1 = require("react-dom");
var tpl_1 = require("../utils/tpl");
var api_1 = require("../utils/api");
var omit_1 = tslib_1.__importDefault(require("lodash/omit"));
var findIndex_1 = tslib_1.__importDefault(require("lodash/findIndex"));
var Html_1 = tslib_1.__importDefault(require("../components/Html"));
var components_1 = require("../components");
var icons_1 = require("../components/icons");
var Table_1 = require("./Table");
var tpl_builtin_1 = require("../utils/tpl-builtin");
// Jay
var LabelPrint_1 = require("./Lion/LabelPrint");
var print_1 = require("../utils/print");
var LodopFuncs_1 = require("../utils/print/LodopFuncs");
var ExpressPrint_1 = require("./Lion/ExpressPrint/ExpressPrint");
var antd_1 = require("antd");
var ActionSheet_1 = tslib_1.__importDefault(require("../components/Lion/ActionSheet"));
var utils_1 = require("./Lion/utils/utils");
var util_1 = require("../utils/print/util");
var locale_1 = require("../locale");
var tools_1 = require("../utils/shell/tools");
var BatchOperation_1 = require("../components/Lion/BatchOperation");
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
var LionCopyItem_1 = tslib_1.__importDefault(require("./Lion/components/LionCopyItem"));
var sub_1 = require("../utils/sub");
var Workflow_1 = tslib_1.__importDefault(require("../components/Mobileprocess/Workflow"));
var lodash_1 = require("lodash");
var SecondFilterDrawer_1 = require("../components/table/SecondFilter/SecondFilterDrawer");
var antdComponentsProxy_1 = require("../components/antdComponentsProxy");
var storage_1 = require("../utils/storage");
var DefaultListPopup_1 = tslib_1.__importDefault(require("../components/Lion/DefaultListPopup"));
var icons_2 = require("@ant-design/icons");
var xlsx_1 = require("../utils/xlsx");
var AiTool_1 = tslib_1.__importDefault(require("./Table/AiTool"));
// import modalStore from '../components/DragModal/modalStore';
var mobx_react_1 = require("mobx-react");
var tableCtxMenuStore_1 = tslib_1.__importDefault(require("./Table/tableCtxMenuStore"));
var commonTableFunction_1 = require("../store/utils/commonTableFunction");
var OverflowWrapper_1 = tslib_1.__importDefault(require("../components/OverflowWrapper"));
// import DragModal from '../components/DragModal';
var crudFilter_1 = require("../templateSchema/crudFilter");
var utils_2 = require("./CRUD/utils");
var Offline_1 = tslib_1.__importDefault(require("./CRUD/components/Offline"));
// 不做处理的按钮类型
var specialButtonType = ['rfid-action'];
var CRUD = /** @class */ (function (_super) {
tslib_1.__extends(CRUD, _super);
function CRUD(props) {
var _this = this;
var _a, _b, _c;
_this = _super.call(this, props) || this;
_this.sort = false;
_this.saveData = new Map();
_this.startX = 0;
_this.startY = 0;
_this.filterDrawerOpened = false;
_this.crudRef = react_1.default.createRef();
_this.fingerprintModalData = undefined;
_this.hasToolBars = false; //是否有工具栏判断
_this.filterData = {};
// 判断条件是否是个合法空值 如果是 空 的情况 默认是true 如果不是 则判断 是不是 undefined null ''
_this.advancefilterValueIsLegalEmptyValue = function (item) {
return item.op !== 10 && ((0, lodash_1.isNil)(item.values) || item.values === '');
};
_this.calcToolActionsMaxCount = function () {
var toolActionsElement = _this.toolActionsRef.current;
if (toolActionsElement) {
var width = 0;
for (var i = 0; i < toolActionsElement.children.length; i++) {
var element = toolActionsElement.children.item(i);
width += element.clientWidth + 12;
if (width > toolActionsElement.clientWidth - 70) {
_this.setState({ toolChildMaxCount: i });
break;
}
}
}
};
// 处理高级查询条件 sub 和 普通的
_this.dealAdvacedCondition = function (advacedArr) {
return (advacedArr === null || advacedArr === void 0 ? void 0 : advacedArr.filter(function (item) {
if (_this.advancefilterValueIsLegalEmptyValue(item)) {
return false;
}
return true;
})) || [];
};
//记录当前选中行,以便再数据更新时向目标组件传送选中行的数据
_this.currentSelectedRow = 0;
_this.changeSelectedRow = function (index) {
if (index === void 0) { index = 0; }
_this.currentSelectedRow = index;
};
//获取全量数据,用于统计
_this.getAllData = function (showFields) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, api, env, allData, params, optionsParam, paramsData, res;
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
return tslib_1.__generator(this, function (_q) {
switch (_q.label) {
case 0:
_a = this.props, api = _a.api, env = _a.env;
allData = {};
if (!api) return [3 /*break*/, 2];
params = {};
if (Object.keys(this.state.filtercont || {}).length) {
params = {
advancedFilter: this.dealAdvacedCondition((_b = this.state.filtercont) === null || _b === void 0 ? void 0 : _b.advancedFilter),
advancedFilterSub: this.dealAdvacedCondition((_c = this.state.filtercont) === null || _c === void 0 ? void 0 : _c.advancedFilterSub),
advancedHeader: (_d = this.state.filtercont) === null || _d === void 0 ? void 0 : _d.advancedHeader,
optionsParam: (showFields === null || showFields === void 0 ? void 0 : showFields.length) > 0 ? tslib_1.__assign(tslib_1.__assign({}, (_e = this.state.filtercont) === null || _e === void 0 ? void 0 : _e.optionsParam), { queryField: showFields }) : (_f = this.state.filtercont) === null || _f === void 0 ? void 0 : _f.optionsParam,
filterParam: (_g = this.state.filtercont) === null || _g === void 0 ? void 0 : _g.filterParam
};
if ((_h = this.state.filtercont) === null || _h === void 0 ? void 0 : _h.filterOptionData) {
optionsParam = ((_j = this.state.filtercont) === null || _j === void 0 ? void 0 : _j.filterOptionData).optionsParam;
params = tslib_1.__assign(tslib_1.__assign({}, params), optionsParam);
}
}
else {
if ((showFields === null || showFields === void 0 ? void 0 : showFields.length) > 0) {
params.optionsParam = { queryField: showFields };
}
}
paramsData = tslib_1.__assign(tslib_1.__assign({}, params), { index: 1, filterParam: (_k = this.props.store.query) === null || _k === void 0 ? void 0 : _k.filterParam, topN: ((_m = (_l = this.state.filtercont) === null || _l === void 0 ? void 0 : _l.limitParam) === null || _m === void 0 ? void 0 : _m.limitStatus) ? (_p = (_o = this.state.filtercont) === null || _o === void 0 ? void 0 : _o.limitParam) === null || _p === void 0 ? void 0 : _p.topN : undefined });
return [4 /*yield*/, env.fetcher(api, (0, helper_1.createObject)(this.props.data, paramsData))];
case 1:
res = _q.sent();
if (res.ok && res.data) {
allData = res.data;
}
else {
allData = null;
antd_1.message.error(res.msg);
}
return [2 /*return*/, allData];
case 2: return [2 /*return*/, allData];
}
});
}); };
_this.dealCellValue = function (originValue, columnName) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
var columns = _this.props.columns;
var keepFormat = _this.state.keepDataFormat === '1';
var value = originValue;
var column = columns.find(function (column) { return column.name === columnName; });
var prefix = (_c = (_a = column.prefix) !== null && _a !== void 0 ? _a : (_b = column === null || column === void 0 ? void 0 : column.pristine) === null || _b === void 0 ? void 0 : _b.prefix) !== null && _c !== void 0 ? _c : '';
var suffix = (_f = (_d = column.suffix) !== null && _d !== void 0 ? _d : (_e = column === null || column === void 0 ? void 0 : column.pristine) === null || _e === void 0 ? void 0 : _e.suffix) !== null && _f !== void 0 ? _f : '';
if ((column === null || column === void 0 ? void 0 : column.type) === 'mapping') {
value = (_h = (_g = column === null || column === void 0 ? void 0 : column.map) === null || _g === void 0 ? void 0 : _g[originValue]) !== null && _h !== void 0 ? _h : (originValue !== null && originValue !== void 0 ? originValue : '');
}
else if ((column === null || column === void 0 ? void 0 : column.type) === 'number' && keepFormat) {
var kilobitSeparator = (_l = (_j = column.kilobitSeparator) !== null && _j !== void 0 ? _j : (_k = column === null || column === void 0 ? void 0 : column.pristine) === null || _k === void 0 ? void 0 : _k.kilobitSeparator) !== null && _l !== void 0 ? _l : false;
var precision = (_m = column.precision) !== null && _m !== void 0 ? _m : (_o = column === null || column === void 0 ? void 0 : column.pristine) === null || _o === void 0 ? void 0 : _o.precision;
if (kilobitSeparator && originValue != null) {
value = (0, helper_1.numberFormatter)(originValue, precision);
}
}
else if ((column === null || column === void 0 ? void 0 : column.type) === 'number' && !keepFormat) {
value = (0, lodash_1.isNil)(originValue) ? originValue : value / 100;
}
if (value != null) {
return typeof value == 'object' ? '[文件]' : "".concat(keepFormat ? prefix : '').concat(typeof value == 'string' ? value.replaceAll('\n', '').replaceAll('\r', '') : value).concat(keepFormat ? suffix : '');
}
return '';
};
//导出统计数据
_this.handleExportStatic = function () {
var _a, _b, _c, _d;
var _e = _this.props, columns = _e.columns, data = _e.data;
var staticExportRange = _this.state.staticExportRange;
var selItems = [];
if (staticExportRange === '1') {
selItems = (0, utils_2.getTableSelectedRowsData)(_this.props.store, _this.tableStore);
if (!selItems || selItems.length == 0) {
antd_1.message.warn('选中数据为空');
return;
}
}
var cols = columns.map(function (item) { return item.label; });
var excelData = (staticExportRange === '0' ? (_b = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.rows.map(function (row) { return row.data; })) !== null && _b !== void 0 ? _b : [] :
staticExportRange === '1' ? selItems :
data.itemsRaw).map(function (row) { return columns.map(function (item) { return _this.dealCellValue(row[item.name], item.name); }); });
(0, xlsx_1.exportXLSX)(cols, excelData, "".concat(((_d = (_c = _this.props.aliasTitle) === null || _c === void 0 ? void 0 : _c.trim) === null || _d === void 0 ? void 0 : _d.call(_c)) || '统计', ".xlsx"));
};
_this.handleExportCross = function () {
var _a, _b, _c;
var staticExportRange = _this.state.staticExportRange;
var columns = _this.tableStore.filteredColumns.filter(function (item) { return item.type !== '__checkme' && item.type != '__pseudoColumn'; });
var tableHeadRows = (0, commonTableFunction_1.getHeadRows)(columns, true);
var excelData = (0, lodash_1.flatMap)((_a = _this.tableStore.rows) !== null && _a !== void 0 ? _a : [], function (row) {
if (staticExportRange == '1') {
return row.checked ? row.data : [];
}
return row.data;
});
(0, xlsx_1.exportXLSXFromCross)(tableHeadRows, columns, excelData, "".concat(((_c = (_b = _this.props.aliasTitle) === null || _b === void 0 ? void 0 : _b.trim) === null || _c === void 0 ? void 0 : _c.call(_b)) || '交叉制表', ".xlsx"), _this.state.keepDataFormat === '1');
};
// 判断元素是否在小型弹窗里
_this.inSmallDialog = function () {
var _a, _b, _c;
return !!((_c = (_b = (_a = _this.crudRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.closest('div[role="dialog"]')) === null || _c === void 0 ? void 0 : _c.className.includes('Modal--sm'));
};
_this.markSort = function () {
_this.sort = true;
};
/**
*
* @param keepDataFormat 保留格式
* @param isTemplate 导出方式
*/
_this.handleExportDefault = function (keepDataFormat, exportType, exportRangeAll, exportFields) {
var _a, _b, _c, _d;
var columns = _this.tableStore.filteredColumns.filter(function (item) { return item.type !== 'lion-upload' && item.type !== '__checkme' && item.type != '__pseudoColumn' && item.name !== 'operation' && item.name; });
if (exportType === 'template' && (exportFields === null || exportFields === void 0 ? void 0 : exportFields.length)) {
var exportCols_1 = [];
exportFields.forEach(function (item) {
var targetItem = columns.find(function (col) { return col.name === item; });
if (targetItem)
exportCols_1.push(targetItem);
});
columns = exportCols_1;
}
var tableHeadRows = (0, commonTableFunction_1.getHeadRows)(columns, true);
var excelData = (_b = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.rows.filter(function (row) { return exportRangeAll || row.checked; }).map(function (row) { return row.data; })) !== null && _b !== void 0 ? _b : [];
(0, xlsx_1.exportXLSXFromCross)(tableHeadRows, columns, excelData, "".concat(((_d = (_c = _this.props.aliasTitle) === null || _c === void 0 ? void 0 : _c.trim) === null || _d === void 0 ? void 0 : _d.call(_c)) || '导出', ".xlsx"), keepDataFormat);
};
_this.handleJump = function (body) {
var _a;
if (body.redirectType === '2') {
_this.props.env.fetcher(body.linkUrl, body.bodydata).then(function (res) {
if (res.ok && res.data != null) {
_this.setState({ flowModalProps: { flowDetail: res.data }, flowModalVisible: true });
}
else {
antd_1.message.error(res.msg);
}
});
return;
}
var types = (0, helper_1.isMobile)() ? 'drawer' : 'dialog';
var action = {
type: "action",
actionType: types,
close: true
};
action[types] = {
showLoading: (0, helper_1.isMobile)(),
title: body.linkTitle,
type: types,
size: (_a = body.linkSize) !== null && _a !== void 0 ? _a : 'lg',
bodyClassName: "overflow-y-auto max-h-nestSide-".concat(types),
className: "h-full",
actions: [],
overlay: (0, helper_1.isMobile)() ? false : true,
body: {
schemaApi: {
"method": "get",
"url": body.linkUrl
},
type: "service"
}
};
_this.handleAction(_this.props.e, action, body.bodydata);
};
// 上拉加载更多数据
_this.lionPullRequest = function (values, init) {
return new Promise(function (resolve, reject) {
var _a;
var _b, _c;
var _d = _this.props, defaultParams = _d.defaultParams, data = _d.data, store = _d.store;
var _e = _this.props, syncLocation = _e.syncLocation, pageField = _e.pageField, perPageField = _e.perPageField;
values = syncLocation
? (0, helper_1.qsparse)((0, helper_1.qsstringify)(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, defaultParams), values), store.query), undefined, true))
: values;
store.changePage(init ? store.page : store.page + 1, (0, helper_1.isMobile)() ? (((_c = (_b = _this.props) === null || _b === void 0 ? void 0 : _b.perPage) !== null && _c !== void 0 ? _c : 10) < 20 ? 20 : _this.props.perPage) : _this.props.perPage);
store.updateQuery(tslib_1.__assign(tslib_1.__assign({}, values), (_a = {}, _a[pageField || 'page'] = store.page, _a)), undefined, pageField, perPageField);
_this.search({ page: store.page, loadDataMode: 'load-more' }, undefined, false, undefined, resolve, reject);
store.setPristineQuery();
});
};
_this.handleLoadMore = function () {
// if (!this.props.loadDataOnce) {
_this.search({ page: _this.props.store.page + 1, loadDataMode: 'load-more' });
// }
};
//移动端刷新或查询时需要滚动到顶部,不然会逐页请求数据
_this.handleScrollToTop = function () {
if ((0, helper_1.isMobile)()) {
var classPrefix = _this.props.classPrefix;
var crud = (0, react_dom_1.findDOMNode)(_this);
var container = crud.querySelector(".".concat(classPrefix, "Table-content"));
if (container) {
container.scrollTo({ top: 0 });
}
var Listitems = crud.querySelector(".".concat(classPrefix, "List-items"));
if (Listitems) {
Listitems.scrollTo({ top: 0 });
}
}
};
//刷新数据,带查询条件
_this.handleResetData = function () {
_this.handleScrollToTop();
_this.search({ page: 1 });
};
_this.handleOptions = function (body) {
var columns = _this.props.columns;
var optionsParam = (0, cloneDeep_1.default)(body);
var compare1 = columns.map(function (item) { return item.name; });
var compare2 = optionsParam === null || optionsParam === void 0 ? void 0 : optionsParam.showFields;
if (compare1 && compare2 && (0, isEqual_1.default)(compare1, compare2)) {
optionsParam.showFields = [];
}
return optionsParam;
};
_this.bulkActionRender = function (btn, index) {
var _a, _b;
var _c = _this.props, render = _c.render, store = _c.store, fullDataApi = _c.fullDataApi, primaryField = _c.primaryField;
var ctx = store.mergedData;
var selectedItems = (0, utils_2.getTableSelectedRowsData)(_this.props.store, _this.tableStore);
var unSelectedItems = store.unSelectedItems;
var ids = selectedItems.map(function (item) {
return item.hasOwnProperty(primaryField) ? item[primaryField] : null;
}).filter(function (item) { return item; }).join(',');
return render("bulk-action/".concat(index), tslib_1.__assign(tslib_1.__assign({}, (0, omit_1.default)(btn, ['visibleOn', 'hiddenOn', 'disabledOn'])), { type: specialButtonType.includes(btn.type) ? btn.type : 'button', ignoreConfirm: true, hidden: false }), {
key: "bulk-".concat(index),
data: (0, helper_1.extendObject)(store.data, tslib_1.__assign(tslib_1.__assign({}, ctx), { ids: ids })),
filterData: _this.state.filterData,
fullDataApi: fullDataApi,
disabled: btn.disabled ||
(btn.requireSelected !== false ? ((0, helper_1.isMobile)() && (0, lodash_1.isObject)((_a = btn === null || btn === void 0 ? void 0 : btn.api) === null || _a === void 0 ? void 0 : _a.data) && Object.keys((_b = btn === null || btn === void 0 ? void 0 : btn.api) === null || _b === void 0 ? void 0 : _b.data).includes('SELECTION_IDS') && selectedItems.length > 0 ? false : !selectedItems.length) : false),
onAction: function (e, action) {
return _this.handleBulkAction(selectedItems.concat(), unSelectedItems.concat(), e, action, btn);
}
});
};
_this.exchangeMode = function () {
var _a = _this.props, listItem = _a.listItem, card = _a.card, cross = _a.cross;
var modes = _this.state.modes;
if (card && listItem && cross) {
return;
}
if (modes == 'table' || modes == undefined) {
_this.setState({ modes: listItem ? 'list' : cross ? 'cross' : 'cards' }, _this.handleFakeAnimation);
}
else {
_this.setState({ modes: 'table' }, _this.handleFakeAnimation);
}
};
//函数防抖,3s内只触发第一次
_this.debounceChangeMode = (0, lodash_1.debounce)(_this.exchangeMode.bind(_this), 3000, { leading: true, trailing: false });
_this.handleFakeAnimation = (0, lodash_1.debounce)(function () {
// // 加载假动画 在线上没问题amis上有问题
setTimeout(function () {
var _a, _b, _c;
(_c = (_b = (_a = _this.control) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.setLoading) === null || _c === void 0 ? void 0 : _c.call(_b, true);
}, 0);
setTimeout(function () {
var _a, _b, _c;
(_c = (_b = (_a = _this.control) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.setLoading) === null || _c === void 0 ? void 0 : _c.call(_b, false);
}, 1000);
}, 1000);
_this.toolBarAction = function () {
_this.reload(undefined, undefined, undefined);
};
_this.renderReload = function (toolbar, index) {
var _a = _this.props, render = _a.render, __ = _a.translate;
if (toolbar.isToolBar && (0, helper_1.isMobile)()) {
return (react_1.default.createElement("div", { className: 'toolbar-item', onClick: function () { return _this.toolBarAction(); } },
react_1.default.createElement("div", { className: 'toolbar-item-icon' },
react_1.default.createElement(icons_1.Icon, { icon: toolbar.icon })),
react_1.default.createElement("div", { className: 'toolbar-item-name' }, __('reload'))));
}
else {
var reloadButton = {
label: '',
icon: toolbar.icon,
tooltip: __('reload'),
tooltipPlacement: 'top',
type: 'button'
};
if (typeof toolbar === 'object') {
reloadButton = tslib_1.__assign(tslib_1.__assign({}, reloadButton), (0, omit_1.default)(toolbar, ['type', 'align']));
}
return render("toolbar/".concat(index), reloadButton, {
onAction: _this.toolBarAction
});
}
};
// Jay
_this.getTableStore = function (store) {
_this.tableStore = store;
};
_this.handleAdvanceSearch = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var res, confirmData, key, _a, filter_1, _b, body, filterParam_1, filterNameArr, isFilterPause, key, queryParams, optionsParam, rawShowFields, itemCount, itemSumCount, showFields_1, sortFields, groupByFields, allInclude, _c, advancedFilterVisible, filterExist, name, originConditionStr, originCondition, newCondition;
var _d, _e;
var _this = this;
var _f, _g, _h;
return tslib_1.__generator(this, function (_j) {
switch (_j.label) {
case 0: return [4 /*yield*/, this.advanceFilterForm.validate()];
case 1:
res = _j.sent();
confirmData = (_f = this.advanceFilterForm) === null || _f === void 0 ? void 0 : _f.confirmAdvancedFilter();
// 移动端的确认逻辑与PC端区别开
if ((0, helper_1.isMobile)()) {
//删除filterParam值为空字符串的属性
if (confirmData.filterParam) {
for (key in confirmData.filterParam) {
if (Object.prototype.hasOwnProperty.call(confirmData.filterParam, key)) {
if (confirmData.filterParam[key] === '') {
delete confirmData.filterParam[key];
}
}
}
}
// 如果校验没有通过,查看是快速查询还是高级查询没有通过校验,与底下的逻辑区分开
if (!res) {
_a = this.props.filter, filter_1 = _a === void 0 ? {} : _a;
_b = filter_1.body, body = _b === void 0 ? [] : _b;
filterParam_1 = confirmData.filterParam;
filterNameArr = body.filter(function (bodyItem) { return bodyItem === null || bodyItem === void 0 ? void 0 : bodyItem.required; }).map(function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.name) === null || _a === void 0 ? void 0 : _a.split('.')) === null || _b === void 0 ? void 0 : _b.pop(); });
isFilterPause = filterNameArr.some(function (name) { return (0, lodash_1.isNil)(filterParam_1[name]) || !filterParam_1[name].length; });
// filterParamStatus = !isFilterPause;
// 如果是高级查询模式下,直接return
if (this.state.advancedFilterAction) {
return [2 /*return*/];
}
else {
if (isFilterPause)
return [2 /*return*/];
}
}
}
else {
if (!res)
return [2 /*return*/];
//删除filterParam值为空字符串的属性
if (confirmData.filterParam) {
for (key in confirmData.filterParam) {
if (Object.prototype.hasOwnProperty.call(confirmData.filterParam, key)) {
if (confirmData.filterParam[key] === '') {
delete confirmData.filterParam[key];
}
}
}
}
}
this.handleScrollToTop();
queryParams = tslib_1.__assign(tslib_1.__assign({}, confirmData), { page: 1 });
optionsParam = (_g = queryParams === null || queryParams === void 0 ? void 0 : queryParams.filterOptionData) === null || _g === void 0 ? void 0 : _g.rawOptionsParams;
rawShowFields = (_h = queryParams === null || queryParams === void 0 ? void 0 : queryParams.filterOptionData) === null || _h === void 0 ? void 0 : _h.rawShowFields;
if (queryParams === null || queryParams === void 0 ? void 0 : queryParams.limitParam.limitStatus) {
queryParams = tslib_1.__assign(tslib_1.__assign({}, queryParams), { topN: queryParams.limitParam.topN });
}
else {
queryParams = tslib_1.__assign(tslib_1.__assign({}, queryParams), { topN: undefined });
}
if (this.advancedMode == 'normal' || this.advancedMode == 'popup-normal') {
itemCount = optionsParam.itemCount, itemSumCount = optionsParam.itemSumCount, showFields_1 = optionsParam.showFields, sortFields = optionsParam.sortFields, groupByFields = optionsParam.groupByFields;
if (!itemCount && !itemSumCount) {
if (rawShowFields.length == 0) {
antd_1.message.warning('显示字段不能为空');
return [2 /*return*/];
}
}
if (sortFields.length > 0 && groupByFields.length > 0) {
allInclude = sortFields.every(function (sortField) { return showFields_1.some(function (showField) { return sortField.includes(showField); }); });
if (!allInclude) {
antd_1.message.warning('同时使用排序和分组时,排序字段必须出现在显示字段中');
return [2 /*return*/];
}
}
}
_c = this.state, advancedFilterVisible = _c.advancedFilterVisible, filterExist = _c.filterExist;
if ((0, helper_1.isMobile)() && advancedFilterVisible && filterExist) {
this.setState({ filterExist: false });
}
this.props.store.updateQuery(queryParams);
if ((0, helper_1.isMobile)()) {
//移动端查询时将查询条件缓存在本地
try {
name = this.props.name;
originConditionStr = localStorage.getItem('tableSearchCondition');
if (originConditionStr) {
originCondition = JSON.parse(originConditionStr);
newCondition = tslib_1.__assign(tslib_1.__assign({}, originCondition), (_d = {}, _d[name] = queryParams, _d));
localStorage.setItem('tableSearchCondition', JSON.stringify(newCondition));
}
else {
localStorage.setItem('tableSearchCondition', JSON.stringify((_e = {}, _e[name] = queryParams, _e)));
}
}
catch (error) {
console.log(error);
}
}
this.setState({ filtercont: queryParams }, function () {
var _a, _b, _c, _d;
_this.handlefilters();
_this.search(undefined, undefined, undefined, true, function (res) {
if (optionsParam === null || optionsParam === void 0 ? void 0 : optionsParam.itemCount) {
if (res.status === 0) {
var count = res.data.items[0]['ITEM_NUMBER'];
if (count) {
antd_1.Modal.info({ icon: null, title: '提示', content: "\u9879\u6570: ".concat(count), okText: '确定' });
}
}
}
}, undefined, undefined, queryParams);
_this.filterDrawerOpened = false;
(_b = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.filterColumns) === null || _b === void 0 ? void 0 : _b.clear();
(_d = (_c = _this.tableStore) === null || _c === void 0 ? void 0 : _c.orderColumns) === null || _d === void 0 ? void 0 : _d.clear();
_this.setState({ showColumnsFilter: false });
});
this.hideAdvancedFilter();
return [2 /*return*/];
}
});
}); };
_this.renderAdvancedFilterAction = (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement("span", { style: { display: 'inline-block', marginRight: 10 } },
react_1.default.createElement(Button_1.default, { onClick: function (e) {
var _a;
(_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.resetIsModleFilter(e);
} }, _this.props.translate('reset'))),
react_1.default.createElement(Button_1.default, { level: "primary", onClick: function () { _this.handleAdvanceSearch(); } }, _this.props.translate('confirm'))));
_this.renderAdvancedModalHeader = function () {
var _a, _b;
var advancedTitle = (_b = (_a = _this.props.tabTitle) !== null && _a !== void 0 ? _a : _this.props.aliasTitle) !== null && _b !== void 0 ? _b : '';
var _c = _this.state, defaultList = _c.defaultList, defaultTempValue = _c.defaultTempValue;
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement("div", { className: 'title' }, _this.props.translate('CRUD.advancedFilter') + (advancedTitle ? " - ".concat(advancedTitle) : '')),
react_1.default.createElement("div", { className: 'template' },
react_1.default.createElement("div", { className: 'template-left' },
react_1.default.createElement(icons_2.QuestionCircleOutlined, { title: "\u4FDD\u5B58\uFF1A\u66F4\u65B0\u5F53\u524D\u9009\u4E2D\u7684\u6A21\u677F\u4FE1\u606F\n\u53E6\u5B58\u4E3A\uFF1A\u57FA\u4E8E\u73B0\u6709\u9009\u9879\u521B\u5EFA\u4E00\u4E2A\u65B0\u6A21\u677F\n\u5220\u9664\uFF1A\u5220\u9664\u5F53\u524D\u9009\u62E9\u7684\u6A21\u677F\n\u6E05\u9664\uFF1A\u6E05\u7A7A\u5F53\u524D\u6A21\u677F\u6761\u4EF6\u6846\u5185\u6570\u636E" }),
react_1.default.createElement("span", { className: 'tip' }, "\u5F53\u524D\u67E5\u8BE2\u6A21\u677F"),
react_1.default.createElement(antd_1.Select, { className: 'select', bordered: false, style: { width: 155 }, listHeight: 200, getPopupContainer: _this.props.env.getModalContainer, defaultActiveFirstOption: true, suffixIcon: defaultList.length > 0 ? react_1.default.createElement(icons_1.Icon, { symbol: true, icon: '#icon-tooltool_down', className: "icon" }) : null, open: defaultList.length === 0 ? false : undefined, value: defaultTempValue, onChange: function (value) {
var _a;
_this.setState({ defaultTempValue: value });
var item = defaultList.find(function (item) { return item.tempKey == value; });
if (item) {
_this.defaultAdvancedQuery(2, { tempName: item.tempName, tempKey: item.tempKey });
}
else {
(_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.resetDefaultQuery();
}
} }, defaultList.concat({ tempKey: 'defaultQuery', tempName: '默认查询' }).map(function (item) { return (react_1.default.createElement(antd_1.Select.Option, { value: item.tempKey, key: item.tempKey }, item.tempName)); }))),
react_1.default.createElement("div", { className: 'template-right' },
react_1.default.createElement(Button_1.default, { size: 'sm', onClick: function () {
var _a, _b;
var columnInfo = (_a = defaultList.find(function (item) { return item.tempKey == defaultTempValue; })) === null || _a === void 0 ? void 0 : _a.columnInfo;
(_b = _this.advanceFilterForm) === null || _b === void 0 ? void 0 : _b.clearAdvancedFilter(columnInfo);
} }, "\u91CD\u7F6E"),
react_1.default.createElement(Button_1.default, { size: 'sm', onClick: function () { var _a; (_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.clearDefaultQuery(); } }, "\u6E05\u7A7A"),
react_1.default.createElement(Button_1.default, { disabled: defaultTempValue === 'defaultQuery', size: 'sm', onClick: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var res;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.props.env.confirm('确认删除吗', '提示')];
case 1:
res = _a.sent();
if (res) {
this.defaultDelete(defaultList[0].tempKey);
}
return [2 /*return*/];
}
});
}); } }, "\u5220\u9664"),
react_1.default.createElement(Button_1.default, { size: 'sm', onClick: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var value;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.props.env.prompt('')];
case 1:
value = _a.sent();
if (value) {
this.defaultAdvancedQuery(2, { tempName: value.text, tempKey: (0, helper_1.uuid)() });
}
return [2 /*return*/];
}
});
}); } }, "\u53E6\u5B58\u4E3A"),
react_1.default.createElement(Button_1.default, { size: 'sm', level: "primary", disabled: defaultTempValue === 'defaultQuery', onClick: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var item;
return tslib_1.__generator(this, function (_a) {
item = defaultList.find(function (item) { return item.tempKey == defaultTempValue; });
if (item) {
this.defaultAdvancedQuery(2, { tempKey: item.tempKey, tempName: item.tempName }, true);
}
return [2 /*return*/];
});
}); } }, "\u4FDD\u5B58")))));
};
_this.renderAdvancedModalFooter = function () {
var _a = _this.state, defaultList = _a.defaultList, templateSwitch = _a.templateSwitch, filtertpl = _a.filtertpl;
return react_1.default.createElement("div", { className: 'defaultModal-footer' },
!(0, helper_1.isMobile)() && react_1.default.createElement("div", { className: 'defaultModal-footer-left' },
react_1.default.createElement(Button_1.default, { level: "primary", disabled: templateSwitch, onClick: function () {
_this.setState({
templateSwitch: true,
multipleDefault: '',
defaultTempKey: ''
});
} }, "+ \u65B0\u589E\u9ED8\u8BA4"),
templateSwitch ? react_1.default.createElement("div", { className: 'template-name' },
react_1.default.createElement(antd_1.Input, { placeholder: "\u8BF7\u8F93\u5165\u6A21\u7248\u540D\u79F0", onChange: function (e) { var _a; return _this.setState({ multipleDefault: (_a = e.target.value) !== null && _a !== void 0 ? _a : '' }); } }),
react_1.default.createElement(Button_1.default, { style: { margin: 0 }, onClick: function () {
_this.defaultOnOk();
_this.setState({ templateSwitch: false });
} },
react_1.default.createElement(icons_2.CheckOutlined, null)),
react_1.default.createElement(Button_1.default, { style: { margin: 0 }, onClick: function () {
var _a, _b;
_this.setState({
templateSwitch: false,
multipleDefault: (_a = defaultList === null || defaultList === void 0 ? void 0 : defaultList[0]) === null || _a === void 0 ? void 0 : _a.tempName,
defaultTempKey: (_b = defaultList === null || defaultList === void 0 ? void 0 : defaultList[0]) === null || _b === void 0 ? void 0 : _b.tempKey
});
} },
react_1.default.createElement(icons_2.CloseOutlined, null))) :
react_1.default.createElement("div", null, defaultList.length > 0 &&
react_1.default.createElement(antd_1.Select
// allowClear={true}
, {
// allowClear={true}
className: 'defaultModal-select-content', dropdownClassName: "dropdown-select-style", bordered: true, placeholder: '\u5168\u90E8', style: { textAlign: 'left' }, getPopupContainer: _this.props.env.getModalContainer, defaultActiveFirstOption: true, suffixIcon: react_1.default.createElement(icons_1.Icon, { symbol: true, icon: '#icon-tooltool_down', className: "icon" }),
// defaultValue={defaultList.length > 0 ? defaultList[0].tempName : ''}
value: defaultList.length > 0 ? defaultList[0].tempKey : '', onSelect: function (value) {
var item = defaultList.find(function (item) { return item.tempKey == value; });
_this.defaultTemplate(item.tempKey, item.tempName);
_this.defaultOnOk(item.tempName, item.tempKey);
}, onChange: function (value) {
if (defaultList[0].tempKey == value)
return;
var item = defaultList.find(function (item) { return item.tempKey == value; });
_this.defaultAdvancedQuery(2, { tempName: item.tempName, tempKey: item.tempKey });
} }, defaultList.map(function (item) { return (react_1.default.createElement(antd_1.Select.Option, { value: item.tempKey, key: item.tempKey, className: 'defaultModal-select-content-option' },
react_1.default.createElement("div", { className: 'defaultModal-select-content-option-tempName' }, item.tempName),
react_1.default.createElement("div", { className: 'defaultModal-select-content-option-click', onClick: function (e) { return e.stopPropagation(); } },
react_1.default.createElement(icons_2.EditOutlined, { onClick: function (e) { return _this.defaultModify(e, item.tempKey, item.tempName); } }),
react_1.default.createElement("div", null,
react_1.default.createElement(antd_1.Popconfirm, { title: "\u786E\u5B9A\u8981\u5220\u9664\u5417?", onConfirm: function () { return _this.defaultDelete(item.tempKey); }, okText: _this.props.translate('confirm'), cancelText: _this.props.translate('cancel') },
react_1.default.createElement(icons_2.DeleteOutlined, null)))))); })))),
react_1.default.createElement("div", { className: 'defaultModal-footer-right' },
_this.props.advancedFilterApi && react_1.default.createElement(react_1.default.Fragment, null,
// 2025-02 更新逻辑为 有默认模版列表则显示设置默认按钮
react_1.default.createElement("span", { style: { display: 'inline-block', marginRight: 10 } },
react_1.default.createElement(Button_1.default, { disabled: templateSwitch, level: "primary", onClick: function () {
(0, helper_1.isMobile)() && _this.setState({ defaultVisible: true });
!(0, helper_1.isMobile)() && defaultList.length > 0 && _this.defaultOnOk(false, false, true);
// this.defaultAdvancedQuery(2)
} }, _this.props.translate('default'))),
(0, helper_1.isMobile)() && defaultList.length > 0 ?
(react_1.default.createElement("span", { style: { display: 'inline-block', marginRight: 10 } },
react_1.default.createElement(Button_1.default, { className: 'default-select', onClick: function () {
// this.defaultAdvancedQuery(1)
defaultList.length > 0 && _this.setState({ selectTmpShow: true });
} },
react_1.default.createElement("div", { className: "text" },
" ",
_this.state.multipleDefault || _this.props.translate('application'),
" "),
react_1.default.createElement(icons_2.DownOutlined, null)))) : null),
react_1.default.createElement("span", { style: { display: 'inline-block', marginRight: 10 } },
react_1.default.createElement(Button_1.default, { onClick: function () {
var _a, _b;
(_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.resetAdvancedOptionsFilter();
(_b = _this.advanceFilterForm) === null || _b === void 0 ? void 0 : _b.resetAdvancedFilter();
} }, _this.props.translate('reset'))),
react_1.default.createElement(Button_1.default, { level: "primary", onClick: _this.handleAdvanceSearch }, _this.props.translate('confirm'))));
};
_this.handleTableRotate = function () {
var tableRotate = _this.state.tableRotate;
var classPrefix = _this.props.classPrefix;
_this.setState({ tableRotate: !tableRotate, toolChildMaxCount: undefined }, function () {
_this.calcToolActionsMaxCount();
if (tools_1.tools.isIOS) {
var crud = (0, react_dom_1.findDOMNode)(_this);
var container_1 = crud.querySelector(".".concat(classPrefix, "Table-content"));
setTimeout(function () {
var origin = container_1.scrollLeft;
container_1.scrollTo({ left: origin + 1 });
}, 800);
}
});
};
_this.clearSelectedItems = function () {
_this.props.store.setSelectedItems([]);
};
_this.getQueryStatus = function () {
return _this.state.queryStatus;
};
_this.handleAdvanced = function () {
var _a = _this.props, render = _a.render, __ = _a.translate, advancedFilter = _a.advancedFilter, columns = _a.columns, advancedQueryFields = _a.advancedQueryFields, filter = _a.filter, advancedFilterApi = _a.advancedFilterApi, store = _a.store, name = _a.name;
var _b = _this.state, advancedFilterVisible = _b.advancedFilterVisible, filterOptions = _b.filterOptions, filtertpl = _b.filtertpl, filtercont = _b.filtercont, queryStatus = _b.queryStatus;
// 使用缓存的普通查询参数
if ((0, helper_1.isMobile)() && (0, lodash_1.isArray)(filter === null || filter === void 0 ? void 0 : filter.body)) {
try {
var originConditionStr = localStorage.getItem('tableSearchCondition');
if (originConditionStr) {
var originCondition_1 = JSON.parse(originConditionStr);
if (originCondition_1[name]) {
filter.body.forEach(function (item) {
var fieldName = item.name.split('.')[1];
if (!(0, lodash_1.isNil)(originCondition_1[name].filterParam[fieldName])) {
item.value = originCondition_1[name].filterParam[fieldName];
}
});
}
}
}
catch (error) {
console.log(error);
}
}
return render(
//默认
'advancedFilter', tslib_1.__assign(tslib_1.__assign({ title: __('CRUD.filter'), submitText: __('search') }, _this.props.advancedFilter), { type: 'form', api: null }), {
key: 'advancedFilter',
onInit: _this.handleFilterInit,
formStore: undefined,
advancedFilterVisible: (0, helper_1.isMobile)() ? true : advancedFilterVisible,
advancedFilterApi: advancedFilterApi,
showAdvancedOption: _this.advancedMode == 'normal' || _this.advancedMode == 'popup-normal',
getFilterColumns: _this.getFilterColumns,
getAdvancedFilterForm: function (form) {
// 避免进行重复设置
if (!_this.advanceFilterForm)
_this.advanceFilterForm = form;
},
dialogContainer: _this.props.env.getTopModalContainer,
advancedFilter: advancedFilter,
filterOptions: filterOptions,
filtertpl: filtertpl,
filtercont: filtercont,
filter: filter,
columns: columns,
advancedQueryFields: advancedQueryFields,
handlePrefix: utils_2.handlePrefix,
handleSaveData: _this.handleSaveData,
hideAdvancedFilter: _this.hideAdvancedFilter,
handleActionDisplay: _this.handleActionDisplay,
handleAdvanceSearch: _this.handleAdvanceSearch,
handleFilterOptions: function (val) {
(0, helper_1.isMobile)() && _this.handleFilterOptions(val);
},
onReset: _this.handleFilterReset,
// 获取当前高级查询的状态(如果有未填项,将显示红点)
queryStatus: queryStatus,
});
};
//点击离线按钮,切换离线状态
_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.quickEditDataCheck = function () { };
// 注册检查数据预留的方法
_this.dataCheckRegist = function (fn) { return _this.quickEditDataCheck = fn; };
_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.getFilterForm = function (form) {
_this.filterForm = form;
};
_this.defaultOnOk = function (tempName, tempKey, senior) {
var _a = _this.state, multipleDefault = _a.multipleDefault, defaultTempKey = _a.defaultTempKey;
if (tempKey && tempName) {
var body = {
tempName: tempName,
tempKey: tempKey
};
_this.defaultAdvancedQuery(1, body);
_this.setState({ selectTmpShow: false });
}
else {
if (!!multipleDefault) {
var body = {};
if (defaultTempKey) {
body = {
tempName: multipleDefault,
tempKey: defaultTempKey
};
}
else {
body = {
tempName: multipleDefault,
tempKey: (0, helper_1.uuid)()
};
}
_this.defaultAdvancedQuery(2, body, senior);
_this.setState({
defaultVisible: false,
selectTmpShow: false,
multipleDefault: '',
defaultTempKey: ''
});
}
else {
antd_1.message.warning('请输入名称');
}
}
};
_this.defaultClose = function () {
_this.setState({ defaultVisible: false, multipleDefault: '' });
};
_this.defaultDelete = function (tempKey) {
_this.defaultAdvancedQuery(3, tempKey);
};
_this.defaultModify = function (e, tempKey, tempName) {
e.stopPropagation();
_this.setState({
defaultVisible: true,
multipleDefault: tempName,
defaultTempKey: tempKey
});
};
_this.defaultTemplate = function (tempKey, tempName) {
_this.setState({
multipleDefault: tempName,
defaultTempKey: tempKey,
defaultTempValue: tempKey
});
};
_this.state = {
// 移动端默认为true 或者这个表格没有自动列宽这个属性的话 也默认使用true -- 即进来就自动适用自动列宽计算逻辑
autoWidth: (0, helper_1.isMobile)() ? true : (!(0, lodash_1.isNil)((_a = (0, storage_1.getLocalStorage)('autoWidthPage')) === null || _a === void 0 ? void 0 : _a[_this.props.name || '']) ? (_b = (0, storage_1.getLocalStorage)('autoWidthPage')) === null || _b === void 0 ? void 0 : _b[_this.props.name || ''] : true),
printType: undefined,
flowModalVisible: false,
fingerModalVisible: false,
filterDrawerVisible: false,
showColumnsFilter: false,
mobileFilterShow: false,
hasFetch: false,
ModalProps: {
show: false,
onHide: null
},
filterData: {},
flowModalProps: {},
defaultVisible: false,
selectTmpShow: false,
defaultList: [],
defaultTempKey: '',
defaultTempValue: 'defaultQuery',
advancedFilterVisible: (!_this.props.initFetch && (props.advancedMode === 'popup-normal' || props.advancedMode === 'popup-condition')) ? true : false,
moreIsOpened: false,
foldColumns: [],
filtercont: {},
filterOptions: {},
multipleDefault: '',
filtertpl: [],
filterExist: false,
filData: {},
transferSubmission: {},
tableRotate: false,
offlineMode: false,
position: { x: document.body.clientWidth / 2 - 135, y: document.body.clientHeight - 200 },
openModle: {
open: false,
width: '65rem',
openModleBody: null,
linkTitle: '',
bodydata: null
},
codeVisible: false,
codeValue: '',
advancedFilterAction: false,
formSwitch: false,
templateSwitch: false,
modes: (props === null || props === void 0 ? void 0 : props.mode) || 'table',
toolActionSwitch: false,
staticExportShow: false,
staticExportRange: '0',
keepDataFormat: '1',
showFilterTimer: undefined,
};
_this.advancedMode = (_c = props.advancedMode) !== null && _c !== void 0 ? _c : 'normal';
_this.controlRef = _this.controlRef.bind(_this);
_this.handleFilterReset = _this.handleFilterReset.bind(_this);
_this.handleFilterSubmit = _this.handleFilterSubmit.bind(_this);
_this.handleFilterInit = _this.handleFilterInit.bind(_this);
_this.handleAction = _this.handleAction.bind(_this);
_this.handleBulkAction = _this.handleBulkAction.bind(_this);
_this.handleChangePage = _this.handleChangePage.bind(_this);
_this.handleFilterOptions = _this.handleFilterOptions.bind(_this);
_this.handleSaveData = _this.handleSaveData.bind(_this);
_this.handledelVisible = _this.handledelVisible.bind(_this);
_this.handleReset = _this.handleReset.bind(_this);
_this.handleBulkGo = _this.handleBulkGo.bind(_this);
_this.handleDialogConfirm = _this.handleDialogConfirm.bind(_this);
_this.handleDrawerConfirm = _this.handleDrawerConfirm.bind(_this);
_this.baseModalConfirm = _this.baseModalConfirm.bind(_this);
_this.handleDialogClose = _this.handleDialogClose.bind(_this);
_this.handleDrawerClose = _this.handleDrawerClose.bind(_this);
_this.handleBaseModalClose = _this.handleBaseModalClose.bind(_this);
_this.handleSave = _this.handleSave.bind(_this);
_this.handleSaveOrder = _this.handleSaveOrder.bind(_this);
_this.handleSelect = _this.handleSelect.bind(_this);
_this.handleChildPopOverOpen = _this.handleChildPopOverOpen.bind(_this);
_this.handleChildPopOverClose = _this.handleChildPopOverClose.bind(_this);
_this.search = _this.search.bind(_this);
_this.silentSearch = _this.silentSearch.bind(_this);
_this.afterSearchFn = _this.afterSearchFn.bind(_this);
_this.handleQuery = _this.handleQuery.bind(_this);
_this.setTotal = _this.setTotal.bind(_this);
_this.renderHeaderToolbar = _this.renderHeaderToolbar.bind(_this);
_this.renderFooterToolbar = _this.renderFooterToolbar.bind(_this);
/** 将renderToolbar方法传递给子组件,提供给移动端工具渲染定义的工具 */
_this.renderToolbar = _this.renderToolbar.bind(_this);
_this.clearSelection = _this.clearSelection.bind(_this);
//aug
_this.renderFilter = _this.renderFilter.bind(_this);
// Jay
_this.pageSwitchRef = react_1.default.createRef();
_this.toolActionsRef = react_1.default.createRef();
_this.handleFilterAdvanced = _this.handleFilterAdvanced.bind(_this);
_this.hideAdvancedFilter = _this.hideAdvancedFilter.bind(_this);
_this.handleActionDisplay = _this.handleActionDisplay.bind(_this);
_this.getTableInstance = _this.getTableInstance.bind(_this);
_this.getFilterColumns = _this.getFilterColumns.bind(_this);
_this.handleAdvanced = _this.handleAdvanced.bind(_this);
// 高级查询默认值
_this.defaultAdvancedQuery = _this.defaultAdvancedQuery.bind(_this);
_this.renderAggregate = _this.renderAggregate.bind(_this);
// this.renderDataQuery = this.renderDataQuery.bind(this);
// this.toggleShowFilter = this.toggleShowFilter.bind(this)
var location = props.location, store = props.store, pageField = props.pageField, perPageField = props.perPageField, syncLocation = props.syncLocation, loadDataOnce = props.loadDataOnce;
_this.mounted = true;
if (syncLocation && location && (location.query || location.search)) {
store.updateQuery((0, helper_1.qsparse)(location.search.substring(1)), undefined, pageField, perPageField);
}
else if (syncLocation && !location && window.location.search) {
store.updateQuery((0, helper_1.qsparse)(window.location.search.substring(1)), undefined, pageField, perPageField);
}
_this.props.store.setFilterTogglable(!!_this.props.filterTogglable, _this.props.filterDefaultVisible);
// 如果有 api,data 里面先写个 空数组,面得继承外层的 items
// 比如 crud 打开一个弹框,里面也是个 crud,默认一开始其实显示
// 的是外层 crud 的数据,等接口回来后就会变成新的。
// 加上这个就是为了解决这种情况
if (_this.props.api) {
_this.props.store.updateData({ items: [], itemsRaw: [] });
}
if (_this.props.isStatic) {
_this.props.store.initStaticData(_this.props.data, { page: 1, perPage: _this.props.perPage || 20 });
}
return _this;
}
CRUD.prototype.componentDidMount = function () {
var _a, _b, _c, _d, _e;
var store = this.props.store;
var _f = this.props, useMobileUI = _f.useMobileUI, name = _f.name;
var mobileUI = (0, helper_1.isMobile)() && useMobileUI;
if (mobileUI)
this.calcToolActionsMaxCount();
this.hasToolBars = !!((_b = (_a = this.crudRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.querySelector("[class*='headToolbar']"));
// 判断是否在小弹窗中
if (localStorage.getItem('g_user_lang') == 'en_US') {
(0, locale_1.setDefaultLocale)('en-US');
}
if (localStorage.getItem('g_user_lang') == 'zh_CN') {
(0, locale_1.setDefaultLocale)('zh-CN');
}
if (mobileUI && ((_e = (_d = (_c = this.advanceFilterForm) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.store) === null || _e === void 0 ? void 0 : _e.data)) {
var data = this.advanceFilterForm.props.store.data;
var existAdvancedFilterSub = Object.keys(this.dealAdvacedCondition(data === null || data === void 0 ? void 0 : data.advancedFilterSub) || {}).length;
var existAdvancedFilter = Object.keys(this.dealAdvacedCondition(data === null || data === void 0 ? void 0 : data.advancedFilter) || {}).length;
var existAdvancedHeader = Object.keys((data === null || data === void 0 ? void 0 : data.advancedHeader) || {}).length;
var existFilterParam = Object.keys((data === null || data === void 0 ? void 0 : data.filterParam) || {}).length;
var exist = existAdvancedFilter + existAdvancedHeader + existFilterParam + existAdvancedFilterSub;
if (exist > 0) {
this.setState({ filterExist: true, filtercont: (0, cloneDeep_1.default)(data) });
}
}
if (this.props.perPage) {
store.changePage(store.page, (0, helper_1.isMobile)() ? (this.props.perPage < 20 ? 20 : this.props.perPage) : this.props.perPage);
}
if ((!this.props.filter || (store.filterTogggable && !store.filterVisible)) || mobileUI) {
var filterParam = {};
if (!this.props.filter || (store.filterTogggable && !store.filterVisible)) {
filterParam = {};
}
else if (mobileUI) {
//解决移动端初始化没有携带普通查询的默认值
if (this.props.advancedMode !== 'popup-normal' && this.props.advancedMode !== 'popup-condition') {
filterParam = (0, utils_2.getInitParam)(this.props.translate, this.props.filter);
}
else {
filterParam = {};
}
}
this.handleFilterInit(filterParam, undefined, true);
}
var val;
if (this.props.pickerMode && (val = (0, helper_1.getPropValue)(this.props))) {
store.setSelectedItems(val);
}
if (mobileUI) {
// 移动端记录当前打开的crud的name,用于退出时清空搜索条件
var currentOpenCrudNameStr = sessionStorage.getItem('currentOpenCrudName');
if (currentOpenCrudNameStr) {
var currentOpenCrudName = JSON.parse(currentOpenCrudNameStr);
currentOpenCrudName.push(name);
sessionStorage.setItem('currentOpenCrudName', JSON.stringify(currentOpenCrudName));
}
else {
sessionStorage.setItem('currentOpenCrudName', JSON.stringify([name]));
}
}
};
CRUD.prototype.componentDidUpdate = function (prevProps, prevState) {
var _this = this;
var _a;
var props = this.props;
var store = prevProps.store;
this.filterData = store.filterData;
if ((0, helper_1.anyChanged)([
'toolbar',
'headerToolbar',
'footerToolbar',
'headerBulkActions',
'footerBulkActions'
], prevProps, props)) {
// 来点参数变化。
this.renderHeaderToolbar = this.renderHeaderToolbar.bind(this);
this.renderFooterToolbar = this.renderFooterToolbar.bind(this);
}
if ((0, helper_1.anyChanged)(['data'], prevProps, props) && props.itemAction) {
//itemAction中的某个字段在当前表格中不存在,会被赋值为undefined传到目标组件,导致目标组件获取不到该字段
var queryParam = (0, helper_1.createObject)(props.data, props.store.query, {}, true);
var TableData = (0, utils_2.getTableRowsData)(this.props.store, this.tableStore);
var ctx_1 = (0, helper_1.createObject)(queryParam, (TableData === null || TableData === void 0 ? void 0 : TableData[this.currentSelectedRow]) || (TableData === null || TableData === void 0 ? void 0 : TableData[0]), {}, true);
props.itemAction &&
((_a = props.data) === null || _a === void 0 ? void 0 : _a.items.length) &&
setTimeout(function () { return _this.handleAction(undefined, props.itemAction, ctx_1, undefined, undefined, true); }, 50);
}
var val;
if (this.props.pickerMode &&
(0, helper_1.isArrayChildrenModified)((val = (0, helper_1.getPropValue)(this.props)), (0, helper_1.getPropValue)(prevProps))) {
store.setSelectedItems(val);
}
if (this.props.filterTogglable !== prevProps.filterTogglable) {
store.setFilterTogglable(!!props.filterTogglable, props.filterDefaultVisible);
}
var dataInvalid = false;
if (prevProps.syncLocation &&
prevProps.location &&
prevProps.location.search !== props.location.search) {
// 同步地址栏,那么直接检测 query 是否变了,变了就重新拉数据
store.updateQuery((0, helper_1.qsparse)(props.location.search.substring(1)), undefined, props.pageField, props.perPageField);
dataInvalid = !!(props.api && (0, helper_1.isObjectShallowModified)(store.query, this.lastQuery, false));
}
if (dataInvalid) {
// 要同步数据
}
else if (prevProps.api &&
props.api &&
(0, api_1.isApiOutdated)(prevProps.api, props.api, store.fetchCtxOf(prevProps.data, {
pageField: prevProps.pageField,
perPageField: prevProps.perPageField
}), store.fetchCtxOf(props.data, {
pageField: props.pageField,
perPageField: props.perPageField
}))) {
dataInvalid = true;
}
else if (!props.api && (0, tpl_builtin_1.isPureVariable)(props.source)) {
var prev = (0, tpl_builtin_1.resolveVariableAndFilter)(prevProps.source, prevProps.data, '| raw');
var next = (0, tpl_builtin_1.resolveVariableAndFilter)(props.source, props.data, '| raw');
if (prev !== next) {
store.initFromScope(props.data, props.source);
}
}
if (dataInvalid && !this.sort) {
this.search();
}
this.sort = false;
};
CRUD.prototype.componentWillUnmount = function () {
this.mounted = false;
this.quickEditDataCheck = function () { return null; }; // 重置 防止发生相互引用
this.crudRef = null;
this.tableStore = null;
this.control = null;
delete this.tableInstance;
delete this.filterForm;
// 清空子store 清空缓存数据
this.props.store.clearChildStore();
this.props.store.clearCacheData();
clearTimeout(this.timer);
// 卸载的时候清除当前打开的crud名称
var currentOpenCrudNameStr = sessionStorage.getItem('currentOpenCrudName');
if (currentOpenCrudNameStr) {
var currentOpenCrudName = JSON.parse(currentOpenCrudNameStr);
currentOpenCrudName.pop();
sessionStorage.setItem('currentOpenCrudName', JSON.stringify(currentOpenCrudName));
}
};
CRUD.prototype.controlRef = function (control) {
// 因为 control 有可能被 n 层 hoc 包裹。
while (control && control.getWrappedInstance) {
control = control.getWrappedInstance();
}
this.control = control;
};
CRUD.prototype.handleAction = function (e, action, ctx, throwErrors, delegate, isItemAction) {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
if (throwErrors === void 0) { throwErrors = false; }
if (isItemAction === void 0) { isItemAction = false; }
var _t = this.props, onAction = _t.onAction, store = _t.store, messages = _t.messages, pickerMode = _t.pickerMode, env = _t.env, pageField = _t.pageField, stopAutoRefreshWhenModalIsOpen = _t.stopAutoRefreshWhenModalIsOpen, columns = _t.columns, data = _t.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.showModal();
return;
}
var actionType = action.actionType || '';
switch (true) {
case ['dialog', 'drawer'].includes(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_2.getTableRowsData)(this.props.store, this.tableStore);
var length = tableRows.length;
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
var openContanierFunction = ({
'dialog': store.openDialog,
'drawer': store.openDrawer,
})[actionType];
openContanierFunction(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);
}
}
break;
case actionType === 'advanced-filter':
this.handleFilterAdvanced();
break;
case 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();
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
_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 () { });
}
break;
case pickerMode && (actionType === 'confirm' || actionType === 'submit'):
{
store.setCurrentAction(action);
return Promise.resolve({ items: store.selectedItems.concat() });
}
break;
case !!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);
}
break;
case 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);
}
});
}
}
});
});
}
break;
case 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_2.getTableSelectedRowsData)(this.props.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 = this.dealAdvacedCondition((_g = this.state.filtercont) === null || _g === void 0 ? void 0 : _g.advancedFilter);
var advancedFilterSub = this.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;
}
break;
case actionType === 'loginAmazon':
{
store.setCurrentAction(action);
store.openAmazonLoginPage(ctx, env);
}
break;
case actionType === 'label-print' || actionType === 'bill-print' || 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_2.getTableSelectedRowsData)(this.props.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]) }), onHide: function () {
_this.setState({ printType: undefined });
} }),
printType: actionType.slice(0, actionType.indexOf('-'))
});
}
}
break;
case 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 });
}
});
}
}
break;
case 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_2.openImageEnlarge)(prints, baseURL, onImageEnlarge, env);
return [2 /*return*/];
});
}); })
.catch(function () { });
}
break;
case !!(actionType === null || actionType === void 0 ? void 0 : actionType.includes('scale')):
{
var foldColumns = this.state.foldColumns;
if (foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.includes(actionType)) {
var newFoldCols = foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.filter(function (col) { return col != actionType; });
this.setState({ foldColumns: newFoldCols });
}
else {
this.setState({ foldColumns: tslib_1.__spreadArray(tslib_1.__spreadArray([], foldColumns, true), [actionType], false) });
}
}
break;
default:
// 这个就是刷新对应action的方法
onAction(e, action, ctx, throwErrors, delegate || this.context, this.props.name, isItemAction);
}
};
CRUD.prototype.handleBulkAction = function (selectedItems, unSelectedItems, e, action, btn) {
var _this = this;
var _a = this.props, store = _a.store, primaryField = _a.primaryField, onAction = _a.onAction, messages = _a.messages, pageField = _a.pageField, stopAutoRefreshWhenModalIsOpen = _a.stopAutoRefreshWhenModalIsOpen, env = _a.env, fullDataApi = _a.fullDataApi, __ = _a.translate;
if (this.tableInstance.props.store.modified > 0) {
this.showModal();
return;
}
if (!selectedItems.length && action.requireSelected !== false) {
return;
}
var ids = selectedItems
.map(function (item) {
return item.hasOwnProperty(primaryField) ? item[primaryField] : null;
})
.filter(function (item) { return item; })
.join(',');
var ctx = (0, helper_1.createObject)(store.mergedData, tslib_1.__assign(tslib_1.__assign({}, selectedItems[0]), { rows: selectedItems, items: selectedItems, selectedItems: selectedItems, unSelectedItems: unSelectedItems, ids: ids }));
var fn = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var api, baseURL;
var _this = this;
var _a, _b;
return tslib_1.__generator(this, function (_c) {
if (action.actionType === 'batch-download') {
api = (0, api_1.buildApi)(action.api, ctx);
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);
api.url && (0, utils_1.downloadFile)((baseURL !== null && baseURL !== void 0 ? baseURL : '') + api.url, '');
}
else if ((action === null || action === void 0 ? void 0 : action.actionType) === 'dialog') {
return [2 /*return*/, this.handleAction(e, tslib_1.__assign(tslib_1.__assign({}, action), { __from: 'bulkAction' }), ctx)];
}
else if (action.actionType === 'ajax') {
(0, api_1.isEffectiveApi)(action.api, ctx) &&
store
.saveRemote(action.api, ctx, {
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;
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
data = (0, helper_1.createObject)(ctx, payload);
if (!(action.feedback && (0, helper_1.isVisible)(action.feedback, data))) return [3 /*break*/, 2];
return [4 /*yield*/, this.openFeedback(action.feedback, data)];
case 1:
_b.sent();
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
_b.label = 2;
case 2:
if (!((data === null || data === void 0 ? void 0 : data.status) === 20001)) return [3 /*break*/, 4];
return [4 /*yield*/, (0, ExpressPrint_1.expressLabels)(data, env.fetcher, this.props.translate)];
case 3:
_b.sent();
_b.label = 4;
case 4:
action.reload
? this.reloadTarget(action.reload, data)
: this.search((_a = {}, _a[pageField || 'page'] = 1, _a), undefined, true, true);
action.close && this.closeTarget(action.close);
redirect = action.redirect && (0, tpl_1.filter)(action.redirect, data);
redirect && env.jumpTo(redirect, action);
return [2 /*return*/];
}
});
}); })
.catch(function () { return null; });
}
// else if (onAction) {
// onAction(e, action, ctx, false, this.context);
// }
// Aug
else {
this.handleAction(e, action, ctx, false, this.context);
}
return [2 /*return*/, undefined];
});
}); };
var actionbut = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var data, confirmMsg, _a;
var _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!(btn && (btn === null || btn === void 0 ? void 0 : btn.openFullSelect) && (btn === null || btn === void 0 ? void 0 : btn.confirmApi))) return [3 /*break*/, 3];
data = (0, helper_1.createObject)(this.props.data, tslib_1.__assign(tslib_1.__assign({}, this.props.data), ctx));
ctx = data;
_a = (btn === null || btn === void 0 ? void 0 : btn.confirmApi);
if (!_a) return [3 /*break*/, 2];
return [4 /*yield*/, env.fetcher(btn === null || btn === void 0 ? void 0 : btn.confirmApi, data).catch(function () { })];
case 1:
_a = (_d.sent());
_d.label = 2;
case 2:
confirmMsg = _a;
if ((confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.status) === 10004 || (confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.status) === 10001 || (confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.status) === 1) {
env.notify('warning', confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.msg);
return [2 /*return*/];
}
else if ((confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.status) === 500) {
return [2 /*return*/];
}
else if ((confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.status) === 10003) {
env
.confirm((0, tpl_1.filter)((_c = (_b = confirmMsg === null || confirmMsg === void 0 ? void 0 : confirmMsg.data) === null || _b === void 0 ? void 0 : _b.showText) !== null && _c !== void 0 ? _c : '', ctx))
.then(function (confirmed) { return confirmed && fn(); });
return [2 /*return*/];
}
fn();
return [3 /*break*/, 4];
case 3:
if (action.confirmText && env.confirm) {
env
.confirm((0, tpl_1.filter)(action.confirmText, ctx))
.then(function (confirmed) { return confirmed && fn(); });
}
else
fn();
_d.label = 4;
case 4: return [2 /*return*/];
}
});
}); };
if (selectedItems.length && !unSelectedItems.length && btn && (btn === null || btn === void 0 ? void 0 : btn.openFullSelect) && fullDataApi) {
(0, BatchOperation_1.confirmWithThreeButtons)({ env: env, translate: __, }).then(function (result) {
if (result === 1)
actionbut();
else if (result === 2) {
var data = (0, helper_1.createObject)(store.mergedData, tslib_1.__assign(tslib_1.__assign({}, _this.state.filterData), { action_id: btn.name }));
env.fetcher(fullDataApi, data).then(function (res) {
var items = res.data;
var ids = res.data.map(function (item) { return Object.values(item)[0]; }).join(',');
ctx = tslib_1.__assign(tslib_1.__assign({}, ctx), { items: items, ids: ids });
actionbut();
});
}
});
}
else
actionbut();
};
CRUD.prototype.handleItemAction = function (action, ctx) {
this.doAction(action, ctx);
};
CRUD.prototype.handleFilterInit = function (values, isChild, init) {
var _a;
if (isChild === void 0) { isChild = false; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _b, defaultParams, data, store, _c, pickerMode, options;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
_b = this.props, defaultParams = _b.defaultParams, data = _b.data, store = _b.store;
if (!((_a = this.props) === null || _a === void 0 ? void 0 : _a.advancedFilterApi)) return [3 /*break*/, 2];
return [4 /*yield*/, this.defaultAdvancedQuery(1, undefined, undefined, init)];
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();
_c = this.props, pickerMode = _c.pickerMode, options = _c.options;
pickerMode &&
store.updateData({
items: options || []
});
return [2 /*return*/];
}
});
});
};
CRUD.prototype.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();
};
CRUD.prototype.handleFilterSubmit = function (values, jumpToFirstPage, replaceLocation, search, isChild, init) {
var _a, _b;
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 _c, store, syncLocation, env, pageField, perPageField, loadDataOnceFetchOnFilter, res, _d;
var _e;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
case 0:
_c = this.props, store = _c.store, syncLocation = _c.syncLocation, env = _c.env, pageField = _c.pageField, perPageField = _c.perPageField, loadDataOnceFetchOnFilter = _c.loadDataOnceFetchOnFilter;
if (!(!init && this.filterForm)) return [3 /*break*/, 4];
_f.label = 1;
case 1:
_f.trys.push([1, 3, , 4]);
return [4 /*yield*/, ((_b = (_a = this.filterForm) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.call(_a))];
case 2:
res = _f.sent();
if (!res) {
return [2 /*return*/, Promise.reject()];
}
;
return [3 /*break*/, 4];
case 3:
_d = _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), (_e = {}, _e[pageField || 'page'] = jumpToFirstPage ? 1 : store.page, _e)), 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*/];
}
});
});
};
// 点击高级查询按钮
CRUD.prototype.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 });
};
CRUD.prototype.hideAdvancedFilter = function () {
this.setState({ advancedFilterVisible: false });
};
CRUD.prototype.handleActionDisplay = function (val) {
switch (val) {
case '0':
this.setState({ advancedFilterAction: false });
break;
case '1':
case '2':
this.setState({ advancedFilterAction: true });
break;
default:
break;
}
};
// 获取普同查寻的数据
CRUD.prototype.handleFilterOptions = function (value) {
this.setState({ filterOptions: value });
};
CRUD.prototype.handleSaveData = function (val, cont) {
if (val.includes('advancedFilter')) {
var name = val.split('.');
if (name[name.length - 1].includes('--')) {
if (!!this.saveData.set(name[name.length - 1].split('--')[0], cont)) {
this.saveData.set(name[name.length - 1].split('--')[0], cont);
}
}
else
this.saveData.set(name[name.length - 1], cont);
}
else {
this.saveData.set(val, cont);
}
};
// 查询1
// selectApi
// 修改2
// modifyApi
// 删除3
// deleteApi
CRUD.prototype.defaultAdvancedQuery = function (val, body, senior, init) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
if (val === void 0) { val = 1 | 2 | 3; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _u, env, name, _v, selectApi, modifyApi, deleteApi, _w, defaultTempKey, defaultList, filter_2, list, data, api, res, body_1, originAdvancedFilterData, originConditionStr, originCondition, originConditionStr, originCondition, options, filterBody, filters_1, defaultBody, data, api, queryParams, rawShowFields, optionsParam, newAdvancedFilter, url, columnInfo, data, msg, res, api, url, res, _x;
var _this = this;
return tslib_1.__generator(this, function (_y) {
switch (_y.label) {
case 0:
_u = this.props, env = _u.env, name = _u.name, _v = _u.advancedFilterApi, selectApi = _v.selectApi, modifyApi = _v.modifyApi, deleteApi = _v.deleteApi;
_w = this.state, defaultTempKey = _w.defaultTempKey, defaultList = _w.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_2 = 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_2),
multipleDefault: list.tempName,
defaultTempKey: list.tempKey
}, function () { _this.handlefilters(); });
if (this.advancedMode == 'condition' || this.advancedMode == 'popup-condition') {
filter_2.optionsParam = undefined;
}
data = (0, utils_2.handlePrefix)(filter_2, this.props.advancedQueryFields, this.props.advancedFilter);
(_a = this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.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;
originAdvancedFilterData = void 0;
try {
if ((0, helper_1.isMobile)()) {
if (init) {
originConditionStr = localStorage.getItem('tableSearchCondition');
if (originConditionStr) {
originCondition = JSON.parse(originConditionStr);
if (originCondition[name]) {
originAdvancedFilterData = originCondition[name];
}
}
}
else {
originConditionStr = localStorage.getItem('tableSearchCondition');
if (originConditionStr) {
originCondition = JSON.parse(originConditionStr);
if (originCondition[name]) {
delete originCondition[name];
localStorage.setItem('tableSearchCondition', JSON.stringify(originCondition));
}
}
}
}
}
catch (error) {
console.log(error);
}
if (Array.isArray(body_1)) {
filter_2 = (0, cloneDeep_1.default)(originAdvancedFilterData || body_1[0].columnInfo);
options = filter_2.optionsParam;
//过滤掉不存在的字段
if (Array.isArray(filter_2.advancedFilter)) {
filterBody = (_b = this.props.advancedFilter) === null || _b === void 0 ? void 0 : _b.body;
filterBody = Array.isArray(filterBody) ? filterBody : filterBody ? [filterBody] : [];
filters_1 = (_c = filterBody.find(function (item) { return item.name === 'advancedFilter'; })) === null || _c === void 0 ? void 0 : _c.body;
filter_2.advancedFilter = filter_2.advancedFilter.filter(function (item) {
var isInside = !!filters_1.find(function (col) { return col.name === "advancedFilter.".concat(item.field); });
return isInside;
});
filter_2.advancedFilterSub = filter_2.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_2.optionsParam = undefined;
}
else if (options) {
if (options.itemCount === false && options.itemRepeat === false && options.itemSumCount === false && options.section === false &&
((_d = options.showFields) === null || _d === void 0 ? void 0 : _d.length) === 0 && ((_e = options.sortFields) === null || _e === void 0 ? void 0 : _e.length) === 0 && ((_f = options.groupByFields) === null || _f === void 0 ? void 0 : _f.length) === 0) {
filter_2.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: (_g = body_1[0].tempKey) !== null && _g !== void 0 ? _g : 'defaultQuery'
});
}
else {
if ((_h = res.data) === null || _h === void 0 ? void 0 : _h.columnInfo) {
filter_2 = (0, cloneDeep_1.default)(originAdvancedFilterData || res.data.columnInfo);
}
else {
filter_2 = (0, cloneDeep_1.default)(res.data);
this.setState({ defaultList: [] });
}
if (this.advancedMode == 'condition' || this.advancedMode == 'popup-condition') {
filter_2.optionsParam = undefined;
}
this.setState({ defaultList: [{ columnInfo: filter_2, tempKey: (_k = (_j = res.data) === null || _j === void 0 ? void 0 : _j.tempKey) !== null && _k !== void 0 ? _k : (0, helper_1.uuid)(), tempName: (_m = (_l = res.data) === null || _l === void 0 ? void 0 : _l.tempName) !== null && _m !== void 0 ? _m : '默认设置' }] });
}
// const filter = cloneDeep(res.data.columnInfo)
this.setState({ filtercont: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, this.state.filtercont), filter_2), { optionsParam: filter_2.optionsParam }) }, function () {
_this.handlefilters();
});
data = (0, utils_2.handlePrefix)(filter_2, this.props.advancedQueryFields, this.props.advancedFilter);
(_o = this.advanceFilterForm) === null || _o === void 0 ? void 0 : _o.handleFiltersArr(data);
}
else {
this.setState({ defaultTempValue: 'defaultQuery' }, (_p = this.advanceFilterForm) === null || _p === void 0 ? void 0 : _p.resetDefaultQuery());
}
_y.label = 4;
case 4: return [3 /*break*/, 12];
case 5:
if (!(val == 2)) return [3 /*break*/, 10];
api = modifyApi;
if (!api)
return [2 /*return*/, true];
queryParams = (_q = this.advanceFilterForm) === null || _q === void 0 ? void 0 : _q.confirmAdvancedFilter(true);
rawShowFields = (_r = queryParams === null || queryParams === void 0 ? void 0 : queryParams.filterOptionData) === null || _r === void 0 ? void 0 : _r.rawShowFields;
optionsParam = (_s = queryParams === null || queryParams === void 0 ? void 0 : queryParams.filterOptionData) === null || _s === void 0 ? void 0 : _s.optionsParam;
if ((rawShowFields === null || rawShowFields === void 0 ? void 0 : rawShowFields.length) == 0) {
antd_1.message.warning('显示字段不能为空');
return [2 /*return*/, true];
}
queryParams.optionsParam = optionsParam;
//初始化的时候,高级查询中的select取不到对应的label,所以传给后端,保存起来
if (((_t = queryParams.advancedFilter) === null || _t === void 0 ? void 0 : _t.length) > 0) {
newAdvancedFilter = queryParams.advancedFilter.map(function (filterItem) {
var _a, _b, _c;
var optionsData = _this.saveData.get(filterItem.field);
var data = filterItem.values;
if (optionsData && (optionsData === null || optionsData === void 0 ? void 0 : optionsData.length) > 0) {
if (typeof (filterItem === null || filterItem === void 0 ? void 0 : filterItem.values) == 'string' && ((_a = filterItem === null || filterItem === void 0 ? void 0 : filterItem.values) === null || _a === void 0 ? void 0 : _a.indexOf(',')) !== -1) {
data = (_b = filterItem.values.split(',').map(function (name_item) { var _a; return (_a = (0, helper_1.findTree)(optionsData, function (current) { return current.value == name_item; })) === null || _a === void 0 ? void 0 : _a.label; })) === null || _b === void 0 ? void 0 : _b.join(',');
}
else {
data = (_c = (0, helper_1.findTree)(optionsData, function (item) { return item.value == filterItem.values; })) === null || _c === void 0 ? void 0 : _c.label;
}
}
return tslib_1.__assign(tslib_1.__assign({}, filterItem), { valuesAlia: data });
});
queryParams.advancedFilter = newAdvancedFilter;
}
if (!body) return [3 /*break*/, 7];
url = {
method: "post",
url: (api === null || api === void 0 ? void 0 : api.url) || '',
data: {
tempName: "${tempName |default:undefined}",
tempKey: "${tempKey |default:undefined}",
columnInfo: {
advancedFilter: "${advancedFilter |default:undefined}",
advancedFilterSub: "${advancedFilterSub |default:undefined}",
advancedHeader: "${advancedHeader |default:undefined}",
optionsParam: "${optionsParam |default:undefined}",
limitParam: "${limitParam |default:undefined}"
}
}
};
columnInfo = void 0;
data = void 0;
if (!senior && defaultList.length > 0 && !!defaultList.find(function (item) { return body.tempKey == item.tempKey; })) {
columnInfo = defaultList.find(function (item) { return body.tempKey == item.tempKey; }).columnInfo;
}
else if (senior) {
columnInfo = queryParams;
}
if (!!defaultTempKey && columnInfo) {
data = tslib_1.__assign(tslib_1.__assign({}, body), columnInfo);
}
else if (columnInfo) {
data = tslib_1.__assign(tslib_1.__assign({}, body), columnInfo);
}
else {
data = tslib_1.__assign(tslib_1.__assign({}, body), queryParams);
}
return [4 /*yield*/, env.fetcher(url, data)];
case 6:
msg = (_y.sent()).msg;
antd_1.message.info(msg);
this.defaultAdvancedQuery(1);
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, env.fetcher(api, queryParams)];
case 8:
res = _y.sent();
if (res.status == 0) {
antd_1.message.success(res.msg);
}
this.defaultAdvancedQuery(1);
_y.label = 9;
case 9: return [3 /*break*/, 12];
case 10:
if (!(val == 3)) return [3 /*break*/, 12];
api = deleteApi;
if (!api)
return [2 /*return*/, true];
url = { method: api.method, url: api.url + '&tempKey=' + body || '', };
return [4 /*yield*/, env.fetcher(url, { tempKey: body })];
case 11:
res = _y.sent();
if (res.status == 0) {
antd_1.message.success(res.msg);
this.setState({ defaultList: defaultList.filter(function (item) { return item.tempKey !== body; }) }, function () {
var list = defaultList.filter(function (item) { return item.tempKey !== body; });
if (list.length == 0) {
_this.setState({ selectTmpShow: false });
}
});
}
this.defaultAdvancedQuery(1);
_y.label = 12;
case 12: return [2 /*return*/, true];
case 13:
_x = _y.sent();
return [2 /*return*/, true];
case 14: return [2 /*return*/];
}
});
});
};
// 判断是否有高级查询的数据将基础查询重置
CRUD.prototype.handleReset = function () {
var filtercont = (0, cloneDeep_1.default)(this.state.filtercont);
if (Object.keys(filtercont).length) {
filtercont.filterParam = (0, cloneDeep_1.default)(this.state.filterOptions.filterParam);
this.setState({ filtercont: filtercont });
}
};
// 删除高级查询条件
CRUD.prototype.handledelVisible = function (value, whole, e, delIndex) {
var _this = this;
var _a, _b, _c, _d, _e;
if (whole === void 0) { whole = false; }
e === null || e === void 0 ? void 0 : e.preventDefault();
var filtercont = (0, cloneDeep_1.default)(this.state.filtercont);
filtercont.filterParam = (0, cloneDeep_1.default)(this.state.filterOptions.filterParam);
if (whole) {
filtercont.advancedFilter = [];
filtercont.advancedFilterSub = [];
filtercont.advancedHeader = {};
(_b = (_a = this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.handlerenew) === null || _b === void 0 ? void 0 : _b.call(_a, whole);
}
else {
var head = value.name.split('.')[0];
var name_1 = value.name.split('.')[1];
if (head.includes('advancedFilter') || head.includes('advancedFilterSub')) {
var newList = tslib_1.__spreadArray([], filtercont[head], true);
if (delIndex !== undefined) {
newList.splice(delIndex, 1);
}
else {
newList = filtercont[head].filter(function (item) { return item.field != name_1; });
}
filtercont[head] = newList;
}
else {
var replacement = {};
for (var key in filtercont[head]) {
if (key !== name_1) {
replacement[key] = (_c = filtercont[head]) === null || _c === void 0 ? void 0 : _c[key];
}
}
filtercont[head] = replacement;
}
(_e = (_d = this.advanceFilterForm) === null || _d === void 0 ? void 0 : _d.handlerenew) === null || _e === void 0 ? void 0 : _e.call(_d, whole, value.name, value.keyName);
}
this.setState({
filtercont: filtercont
}, function () {
_this.handlefilters();
});
};
// 高级查询内容展示
CRUD.prototype.handlefilters = function () {
var _this = this;
var _a = this.props, advancedFilter = _a.advancedFilter, advancedQueryFields = _a.advancedQueryFields;
var filtercont = this.state.filtercont;
if (!advancedFilter)
return;
var body = advancedFilter.body;
var filters = Array.isArray(body) ? body : body ? [body] : [];
var _b = filtercont || {}, advancedFilterCont = _b.advancedFilter, advancedFilterSub = _b.advancedFilterSub;
var allAdvancedFilters = tslib_1.__spreadArray(tslib_1.__spreadArray([], (advancedFilterCont || []), true), (advancedFilterSub || []), true);
var dateLineItem = allAdvancedFilters.find(function (filItem) { return filItem.dateLine; });
var filtertpl = allAdvancedFilters.reduce(function (result, value, currentIndex) {
filters.forEach(function (item) {
if (item.name.includes('advancedFilter')) {
item.body.forEach(function (items) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var long = items.name.split('.');
if (long[long.length - 1] === value.field) {
var currentValue_1 = _this.saveData.get(value.field);
var data = null;
if (currentValue_1) {
if (typeof (value === null || value === void 0 ? void 0 : value.values) == 'string' && ((_a = value === null || value === void 0 ? void 0 : value.values) === null || _a === void 0 ? void 0 : _a.indexOf((_b = value === null || value === void 0 ? void 0 : value.delimiter) !== null && _b !== void 0 ? _b : ',')) > -1) {
data = value.values.split((_c = value === null || value === void 0 ? void 0 : value.delimiter) !== null && _c !== void 0 ? _c : ',').map(function (name_item) {
var _a, _b;
if (value.op == 12) {
var newArray = (0, utils_2.handleSelectStructure)(currentValue_1);
return (_a = newArray.find(function (current) { return current.value == name_item; })) === null || _a === void 0 ? void 0 : _a.label;
}
return (_b = (0, helper_1.findTree)(currentValue_1, (function (current) { return current.value == name_item; }))) === null || _b === void 0 ? void 0 : _b.label;
});
}
else {
data = (_d = (0, helper_1.findTree)(currentValue_1, (function (current) { return current.value == value.values; }))) === null || _d === void 0 ? void 0 : _d.label;
}
}
var dateList = item.body.filter(function (filterItem) { return filterItem.type && ['input-date', 'input-datetime', 'input-time', 'input-month', 'input-quarter', 'input-year'].includes(filterItem.type); });
if (advancedQueryFields) {
dateList = dateList.filter(function (info) { var _a; return advancedQueryFields.includes((_a = info.name.split('.')) === null || _a === void 0 ? void 0 : _a[1]); });
}
var cop = {};
if ((_g = (_f = (_e = _this.advanceFilterForm) === null || _e === void 0 ? void 0 : _e.state) === null || _f === void 0 ? void 0 : _f.filtersArr) === null || _g === void 0 ? void 0 : _g.length) {
cop.keyName = ((_k = (_j = (_h = _this.advanceFilterForm) === null || _h === void 0 ? void 0 : _h.state) === null || _j === void 0 ? void 0 : _j.filtersArr[!dateList.length || dateLineItem ? currentIndex : currentIndex + 1]) === null || _k === void 0 ? void 0 : _k.field) || 'advancedFilter.' + value.field;
}
else {
var repeatNum = result.filter(function (resItem) { return resItem.name === 'advancedFilter.' + value.field; }).length + (dateList.length && !dateLineItem && dateList[0].name === 'advancedFilter.' + value.field ? 1 : 0);
var keyName = 'advancedFilter.' + value.field + (repeatNum > 0 ? "--".concat(repeatNum) : '');
cop.keyName = keyName;
}
cop.value = data ? typeof data === 'object' ? data.join(',') : data : value.values;
cop.label = (items === null || items === void 0 ? void 0 : items.label) || (items === null || items === void 0 ? void 0 : items.placeholder);
cop.name = items.name;
if (value.valuesAlia) {
cop.valuesAlia = value.valuesAlia;
}
switch (value.op) {
case 2:
if (cop.value) {
if (value.not) {
cop.value = "![".concat(cop.value, "]");
}
else {
cop.value = "[".concat(cop.value, "]");
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "![".concat(cop.valuesAlia, "]");
}
else {
cop.valuesAlia = "[".concat(cop.valuesAlia, "]");
}
}
break;
case 3:
if (cop.value) {
if (value.not) {
cop.value = "!\uFF08".concat(cop.value, "\uFF0C\u221E)");
}
else {
cop.value = "\uFF08".concat(cop.value, "\uFF0C\u221E)");
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "!\uFF08".concat(cop.valuesAlia, "\uFF0C\u221E)");
}
else {
cop.valuesAlia = "\uFF08".concat(cop.valuesAlia, "\uFF0C\u221E)");
}
}
break;
case 4:
if (cop.value) {
if (value.not) {
cop.value = "![".concat(cop.value, "\uFF0C\u221E)");
}
else {
cop.value = "[".concat(cop.value, "\uFF0C\u221E)");
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "![".concat(cop.valuesAlia, "\uFF0C\u221E)");
}
else {
cop.valuesAlia = "[".concat(cop.valuesAlia, "\uFF0C\u221E)");
}
}
break;
case 5:
if (cop.value) {
if (value.not) {
cop.value = "!\uFF08-\u221E,".concat(cop.value, "\uFF09");
}
else {
cop.value = "\uFF08-\u221E,".concat(cop.value, "\uFF09");
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "!\uFF08-\u221E,".concat(cop.valuesAlia, "\uFF09");
}
else {
cop.valuesAlia = "\uFF08-\u221E,".concat(cop.valuesAlia, "\uFF09");
}
}
break;
case 6:
if (cop.value) {
if (value.not) {
cop.value = "!\uFF08-\u221E,".concat(cop.value, "]");
}
else {
cop.value = "\uFF08-\u221E,".concat(cop.value, "]");
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "!\uFF08-\u221E,".concat(cop.valuesAlia, "]");
}
else {
cop.valuesAlia = "\uFF08-\u221E,".concat(cop.valuesAlia, "]");
}
}
break;
case 7:
if (value.values) {
cop.value = "[".concat(value.values, "]");
cop.valuesAlia = "[".concat(value.values, "]");
}
break;
case 9:
if (cop.value) {
if (value.not) {
cop.value = "!".concat(cop.value);
}
else
cop.value = "".concat(cop.value);
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "!".concat(cop.valuesAlia);
}
else
cop.valuesAlia = "".concat(cop.valuesAlia);
}
break;
case 10:
if (value.not) {
cop.value = '[不为空]';
}
else {
cop.value = '[为空]';
}
break;
case 12:
if (cop.value) {
if (value.not) {
cop.value = "!\u5C5E\u4E8E\u6807\u7B7E ".concat(cop.value);
}
else {
cop.value = "\u5C5E\u4E8E\u6807\u7B7E ".concat(cop.value);
}
}
if (value.valuesAlia) {
if (value.not) {
cop.valuesAlia = "!\u5C5E\u4E8E\u6807\u7B7E".concat(cop.valuesAlia);
}
else {
cop.valuesAlia = "\u5C5E\u4E8E\u6807\u7B7E".concat(cop.valuesAlia);
}
}
break;
default:
break;
}
if (!_this.advancefilterValueIsLegalEmptyValue(value)) {
// 加一个在高级查询中的位置 方便移除
result.push(tslib_1.__assign(tslib_1.__assign({}, cop), { advancedFilterIndex: currentIndex }));
}
}
});
}
});
return result;
}, []);
var advancedHeader = (filtercont || {}).advancedHeader;
if (advancedHeader && Object.keys(advancedHeader).length) {
Object.keys(advancedHeader).forEach(function (key) {
filters.forEach(function (item) {
if (item.name === 'advancedHeader') {
item.body.forEach(function (items) {
if (items === null || items === void 0 ? void 0 : items.body) {
items.body.forEach(function (it) {
var long = it.name.split('.');
if (long[long.length - 1] === key) {
var currentValue = _this.saveData.get(it.name);
var cop = {};
if (currentValue) {
var currentLabel = currentValue.find(function (opp) { return opp.value === advancedHeader[key]; });
cop.labelName = currentLabel === null || currentLabel === void 0 ? void 0 : currentLabel.label;
}
cop.value = advancedHeader[key];
cop.label = it.label || it.placeholder;
cop.name = it.name;
filtertpl.push(cop);
}
});
}
else {
var long = items.name.split('.');
if (long[long.length - 1] === key) {
var currentValue = _this.saveData.get(items.name);
var cop = {};
if (currentValue) {
var currentLabel = currentValue.find(function (opp) { return opp.value === advancedHeader[key]; });
cop.labelName = currentLabel === null || currentLabel === void 0 ? void 0 : currentLabel.label;
}
cop.value = advancedHeader[key];
cop.label = items.label || items.placeholder;
cop.name = items.name;
filtertpl.push(cop);
}
}
});
}
});
});
}
this.setState({ filtertpl: filtertpl });
};
CRUD.prototype.handleBulkGo = function (selectedItems, unSelectedItems, e) {
var _this = this;
var action = this.props.store.selectedAction;
var env = this.props.env;
if (action.confirmText) {
return env
.confirm(action.confirmText)
.then(function (confirmed) {
return confirmed &&
_this.handleBulkAction(selectedItems, unSelectedItems, e, action);
});
}
return this.handleBulkAction(selectedItems, unSelectedItems, e, action);
};
CRUD.prototype.showModal = 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')
});
};
CRUD.prototype.baseModalConfirm = function (type) {
var _this = this;
return function (values, action, ctx, components) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, store, pageField, stopAutoRefreshWhenModalIsOpen, interval, silentPolling, env, tableRows, dialogAction, count, count, value, component, reload_1, reload, redirect;
var _b;
var _this = this;
var _c, _d, _e;
return tslib_1.__generator(this, function (_f) {
_a = this.props, store = _a.store, pageField = _a.pageField, stopAutoRefreshWhenModalIsOpen = _a.stopAutoRefreshWhenModalIsOpen, interval = _a.interval, silentPolling = _a.silentPolling, env = _a.env;
// Jay 下一个、上一个不用关闭
if (!['next', 'prev'].includes(action.actionType || '')) {
switch (type) {
case 'drawer':
default:
store.closeDrawer(true);
break;
case 'dialog':
store.closeDialog(true);
break;
}
}
tableRows = (0, utils_2.getTableRowsData)(this.props.store, this.tableStore);
dialogAction = store.action;
// 自动聚焦第一个搜索栏,释放内存
(0, helper_1.functionInOneFrame)(function () { var _a, _b, _c; return (_c = (_b = (_a = _this.crudRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.querySelector('input[type="text"]')) === null || _c === void 0 ? void 0 : _c.focus(); });
if (stopAutoRefreshWhenModalIsOpen && interval) {
this.timer = setTimeout(silentPolling ? this.silentSearch : this.search, Math.max(interval, 1000));
}
if (action.actionType === 'next' &&
typeof ctx.nextIndex === 'number' &&
tableRows[ctx.nextIndex]) {
if (this.tableInstance) {
count = this.tableInstance.props.store.modified;
if (count > 0) {
this.showModal();
return [2 /*return*/];
}
}
return [2 /*return*/, this.handleAction(undefined, tslib_1.__assign({}, dialogAction), (0, helper_1.createObject)((0, helper_1.createObject)(store.data, {
index: ctx.nextIndex
// Jay
// initApiDisable: 0
}), tableRows[ctx.nextIndex]))];
}
else if (action.actionType === 'prev' &&
typeof ctx.prevIndex === 'number' &&
tableRows[ctx.prevIndex]) {
if (this.tableInstance) {
count = this.tableInstance.props.store.modified;
if (count > 0) {
this.showModal();
return [2 /*return*/];
}
}
return [2 /*return*/, this.handleAction(undefined, tslib_1.__assign({}, dialogAction), (0, helper_1.createObject)((0, helper_1.createObject)(store.data, {
index: ctx.prevIndex
// Jay
// initApiDisable: 0
}), tableRows[ctx.prevIndex]))];
}
else if (values.length) {
value = values[0];
ctx = (0, helper_1.createObject)(ctx, value);
component = components[0];
// 提交来自 form
if (component && component.props.type === 'form') {
// 数据保存了,说明列表数据已经无效了,重新刷新。
if (value && value.__saved) {
reload_1 = (_c = action.reload) !== null && _c !== void 0 ? _c : dialogAction.reload;
// 配置了 reload 则跳过自动更新。
reload_1 ||
this.search(dialogAction.__from ? (_b = {}, _b[pageField || 'page'] = 1, _b) : undefined, undefined, true, true, this.afterSearchFn);
}
else if (value &&
((value.hasOwnProperty('items') && value.items) ||
value.hasOwnProperty('ids')) &&
this.control.bulkUpdate) {
this.control.bulkUpdate(value, value.items);
}
}
}
reload = (_d = action.reload) !== null && _d !== void 0 ? _d : dialogAction.reload;
if (reload) {
this.reloadTarget(reload, ctx);
}
redirect = (_e = action.redirect) !== null && _e !== void 0 ? _e : dialogAction.redirect;
redirect = redirect && (0, tpl_1.filter)(redirect, ctx);
redirect && env.jumpTo(redirect, dialogAction);
return [2 /*return*/];
});
}); };
};
CRUD.prototype.handleDialogConfirm = function (values, action, ctx, components) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.baseModalConfirm('dialog')(values, action, ctx, components)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
CRUD.prototype.handleDrawerConfirm = function (values, action, ctx, components) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.baseModalConfirm('drawer')(values, action, ctx, components)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
CRUD.prototype.handleBaseModalClose = function (type) {
var _this = this;
return function (confirmed, formInstance, tableInstance) {
// 自动聚焦第一个搜索栏,释放内存
(0, helper_1.functionInOneFrame)(function () { var _a, _b, _c; return (_c = (_b = (_a = _this.crudRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.querySelector('input[type="text"]')) === null || _c === void 0 ? void 0 : _c.focus(); });
var _a = _this.props, __ = _a.translate, env = _a.env;
if (tableInstance) {
var count = tableInstance.props.store.modified;
if (count > 0) {
_this.showModal();
return;
}
}
// Jay
if (formInstance) {
var promptPageLeave = formInstance.props.promptPageLeave;
if (promptPageLeave && formInstance.is_edit) {
antd_1.Modal.confirm({
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'),
cancelText: __('cancel'),
onOk: function () { return _this.closeModal(type); },
className: 'ant-modal-adaptation-style'
});
return;
}
}
_this.closeModal(type);
};
};
CRUD.prototype.handleDialogClose = function (confirmed, formInstance, tableInstance) {
return this.handleBaseModalClose('dialog')(confirmed, formInstance, tableInstance);
};
CRUD.prototype.handleDrawerClose = function (confirmed, formInstance, tableInstance) {
return this.handleBaseModalClose('drawer')(confirmed, formInstance, tableInstance);
};
CRUD.prototype.closeModal = function (type) {
if (type === void 0) { type = 'dialog'; }
var _a = this.props, store = _a.store, stopAutoRefreshWhenModalIsOpen = _a.stopAutoRefreshWhenModalIsOpen, silentPolling = _a.silentPolling, interval = _a.interval;
switch (type) {
case 'dialog':
store.closeDialog();
break;
case 'drawer':
store.closeDrawer();
break;
}
if (stopAutoRefreshWhenModalIsOpen && interval) {
this.timer = setTimeout(silentPolling ? this.silentSearch : this.search, Math.max(interval, 1000));
}
};
CRUD.prototype.openFeedback = function (dialog, ctx) {
var _this = this;
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);
});
});
};
CRUD.prototype.search = function (values, silent, clearSelection, forceReload, resolve, reject, isChild, postData, // Jay
init) {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g, _h;
if (forceReload === void 0) { forceReload = false; }
var _j = this.props, store = _j.store, api = _j.api, messages = _j.messages, pageField = _j.pageField, perPageField = _j.perPageField, interval = _j.interval, stopAutoRefreshWhen = _j.stopAutoRefreshWhen, stopAutoRefreshWhenModalIsOpen = _j.stopAutoRefreshWhenModalIsOpen, silentPolling = _j.silentPolling, syncLocation = _j.syncLocation, syncResponse2Query = _j.syncResponse2Query, keepItemSelectionOnPageChange = _j.keepItemSelectionOnPageChange, pickerMode = _j.pickerMode, env = _j.env, loadDataOnce = _j.loadDataOnce, loadDataOnceFetchOnFilter = _j.loadDataOnceFetchOnFilter, source = _j.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.timer);
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 = getInitParam(this.props.translate, this.props.filter)
// if (Object.keys(data.filterParam)) {
// data.filterParam = this.state.filtercont?.filterParam
// }
// } else {
// data.filterParam = this.state.filtercont?.filterParam
// }
data.filterParam = (_g = this.state.filtercont) === null || _g === void 0 ? void 0 : _g.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 = this.dealAdvacedCondition(data.advancedFilterSub);
}
if (data.advancedFilter) {
data.advancedFilter = this.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));
// 清空子表格的列表宽度
(_h = this.tableStore) === null || _h === void 0 ? void 0 : _h.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 &&
(!stopAutoRefreshWhen ||
!((stopAutoRefreshWhenModalIsOpen && store.hasModalOpened) ||
(0, tpl_1.evalExpression)(stopAutoRefreshWhen, data))) &&
(_this.timer = setTimeout(silentPolling
? _this.silentSearch.bind(_this, undefined, undefined, true)
: _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;
}
};
CRUD.prototype.silentSearch = function (values, clearSelection, forceReload) {
if (forceReload === void 0) { forceReload = false; }
return this.search(values, true, clearSelection, forceReload);
};
CRUD.prototype.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);
};
CRUD.prototype.handleChangePage = function (page, perPage) {
var _a, _b, _c, _d;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _e, store, syncLocation, env, pageField, perPageField, autoJumpToTopOnPagerChange, affixOffsetTop, loadDataOnce, query, queryParams, advanced, filter_3, scrolledY, offsetTop;
var _f;
return tslib_1.__generator(this, function (_g) {
switch (_g.label) {
case 0:
_e = this.props, store = _e.store, syncLocation = _e.syncLocation, env = _e.env, pageField = _e.pageField, perPageField = _e.perPageField, autoJumpToTopOnPagerChange = _e.autoJumpToTopOnPagerChange, affixOffsetTop = _e.affixOffsetTop, loadDataOnce = _e.loadDataOnce;
query = (_f = {},
_f[pageField || 'page'] = page,
_f);
if (!!loadDataOnce) return [3 /*break*/, 2];
return [4 /*yield*/, this.quickEditDataCheck()];
case 1:
_g.sent();
_g.label = 2;
case 2:
if (perPage) {
query[perPageField || 'perPage'] = perPage;
}
store.updateQuery(query, syncLocation && (env === null || env === void 0 ? void 0 : env.updateLocation) ? env.updateLocation : undefined, pageField, perPageField);
if ((_a = this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.confirmAdvancedFilter()) {
advanced = (_b = this.advanceFilterForm) === null || _b === void 0 ? void 0 : _b.confirmAdvancedFilter();
filter_3 = (advanced === null || advanced === void 0 ? void 0 : advanced.advancedFilter.length) || (advanced === null || advanced === void 0 ? void 0 : advanced.advancedFilterSub.length) || Object.keys(advanced === null || advanced === void 0 ? void 0 : advanced.advancedHeader).length;
if (filter_3) {
queryParams = (_c = this.advanceFilterForm) === null || _c === void 0 ? void 0 : _c.confirmAdvancedFilter();
}
}
if (Object.keys(this.state.filtercont).length) {
queryParams = this.state.filtercont;
}
this.search(undefined, undefined, undefined, false, this.afterSearchFn, undefined, undefined, queryParams);
if (autoJumpToTopOnPagerChange && this.control) {
(0, react_dom_1.findDOMNode)(this.control).scrollIntoView();
scrolledY = window.scrollY;
offsetTop = (_d = affixOffsetTop !== null && affixOffsetTop !== void 0 ? affixOffsetTop : env === null || env === void 0 ? void 0 : env.affixOffsetTop) !== null && _d !== void 0 ? _d : 0;
scrolledY && window.scroll(0, scrolledY - offsetTop);
}
return [2 /*return*/];
}
});
});
};
CRUD.prototype.handleSave = function (rows, diff, indexes, unModifiedItems, rowsOrigin, resetOnFailed, shouldHideLoaing) {
var _this = this;
var _a = this.props, store = _a.store, quickSaveApi = _a.quickSaveApi, quickSaveItemApi = _a.quickSaveItemApi, primaryField = _a.primaryField, env = _a.env, messages = _a.messages, reload = _a.reload, quickReloadTarget = _a.quickReloadTarget, quickDataReload = _a.quickDataReload, mode = _a.mode;
if (Array.isArray(rows)) {
if (!(0, api_1.isEffectiveApi)(quickSaveApi)) {
env && env.alert('CRUD quickSaveApi is required');
return;
}
//书豪说这里改成mergedData
var data_2 = (0, helper_1.createObject)(store.mergedData, {
rows: rows,
rowsDiff: diff,
indexes: indexes,
rowsOrigin: rowsOrigin
});
if (Array.isArray(rows) && rows.length && rows[0].hasOwnProperty(primaryField || 'id')) {
data_2.ids = rows
.map(function (item) { return item[primaryField || 'id']; })
.join(',');
}
if (unModifiedItems) {
data_2.unModifiedItems = unModifiedItems;
}
if (quickDataReload)
store.markFetching(true);
store
.saveRemote(quickSaveApi, data_2, {
shouldHideLoaing: shouldHideLoaing,
successMessage: messages && messages.saveFailed,
errorMessage: messages && messages.saveSuccess
})
.then(function () {
var _a, _b, _c, _d, _e;
if (quickDataReload)
store.markFetching(false);
reload && _this.reloadTarget(reload, data_2);
quickReloadTarget && _this.reloadTarget(quickReloadTarget, data_2);
if (quickDataReload) {
_this.search(undefined, undefined, true, true, _this.afterSearchFn);
}
else {
// 解除readonly限制
var _items = JSON.parse(JSON.stringify(mode == 'cross' ? tslib_1.__spreadArray([], ((_b = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.data.items) !== null && _b !== void 0 ? _b : []), true) : tslib_1.__spreadArray([], store.data.items, true)));
var _itemsRaw = JSON.parse(JSON.stringify(mode == 'cross' ? tslib_1.__spreadArray([], ((_d = (_c = _this.tableStore) === null || _c === void 0 ? void 0 : _c.data.items) !== null && _d !== void 0 ? _d : []), true) : tslib_1.__spreadArray([], store.data.itemsRaw, true)));
// 增加映射 加快查找速度 防止极端情况下复杂度指数增长
var _itemIdMap_1 = {};
(0, helper_1.mapTree)(_items, function (_) { return _itemIdMap_1[_[crud_1.DATAKEYID]] = _; });
var _itemRawIdMap_1 = {};
(0, helper_1.mapTree)(_itemsRaw, function (_) { return _itemRawIdMap_1[_[crud_1.DATAKEYID]] = _; });
if (data_2.rowsDiff.length) {
for (var _i = 0, _f = data_2.rowsDiff; _i < _f.length; _i++) {
var changeRows = _f[_i];
var changeItem = _itemIdMap_1[changeRows.changeItemKey];
var changeItemRaw = _itemRawIdMap_1[changeRows.changeItemKey];
if (changeItem)
Object.assign(changeItem, changeRows.diff);
if (changeItemRaw)
Object.assign(changeItemRaw, changeRows.diff);
}
}
var newData = tslib_1.__assign(tslib_1.__assign({}, store.data), { items: _items, itemsRaw: _itemsRaw, dataSetId: (0, helper_1.uuidv4)() });
if (_this.props.openCache)
store.updateCacheData(newData);
mode == 'cross' ? (_e = _this.tableStore) === null || _e === void 0 ? void 0 : _e.reInitData(newData) : store.reInitData(newData);
_this.afterSearchFn();
}
})
.catch(function (e) {
console.log(e);
store.markFetching(false);
});
}
else {
if (!(0, api_1.isEffectiveApi)(quickSaveItemApi)) {
env && env.alert('CRUD quickSaveItemApi is required!');
return;
}
var data_3 = (0, helper_1.createObject)(store.data, {
item: rows,
modified: diff,
origin: rowsOrigin
});
var sendData = (0, helper_1.createObject)(data_3, rows);
store
.saveRemote(quickSaveItemApi, sendData, { shouldHideLoaing: shouldHideLoaing })
.then(function () {
reload && _this.reloadTarget(reload, data_3);
quickReloadTarget && _this.reloadTarget(quickReloadTarget, data_3);
_this.search(undefined, undefined, true, true);
})
.catch(function () {
resetOnFailed && _this.control.reset();
});
}
};
CRUD.prototype.handleSaveOrder = function (moved, rows) {
var _this = this;
var _a = this.props, store = _a.store, saveOrderApi = _a.saveOrderApi, orderField = _a.orderField, primaryField = _a.primaryField, env = _a.env, reload = _a.reload;
if (!saveOrderApi) {
env && env.alert('CRUD saveOrderApi is required!');
return;
}
var model = (0, helper_1.createObject)(store.data);
var insertAfter;
var insertBefore;
var holding = [];
var hasIdField = primaryField &&
rows[0] &&
rows[0].hasOwnProperty(primaryField);
hasIdField || (model.idMap = {});
model.insertAfter = {};
rows.forEach(function (item) {
if (~moved.indexOf(item)) {
if (insertAfter) {
var insertAfterId = hasIdField
? insertAfter[primaryField]
: rows.indexOf(insertAfter);
model.insertAfter[insertAfterId] =
model.insertAfter[insertAfterId] || [];
hasIdField || (model.idMap[insertAfterId] = insertAfter);
model.insertAfter[insertAfterId].push(hasIdField ? item[primaryField] : item);
}
else {
holding.push(item);
}
}
else {
insertAfter = item;
insertBefore = insertBefore || item;
}
});
if (insertBefore && holding.length) {
var insertBeforeId = hasIdField
? insertBefore[primaryField]
: rows.indexOf(insertBefore);
hasIdField || (model.idMap[insertBeforeId] = insertBefore);
model.insertBefore = {};
model.insertBefore[insertBeforeId] = holding.map(function (item) {
return hasIdField ? item[primaryField] : item;
});
}
else if (holding.length) {
var first = holding[0];
var firstId = hasIdField
? first[primaryField]
: rows.indexOf(first);
hasIdField || (model.idMap[firstId] = first);
model.insertAfter[firstId] = holding
.slice(1)
.map(function (item) { return (hasIdField ? item[primaryField] : item); });
}
if (orderField) {
var start_1 = (store.page - 1) * store.perPage || 0;
rows = rows.map(function (item, key) {
var _a;
return (0, helper_1.extendObject)(item, (_a = {},
_a[orderField] = start_1 + key + 1,
_a));
});
}
model.rows = rows.concat();
hasIdField &&
(model.ids = rows
.map(function (item) { return item[primaryField]; })
.join(','));
hasIdField &&
orderField &&
(model.order = rows.map(function (item) {
return (0, pick_1.default)(item, [primaryField, orderField]);
}));
(0, api_1.isEffectiveApi)(saveOrderApi, model) &&
store
.saveRemote(saveOrderApi, model)
.then(function () {
reload && _this.reloadTarget(reload, model);
_this.search(undefined, undefined, true, true);
})
.catch(function () { });
};
CRUD.prototype.handleSelect = function (items, unSelectedItems) {
var _a = this.props, store = _a.store, keepItemSelectionOnPageChange = _a.keepItemSelectionOnPageChange, primaryField = _a.primaryField, multiple = _a.multiple, pickerMode = _a.pickerMode, onSelect = _a.onSelect;
var newItems = items;
var newUnSelectedItems = unSelectedItems;
if (keepItemSelectionOnPageChange && store.selectedItems.length) {
var oldItems_1 = store.selectedItems.concat();
var oldUnselectedItems_1 = store.unSelectedItems.concat();
items.forEach(function (item) {
var idx = (0, findIndex_1.default)(oldItems_1, function (a) {
return a === item ||
(a[primaryField || 'id'] &&
a[primaryField || 'id'] == item[primaryField || 'id']);
});
if (~idx) {
oldItems_1[idx] = item;
}
else {
oldItems_1.push(item);
}
var idx2 = (0, findIndex_1.default)(oldUnselectedItems_1, function (a) {
return a === item ||
(a[primaryField || 'id'] &&
a[primaryField || 'id'] == item[primaryField || 'id']);
});
if (~idx2) {
oldUnselectedItems_1.splice(idx2, 1);
}
});
unSelectedItems.forEach(function (item) {
var idx = (0, findIndex_1.default)(oldUnselectedItems_1, function (a) {
return a === item ||
(a[primaryField || 'id'] &&
a[primaryField || 'id'] == item[primaryField || 'id']);
});
var idx2 = (0, findIndex_1.default)(oldItems_1, function (a) {
return a === item ||
(a[primaryField || 'id'] &&
a[primaryField || 'id'] == item[primaryField || 'id']);
});
if (~idx) {
oldUnselectedItems_1[idx] = item;
}
else {
oldUnselectedItems_1.push(item);
}
~idx2 && oldItems_1.splice(idx2, 1);
});
newItems = oldItems_1;
newUnSelectedItems = oldUnselectedItems_1;
// const thisBatch = items.concat(unSelectedItems);
// let notInThisBatch = (item: any) =>
// !find(
// thisBatch,
// a => a[primaryField || 'id'] == item[primaryField || 'id']
// );
// newItems = store.selectedItems.filter(notInThisBatch);
// newUnSelectedItems = store.unSelectedItems.filter(notInThisBatch);
// newItems.push(...items);
// newUnSelectedItems.push(...unSelectedItems);
}
if (pickerMode && multiple === false && newItems.length > 1) {
newUnSelectedItems.push.apply(newUnSelectedItems, newItems.splice(0, newItems.length - 1));
}
store.setSelectedItems(newItems);
store.setUnSelectedItems(newUnSelectedItems);
onSelect && onSelect(newItems);
};
CRUD.prototype.handleChildPopOverOpen = function (popOver) {
if (this.props.interval &&
popOver &&
~['dialog', 'drawer'].indexOf(popOver.mode)) {
this.props.stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
this.props.store.setInnerModalOpened(true);
}
};
CRUD.prototype.handleChildPopOverClose = function (popOver) {
var _a = this.props, stopAutoRefreshWhenModalIsOpen = _a.stopAutoRefreshWhenModalIsOpen, silentPolling = _a.silentPolling, interval = _a.interval;
if (popOver && ~['dialog', 'drawer'].indexOf(popOver.mode)) {
this.props.store.setInnerModalOpened(false);
if (stopAutoRefreshWhenModalIsOpen && interval) {
this.timer = setTimeout(silentPolling ? this.silentSearch : this.search, Math.max(interval, 1000));
}
}
};
CRUD.prototype.setTotal = function (total) {
this.props.store.changeTotal(total);
};
CRUD.prototype.handleQuery = function (values, forceReload) {
var _a;
var _this = this;
var _b, _c;
if (forceReload === void 0) { forceReload = false; }
var _d = this.props, store = _d.store, syncLocation = _d.syncLocation, env = _d.env, pageField = _d.pageField, perPageField = _d.perPageField, loadDataOnce = _d.loadDataOnce;
var saveFilter = values['filterParam'] == null;
// Jay crud filter是点击submit按钮才更新query,现在需要拿到实时的form的data
var tmpValues = tslib_1.__assign(tslib_1.__assign({}, values), (_a = {}, _a[pageField || 'page'] = 1, _a));
var temp = (_b = this.filterForm) === null || _b === void 0 ? void 0 : _b.props.store.data[(_c = this.props.filter) === null || _c === void 0 ? void 0 : _c.name];
if (temp) {
tmpValues[this.props.filter.name] = temp;
}
store.updateQuery(tmpValues, syncLocation && env && env.updateLocation
? env.updateLocation
: undefined, pageField, perPageField);
// 如果需要缓存数据 阐释静默加载数据进缓存
this.search(undefined, undefined, undefined, forceReload, saveFilter ? this.afterSearchFn : function () {
var _a, _b;
_this.filterDrawerOpened = false;
(_b = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.filterColumns) === null || _b === void 0 ? void 0 : _b.clear();
_this.setState({ showColumnsFilter: false }, function () {
var _a, _b;
var orderColumns = (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.orderColumns;
if ((orderColumns === null || orderColumns === void 0 ? void 0 : orderColumns.size) > 0) {
(_b = _this.tableStore) === null || _b === void 0 ? void 0 : _b.handleMutilSort(loadDataOnce);
}
});
});
};
// 当itemaction触发的时候 subpath query ctx 都会有 走的是this.receive的逻辑
CRUD.prototype.reload = function (subpath, query, ctx, isItemAction) {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
if (isItemAction && ((_b = (_a = this.tableInstance) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.store.modified) > 0) {
this.showModal();
return;
}
// 我被触发了
this.handleScrollToTop();
if (this.props.api) {
if (ctx === null) {
(_d = (_c = this.props) === null || _c === void 0 ? void 0 : _c.store) === null || _d === void 0 ? void 0 : _d.clearData();
(_f = (_e = this.props) === null || _e === void 0 ? void 0 : _e.setTotalNum) === null || _f === void 0 ? void 0 : _f.call(_e, (_g = this.props.totalTab) === null || _g === void 0 ? void 0 : _g.key, 0, this.props.name, this.props.bodyName);
}
else {
if (query) {
if (isItemAction) {
this.itemActionData = query;
}
// 讨巧写法,同步方法中带有把参数合并的方法 handlequery 等同步代码执行完了再执行静默更新,保证查询条件时同步的
setTimeout(function () {
// 初始化查询条件之后在进行获取缓存
if (_this.props.openCache && _this.props.api) {
_this.props.store.preFetchDataSlience(_this.props.api, ctx, {
forceReload: false,
loadDataOnce: _this.props.loadDataOnce,
pageField: _this.props.pageField,
perPageField: _this.props.perPageField,
source: _this.props.source,
syncResponse2Query: _this.props.syncResponse2Query,
});
}
}, 100);
return this.receive((0, helper_1.isMobile)() ? tslib_1.__assign(tslib_1.__assign({}, query), { page: 1 }) : query);
}
else {
var advanceFilter = (_h = this.advanceFilterForm) === null || _h === void 0 ? void 0 : _h.confirmAdvancedFilter();
var postData = advanceFilter ? tslib_1.__assign(tslib_1.__assign({}, advanceFilter), { filterParam: (_k = (_j = this.props.store) === null || _j === void 0 ? void 0 : _j.query) === null || _k === void 0 ? void 0 : _k.filterParam }) : undefined;
// reload时候的快速查询条件会因为 已经有高级查询条件导致条件被固定,产生问题
this.search((0, helper_1.isMobile)() ? { page: 1 } : undefined, undefined, true, true, this.afterSearchFn, undefined, undefined, postData);
}
}
}
else if (ctx.items) {
// 没有api的情况下用其他的方式init
this.props.store.reInitData({ items: ctx.items }, true);
}
};
CRUD.prototype.receive = function (values) {
// 根据是否需要根据主表缓存数据,决定在由主表触发reload的时候是否要进行强制刷新
this.handleQuery(values, !this.props.openCache);
};
CRUD.prototype.reloadTarget = function (target, data) {
// implement this.
};
CRUD.prototype.closeTarget = function (target) {
// implement this.
};
CRUD.prototype.doAction = function (action, data, throwErrors) {
if (throwErrors === void 0) { throwErrors = false; }
return this.handleAction(undefined, action, data, throwErrors);
};
CRUD.prototype.unSelectItem = function (item, index) {
var _a, _b, _c, _d, _e;
var store = this.props.store;
var data = (_c = (_b = (_a = this.control) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.store) === null || _c === void 0 ? void 0 : _c.rows.concat();
var Item = data === null || data === void 0 ? void 0 : data.find(function (items) { return (0, isEqual_1.default)(item, items.data); });
if (Item) {
(_e = (_d = this.control) === null || _d === void 0 ? void 0 : _d.handleCheck) === null || _e === void 0 ? void 0 : _e.call(_d, Item);
}
var selected = store.selectedItems.concat();
var unSelected = store.unSelectedItems.concat();
var idx = selected.indexOf(item);
~idx && unSelected.push.apply(unSelected, selected.splice(idx, 1));
store.setSelectedItems(selected);
store.setUnSelectedItems(unSelected);
};
CRUD.prototype.clearSelection = function () {
var _a;
var _b = this.props, store = _b.store, OnSelectedItems = _b.OnSelectedItems;
(_a = this.control) === null || _a === void 0 ? void 0 : _a.handleCheckAll(2);
var selected = store.selectedItems.concat();
var unSelected = store.unSelectedItems.concat();
store.setSelectedItems([]);
store.setUnSelectedItems(unSelected.concat(selected));
};
// hasBulkActionsToolbar() {
// const { headerToolbar, footerToolbar } = this.props;
// const isBulkActions = (item: any) =>
// ~[
// 'headerBulkActions',
// 'footerBulkActions',
// 'bulkActions',
// 'bulk-actions'
// ].indexOf(item.type || item);
// return (
// (Array.isArray(headerToolbar) && find(headerToolbar, isBulkActions)) ||
// (Array.isArray(footerToolbar) && find(footerToolbar, isBulkActions))
// );
// }
CRUD.prototype.renderBulkActions = function (childProps, bulkActions) {
var _this = this;
var _a = this.props, itemActions = _a.itemActions, store = _a.store, render = _a.render, cx = _a.classnames, useMobileUI = _a.useMobileUI, primaryField = _a.primaryField, inModal = _a.inModal, fullDataApi = _a.fullDataApi;
var items = childProps.items;
if (!items.length ||
((!bulkActions || !bulkActions.length) &&
(!itemActions || !itemActions.length))) {
return null;
}
var selectedItems = (0, utils_2.getTableSelectedRowsData)(this.props.store, this.tableStore);
var bulkBtns = [];
var itemBtns = [];
var ctx = store.mergedData;
if (bulkActions &&
bulkActions.length &&
(!itemActions || !itemActions.length || selectedItems.length > 1)) {
bulkBtns = bulkActions
.filter(function (toolbar) {
return (0, helper_1.isVisible)(toolbar, inModal ? _this.filterData : store.filterData);
})
.map(function (item) { return (tslib_1.__assign(tslib_1.__assign({}, item), (0, filter_schema_1.default)(item, ctx))); })
.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.visible) !== false; });
}
var itemData = (0, helper_1.createObject)(store.data, selectedItems.length ? selectedItems[0] : {});
if (itemActions && selectedItems.length <= 1) {
itemBtns = itemActions
.map(function (item) { return (tslib_1.__assign(tslib_1.__assign({}, item), (0, filter_schema_1.default)(item, itemData))); })
.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.visible) !== false; });
}
var ids = selectedItems
.map(function (item) {
return item.hasOwnProperty(primaryField) ? item[primaryField] : null;
})
.filter(function (item) { return item; })
.join(',');
// Aug
var renderBulk = bulkBtns.length
? bulkBtns.map(function (btn, index) { return _this.bulkActionRender(btn, index); }) : [];
var renderItem = itemBtns.length
? itemBtns.map(function (btn, index) {
return render("bulk-action/".concat(index), tslib_1.__assign(tslib_1.__assign({}, (0, omit_1.default)(btn, ['visibleOn', 'hiddenOn', 'disabledOn'])), { type: specialButtonType.includes(btn.type) ? btn.type : 'button' }), {
key: "item-".concat(index),
data: itemData,
disabled: btn.disabled || selectedItems.length !== 1,
onAction: _this.handleItemAction.bind(_this, btn, itemData)
});
})
: [];
var children = tslib_1.__spreadArray(tslib_1.__spreadArray([], renderBulk, true), renderItem, true);
if (useMobileUI && (0, helper_1.isMobile)() && children.length > 3) {
var more = children.splice(2);
children.splice(0, 0, this.renderMoreToolbar(more));
}
return (react_1.default.createElement("div", { className: cx('Crud-actions', 'Crud-bulkActions') }, children));
};
CRUD.prototype.renderPagination = function (toolbar) {
var _a = this.props, store = _a.store, render = _a.render, cx = _a.classnames, alwaysShowPagination = _a.alwaysShowPagination;
var page = store.page, lastPage = store.lastPage;
if (store.mode !== 'simple' &&
store.lastPage < 2 &&
!alwaysShowPagination) {
return null;
}
var extraProps = {};
if (typeof toolbar !== 'string') {
extraProps.showPageInput = toolbar.showPageInput;
extraProps.maxButtons = toolbar.maxButtons;
}
return (react_1.default.createElement("div", { className: cx('Crud-pager') }, render('pagination', {
type: 'pagination'
}, tslib_1.__assign(tslib_1.__assign({}, extraProps), { inSmallDialog: this.inSmallDialog(), activePage: page, lastPage: lastPage, hasNext: store.hasNext, mode: store.mode, onPageChange: this.handleChangePage }))));
};
CRUD.prototype.renderStatistics = function () {
var _a, _b, _c;
var _d = this.props, store = _d.store, cx = _d.classnames, __ = _d.translate, mode = _d.mode;
return (react_1.default.createElement("div", { className: cx('Crud-statistics') }, mode == 'cross' ?
__('CRUD.total', { total: mode == 'cross' ? (_b = (_a = this.tableStore) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.length : (_c = store.data) === null || _c === void 0 ? void 0 : _c.total }) :
__('CRUD.stat', { total: store.total })));
};
CRUD.prototype.renderSwitchPerPage = function (childProps) {
var _this = this;
var _a;
var _b = this.props, store = _b.store, perPageAvailable = _b.perPageAvailable, cx = _b.classnames, ns = _b.classPrefix, __ = _b.translate;
// const items = childProps.items;
// if (!items.length) {
// return null;
// }
var perPages = (perPageAvailable || [5, 10, 20, 50, 100]).map(function (item) { return ({
// Jay 修改分页器样式
label: item + (_this.inSmallDialog() ? '' : " ".concat(__('CRUD.countPage'))),
value: item
}); });
return (react_1.default.createElement("div", { className: cx('Crud-pageSwitch'), ref: this.pageSwitchRef },
react_1.default.createElement(antd_1.Select, { options: perPages, placeholder: __('Select.placeholder'), defaultValue: ((_a = perPages[0]) === null || _a === void 0 ? void 0 : _a.value) || '', onChange: function (value) {
_this.handleChangePage(1, value);
}, getPopupContainer: function () { return _this.pageSwitchRef.current; } })));
};
CRUD.prototype.renderLoadMore = function (toolbar) {
var _this = this;
var _a = this.props, store = _a.store, ns = _a.classPrefix, cx = _a.classnames, __ = _a.translate;
var page = store.page, lastPage = store.lastPage;
return page < lastPage ? (react_1.default.createElement("div", { className: cx('Crud-loadMore') },
react_1.default.createElement(Button_1.default, { classPrefix: ns, onClick: function () {
return _this.search({ page: page + 1, loadDataMode: 'load-more' });
}, size: "sm" },
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon) &&
react_1.default.createElement(icons_1.Icon, { icon: toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon, className: "icon", symbol: true }),
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.label) ? toolbar === null || toolbar === void 0 ? void 0 : toolbar.label : __('CRUD.loadMore')))) : ('');
};
CRUD.prototype.renderColumnsFilterBtn = function (toolbar) {
var _this = this;
var _a = this.state, showColumnsFilter = _a.showColumnsFilter, filterDrawerVisible = _a.filterDrawerVisible;
var env = this.props.env;
return (react_1.default.createElement(Button_1.default, { tooltip: '列过滤', size: "sm", iconOnly: true, butColor: showColumnsFilter, tooltipContainer: (env === null || env === void 0 ? void 0 : env.getTopModalContainer) || undefined, onClick: function () {
var _a, _b;
if (_this.filterDrawerOpened) {
_this.setState({ filterDrawerVisible: true });
}
else {
var value = localStorage.getItem((_a = _this.props.name) !== null && _a !== void 0 ? _a : '');
if (value) {
var obj_1 = JSON.parse(value);
Object.keys(obj_1).forEach(function (key) { var _a; return (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.filterColumns.set(key, obj_1[key]); });
}
if (showColumnsFilter) {
_this.filterDrawerOpened = true;
_this.setState({ filterDrawerVisible: true });
}
else {
var items = (_b = _this.tableStore) === null || _b === void 0 ? void 0 : _b.handleMutilSort(_this.props.loadDataOnce);
if (_this.props.loadDataOnce && Array.isArray(items))
_this.setTotal(items.length);
_this.setState({ showColumnsFilter: !showColumnsFilter });
}
}
} },
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon) ?
react_1.default.createElement(icons_1.Icon, { icon: toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon, className: "icon", symbol: true }) :
react_1.default.createElement(icons_1.Icon, { icon: "packet-filtery", className: "icon" }),
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.label) && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.label)));
};
CRUD.prototype.renderToolAction = function (toolbar, index, childProps, toolbarRenderer) {
var _this = this;
var _a, _b;
if (index === void 0) { index = 0; }
if (childProps === void 0) { childProps = {}; }
var _c = this.props, cx = _c.classnames, __ = _c.translate, env = _c.env;
var toolActionSwitch = this.state.toolActionSwitch;
return react_1.default.createElement(antd_1.Popover, { placement: "bottomLeft", overlayClassName: cx('Tool-action'), getPopupContainer: env.getModalContainer, onVisibleChange: function (visible) { _this.setState({ toolActionSwitch: visible }); }, trigger: (0, helper_1.isMobile)() ? 'click' : 'hover', visible: toolActionSwitch, overlay: true, content: react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement("div", { className: cx('Tool-action-body'), onClick: function (e) { _this.setState({ toolActionSwitch: false }); } }, toolbar.toolBarItems.map(function (toolbar, index) { return _this.renderToolbar(toolbar, index, childProps, toolbarRenderer); }))) },
react_1.default.createElement(Button_1.default, null,
react_1.default.createElement(icons_1.Icon, { icon: "".concat((_a = toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon) !== null && _a !== void 0 ? _a : "#icon-tooltool_process--"), className: "icon", symbol: true }), (_b = ((toolbar === null || toolbar === void 0 ? void 0 : toolbar.label) && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.label))) !== null && _b !== void 0 ? _b : __('Table.tools')));
};
CRUD.prototype.renderType = function (schema) {
var _this = this;
var _a, _b, _c;
var _d = this.props, ctx = _d.ctx, cx = _d.classnames, ns = _d.classPrefix, __ = _d.translate, card = _d.card, listItem = _d.listItem, cross = _d.cross, env = _d.env;
var modes = this.state.modes;
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(LionCopyItem_1.default, { showItems: [{
value: (_b = (_a = schema.name) !== null && _a !== void 0 ? _a : schema.labelId) !== null && _b !== void 0 ? _b : "",
label: __('Alert.copyName'),
icon: "fa fa-sticky-note-o"
}], env: (_c = this.props) === null || _c === void 0 ? void 0 : _c.env },
react_1.default.createElement(antd_1.Popover, { placement: "bottomLeft", overlayClassName: cx('Tool-action'), getPopupContainer: env.getModalContainer, trigger: ['hover'], content: function () {
if (!(listItem || card || cross))
return;
return react_1.default.createElement("div", { className: 'crud-mode-exchange' },
react_1.default.createElement(Button_1.default, { disabled: modes == 'table' || modes == undefined, classPrefix: ns, onClick: function () { _this.setState({ modes: 'table' }, _this.handleFakeAnimation); }, size: "sm" },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-tooltool_table', className: "icon", symbol: true }),
"\u8868\u683C"),
listItem && react_1.default.createElement(Button_1.default, { disabled: modes == 'list', classPrefix: ns, onClick: function () {
_this.tableStore = null;
_this.setState({ modes: 'list' }, _this.handleFakeAnimation);
}, size: "sm" },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-tooltool_list', className: "icon", symbol: true }),
"\u5217\u8868"),
card && react_1.default.createElement(Button_1.default, { disabled: modes == 'cards', classPrefix: ns, onClick: function () {
_this.tableStore = null;
_this.setState({ modes: 'cards' }, _this.handleFakeAnimation);
}, size: "sm" },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-toolqiapianxingshi', className: "icon", symbol: true }),
"\u5361\u7247"),
cross && react_1.default.createElement(Button_1.default, { disabled: modes == 'cross', classPrefix: ns, onClick: function () {
_this.setState({ modes: 'cross' }, _this.handleFakeAnimation);
}, size: "sm" },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-tooltool_table', className: "icon", symbol: true }),
"\u4EA4\u53C9"));
} },
react_1.default.createElement(Button_1.default, { disabled: schema.disabled || (0, tpl_1.evalExpression)(schema.disabledOn, ctx), classPrefix: ns,
// onClick={this.debounceChangeMode}
size: "sm" },
(schema === null || schema === void 0 ? void 0 : schema.icon) ?
react_1.default.createElement(icons_1.Icon, { icon: schema === null || schema === void 0 ? void 0 : schema.icon, className: "icon", symbol: true }) :
react_1.default.createElement(icons_1.Icon, { style: { width: '14px', height: '15px', fill: this.state.autoWidth ? '#005bff' : '#000', stroke: '#005bff' }, icon: "auto-width", className: "icon" }),
(schema === null || schema === void 0 ? void 0 : schema.label) && (schema === null || schema === void 0 ? void 0 : schema.label))))));
};
CRUD.prototype.renderAiTool = function (action) {
var _a, _b;
// if (isMobile()) return null
var url = this.props.api.url;
var newData = (0, helper_1.createObject)(this.props.store.filterData, this.props.store.query, {}, true);
var _c = this.props.store.getRawCacheData().curApiForCache, curApiForCache = _c === void 0 ? '' : _c;
return (react_1.default.createElement(AiTool_1.default, { pageId: (_a = this.props.name) !== null && _a !== void 0 ? _a : '', env: tslib_1.__assign(tslib_1.__assign({}, this.props.env), { container: (_b = this.crudRef) === null || _b === void 0 ? void 0 : _b.current }), action: action, data: newData, paramData: curApiForCache || url, render: this.props.render }));
};
CRUD.prototype.renderAggregate = function () {
var _a = this.props, aggregate = _a.aggregate, cx = _a.classnames, render = _a.render, store = _a.store;
if (aggregate) {
var query = tslib_1.__assign(tslib_1.__assign({}, store.query), this.state.filtercont);
if (query.advancedFilter) {
query.advancedFilter = this.dealAdvacedCondition(query.advancedFilter);
}
return (react_1.default.createElement("div", { className: cx('Table-statistics', (0, helper_1.isMobile)() ? 'Table-statistic-mobile' : '') }, render('aggregate', aggregate, { items: (0, utils_2.getTableRowsData)(this.props.store, this.tableStore), query: query })));
}
return null;
};
CRUD.prototype.renderFilterToggler = function () {
var _a = this.props, store = _a.store, cx = _a.classnames, __ = _a.translate;
if (!store.filterTogggable) {
return null;
}
return (react_1.default.createElement("button", { onClick: function () { return store.setFilterVisible(!store.filterVisible); }, className: cx('Button Button--sm Button--default', {
'is-active': store.filterVisible
}) },
react_1.default.createElement(icons_1.Icon, { icon: "filter", className: "icon m-r-xs" }),
__('CRUD.filter')));
};
CRUD.prototype.renderAutoWidth = function (toolbar) {
var _this = this;
var env = this.props.env;
return (react_1.default.createElement(Button_1.default, { tooltip: this.state.autoWidth ? '宽松列宽' : '紧凑列宽', size: "sm", iconOnly: true, butColor: this.state.autoWidth, tooltipContainer: (env === null || env === void 0 ? void 0 : env.getTopModalContainer) || undefined, onClick: function () {
var _a;
var autoWidthPage = (0, storage_1.getLocalStorage)('autoWidthPage') || {};
autoWidthPage[_this.props.name || ''] = !_this.state.autoWidth;
(0, storage_1.setLocalStorage)('autoWidthPage', autoWidthPage);
_this.setState({ autoWidth: !_this.state.autoWidth });
var localEditWidthMap = (0, storage_1.getLocalStorage)(Table_1.EDITWIDTHKEY) || {};
localEditWidthMap === null || localEditWidthMap === void 0 ? true : delete localEditWidthMap[((_a = _this.props) === null || _a === void 0 ? void 0 : _a.name) || ''];
(0, storage_1.setLocalStorage)(Table_1.EDITWIDTHKEY, localEditWidthMap);
} },
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon) ?
react_1.default.createElement(icons_1.Icon, { icon: toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon, className: "icon", symbol: true }) :
react_1.default.createElement(icons_1.Icon, { style: { width: '14px', height: '15px', fill: this.state.autoWidth ? '#005bff' : '#000', stroke: '#005bff' }, icon: "auto-width", className: "icon" }),
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.label) && (toolbar === null || toolbar === void 0 ? void 0 : toolbar.label)));
};
CRUD.prototype.renderExportCSV = function (toolbar) {
var _a = this.props, store = _a.store, ns = _a.classPrefix, cx = _a.classnames, __ = _a.translate, loadDataOnce = _a.loadDataOnce;
var api = toolbar.api;
return (react_1.default.createElement(Button_1.default, { classPrefix: ns, onClick: function () {
return store.exportAsCSV({
loadDataOnce: loadDataOnce,
api: api
});
}, size: "sm" }, toolbar.label || __('CRUD.exportCSV')));
};
CRUD.prototype.renderExport = function (toolbar) {
var _this = this;
var _a, _b, _c;
var _d = this.props, store = _d.store, ns = _d.classPrefix, cx = _d.classnames, __ = _d.translate, env = _d.env;
var ctx = (0, helper_1.createObject)({}, {
items: (0, utils_2.getTableRowsData)(this.props.store, this.tableStore),
selectedItems: (0, utils_2.getTableSelectedRowsData)(this.props.store, this.tableStore),
unSelectedItems: store.unSelectedItems.concat()
});
return (react_1.default.createElement(LionCopyItem_1.default, { showItems: [{
value: (_b = (_a = toolbar.name) !== null && _a !== void 0 ? _a : toolbar.labelId) !== null && _b !== void 0 ? _b : "",
label: __('Alert.copyName'),
icon: "fa fa-sticky-note-o"
}], env: (_c = this.props) === null || _c === void 0 ? void 0 : _c.env },
react_1.default.createElement("div", { style: { position: 'relative' }, className: 'exportExcel' },
react_1.default.createElement(Button_1.default, { classPrefix: ns, onClick: function (e) { _this.handleAction(e, toolbar, ctx); }, size: "sm" },
(toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon) && react_1.default.createElement(icons_1.Icon, { icon: toolbar === null || toolbar === void 0 ? void 0 : toolbar.icon, className: "icon", symbol: true }),
toolbar.label || __('CRUD.exportExcel')),
toolbar.redDot === true && react_1.default.createElement("div", { style: { position: 'absolute', display: 'inline-block', right: 0, top: 0, background: 'red', width: 6, height: 6, borderRadius: 4 } }))));
};
/**
* Jay
* 标签、文件打印
*/
CRUD.prototype.renderPrint = function (schema, isFilePrint) {
var _this = this;
var _a, _b, _c;
var _d = this.props, store = _d.store, ns = _d.classPrefix, cx = _d.classnames, __ = _d.translate, primaryField = _d.primaryField;
var selectedItems = (0, utils_2.getTableSelectedRowsData)(this.props.store, this.tableStore);
var ids = selectedItems
.map(function (item) {
return item.hasOwnProperty(primaryField) ? item[primaryField] : null;
})
.filter(function (item) { return item; })
.join(',');
var ctx = (0, helper_1.createObject)(store.mergedData, tslib_1.__assign(tslib_1.__assign({}, selectedItems[0]), { items: (0, utils_2.getTableRowsData)(this.props.store, this.tableStore), // 选中行数据
selectedItems: selectedItems, // 选中行数据
ids: ids, primaryField: primaryField }));
return (react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement(LionCopyItem_1.default, { showItems: [{
value: (_b = (_a = schema.name) !== null && _a !== void 0 ? _a : schema.labelId) !== null && _b !== void 0 ? _b : "",
label: __('Alert.copyName'),
icon: "fa fa-sticky-note-o"
}], env: (_c = this.props) === null || _c === void 0 ? void 0 : _c.env },
react_1.default.createElement(Button_1.default, { disabled: schema.disabled || (0, tpl_1.evalExpression)(schema.disabledOn, ctx), classPrefix: ns, onClick: function () {
var LODOP = (0, LodopFuncs_1.getLodop)();
if (LODOP) {
_this.setState({
ModalProps: tslib_1.__assign(tslib_1.__assign({}, schema), { show: true, ctx: ctx, onHide: function () {
_this.setState({ printType: undefined });
} }),
printType: isFilePrint
? 'file'
: schema.actionType === 'label-print'
? 'label'
: 'bill'
});
}
}, size: "sm" }, __(schema.label
? schema.label
: !isFilePrint
? 'CRUD.labelPrint'
: 'CRUD.filePrint')))));
};
// Aug
CRUD.prototype.moreHandleTouch = function (e) {
e.stopPropagation();
this.setState({ moreIsOpened: true });
};
CRUD.prototype.renderActionGroup = function (toolbar, index, childProps) {
var _this = this;
var _a = this.props, size = _a.size, block = _a.block, className = _a.className, __ = _a.translate, cx = _a.classnames, ns = _a.classPrefix, groupName = _a.groupName, groupLevel = _a.groupLevel;
return react_1.default.createElement(antd_1.Popover, { content: function () {
return react_1.default.createElement("div", { className: cx('Group-action-items') }, toolbar.actionItems.map(function (_) {
return _this.renderToolbar(_, index, childProps);
}));
} },
react_1.default.createElement(Button_1.default, { className: cx('Group-display-button', className), level: groupLevel || 'primary', block: block, size: size },
react_1.default.createElement("span", { className: cx('Group-text') }, toolbar.groupName),
react_1.default.createElement("span", { className: cx('Group-icon') },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-tooltool_down', className: "icon", symbol: true }))));
};
// Aug更多操作
CRUD.prototype.renderMoreToolbar = function (children) {
var _this = this;
var _a = this.props, cx = _a.classnames, __ = _a.translate, getModalContainer = _a.env.getModalContainer, render = _a.render;
return (react_1.default.createElement(ActionSheet_1.default, { key: Date.now() + '-actionSheet', isOpened: this.state.moreIsOpened, container: getModalContainer, round: true, onHide: function (e) {
e.stopPropagation();
_this.setState({ moreIsOpened: false });
}, popupContent: react_1.default.createElement("div", { style: { width: '100%' } }, children.map(function (child, idx) {
return (react_1.default.createElement("div", { key: idx, "data-index": idx, id: "amis-action-sheet-btn-wrapper", className: "action-sheet-btn-wrapper", onClick: function (e) {
// e.stopPropagation();
_this.setState({ moreIsOpened: false });
} }, child.dom || child));
})) },
react_1.default.createElement("span", { className: cx('Button', 'Button--link'), onClick: this.moreHandleTouch.bind(this) },
react_1.default.createElement("i", { className: cx('Button-icon', 'fa', 'fa-reorder') }),
react_1.default.createElement("span", null, __('More')))));
};
CRUD.prototype.renderToolbar = function (toolbar, index, childProps, toolbarRenderer,
// Jay
isFooter) {
var _this = this;
var _a, _b, _c, _d, _e;
if (index === void 0) { index = 0; }
if (childProps === void 0) { childProps = {}; }
if (!toolbar) {
return null;
}
var _f = this.props, render = _f.render, store = _f.store, __ = _f.translate, useMobileUI = _f.useMobileUI, headerBulkActions = _f.headerBulkActions, footerBulkActions = _f.footerBulkActions, inModal = _f.inModal, card = _f.card, listItem = _f.listItem, cross = _f.cross, env = _f.env, header = _f.header, filter = _f.filter;
var _g = this.state, modes = _g.modes, toolChildMaxCount = _g.toolChildMaxCount, filtercont = _g.filtercont;
var type = toolbar.type || toolbar;
var actionType = toolbar.actionType;
if (type === 'headerBulkActions') {
return this.renderBulkActions(childProps, (0, helper_1.isMobile)() ? (0, utils_2.unitBulkActions)({
headerActions: this.props.headerActions,
headerToolbar: this.props.headerToolbar,
headerBulkActions: this.props.headerBulkActions
}) : headerBulkActions);
}
else if (type === 'data-statics' || type === 'data-cross' || type === 'find-replace' || type === 'data-chart') {
// 统计模式卡片列表中移除
if (modes == 'cards' || modes == 'list') {
return null;
}
}
else if (type === "detail-model") {
return null;
}
else if (type === 'footerBulkActions') {
return this.renderBulkActions(childProps, footerBulkActions);
}
else if (type === 'pagination') {
return this.renderPagination(toolbar);
}
else if (type === 'ai-tool') {
return this.renderAiTool(toolbar);
}
else if (type === 'statistics') {
return this.renderStatistics();
}
else if (type === 'switch-per-page') {
return this.renderSwitchPerPage(childProps);
}
else if (type === 'load-more') {
return this.renderLoadMore(toolbar);
}
else if (type === 'filter-toggler') {
return this.renderFilterToggler();
}
else if (type === 'auto-width') {
return this.renderAutoWidth(toolbar);
}
else if (type === 'export-csv') {
return this.renderExportCSV(toolbar);
}
else if (type === 'reload') {
return this.renderReload(toolbar, index);
}
else if (actionType === 'label-print' || actionType === 'bill-print') {
return this.renderPrint(toolbar);
}
else if (actionType === 'export') {
return this.renderExport(toolbar);
// } else if (actionType === "action-group") {
// return this.renderActionGroup(toolbar as Schema, index, childProps, this.toolbarRenderer)
}
else if (type === 'file-print') {
return this.renderPrint(toolbar, true);
}
else if (type === 'columns-filter') {
if (modes == 'cards' || modes == 'list') {
return;
}
return this.renderColumnsFilterBtn(toolbar);
}
else if (type === 'tool-bar-action') {
return this.renderToolAction(toolbar, index, childProps, toolbarRenderer);
}
else if (type === 'type-conversion') {
if (!card && !listItem && !cross || (0, helper_1.isMobile)()) {
return;
}
return this.renderType(toolbar);
}
else if (Array.isArray(toolbar)) {
var children = toolbar
.filter(function (toolbar) {
return (0, helper_1.isVisible)(toolbar, inModal ? _this.filterData : store.filterData) && !((0, helper_1.isMobile)() && (toolbar.type == 'columns-toggler' || toolbar.isToolBar));
})
.map(function (toolbar, index) { return ({
dom: _this.renderToolbar(toolbar, index, childProps, toolbarRenderer),
toolbar: toolbar
}); })
.filter(function (item) { return item.dom; });
// Jay
// 对分页器的几个元素进行排序
var sortFooterbar_1 = {
'statistics': 1,
'pagination': 2,
'switch-per-page': 3
};
children.sort(function (a, b) {
var _a, _b;
if (b.toolbar.align === 'right') {
if (a.toolbar.align === 'left' ||
sortFooterbar_1[(_a = a.toolbar) === null || _a === void 0 ? void 0 : _a.type] > sortFooterbar_1[(_b = b.toolbar) === null || _b === void 0 ? void 0 : _b.type]) {
return -1;
}
else if (sortFooterbar_1[a.toolbar.type] < sortFooterbar_1[b.toolbar.type]) {
return 1;
}
}
return 0;
});
var len = children.length;
var cx_1 = this.props.classnames;
if (len) {
// Aug 移动端超过三个显示更多
if (useMobileUI && (0, helper_1.isMobile)() && toolChildMaxCount && len > toolChildMaxCount) {
var moreToolbar = children.splice(toolChildMaxCount);
var moreToolbarDom = this.renderMoreToolbar(moreToolbar);
children.splice(0, 0, { dom: moreToolbarDom, toolbar: { type: 'more' } });
}
var button = children.filter(function (_a, index) {
var toolbar = _a.toolbar;
return toolbar.align == 'right' && !isFooter;
}).reverse();
var searchBtnIndex = button.findIndex(function (_a) {
var toolbar = _a.toolbar;
return toolbar.actionType === 'advanced-filter';
});
var leftBtns = children.filter(function (_a, index) {
var toolbar = _a.toolbar;
return (toolbar.align !== 'right' || isFooter) && toolbar.type !== 'paginator';
});
var paginator = children.find(function (_a) {
var toolbar = _a.toolbar;
return toolbar.type === 'paginator';
});
// 工具栏里面啥都没有的情况之前返回空
if (!((_a = this.props.headerToolbar) === null || _a === void 0 ? void 0 : _a.length) && !((_b = this.props.footerToolbar) === null || _b === void 0 ? void 0 : _b.filter(function (_) { return _.type !== 'footerBulkActions'; }).length))
return react_1.default.createElement("div", { style: { marginTop: 0, border: 0 } });
return (react_1.default.createElement("div", { className: cx_1('Crud-toolbar', { footer: isFooter }), key: index },
leftBtns.length > 0 && react_1.default.createElement("div", { ref: this.toolActionsRef, className: cx_1('Crud-toolbar-tool--actions') }, leftBtns.map(function (_a, index) {
var toolbar = _a.toolbar, child = _a.dom;
// const type = (toolbar as Schema).type || toolbar;
// let align = toolbar.align || (type === 'pagination' ? 'right' : 'left');
return (react_1.default.createElement("div", { key: index, className: cx_1('Crud-toolbar-item', toolbar.className) },
" ",
child,
" "));
})),
(paginator || (!isFooter && button.length > 0)) && react_1.default.createElement("div", { className: cx_1('Crud-toolbar-tool--head') },
paginator && ((_d = (_c = paginator.toolbar).renderPagenation) === null || _d === void 0 ? void 0 : _d.call(_c)),
!isFooter && button.length > 0 && react_1.default.createElement("div", { className: cx_1('Crud-toolbar-tool') },
react_1.default.createElement("div", { className: cx_1('Crud-toolbar-tool-content') },
react_1.default.createElement(OverflowWrapper_1.default, { env: env, classPrefix: cx_1, itemClassName: 'toolbar-btn-item', showFixRight: searchBtnIndex > -1, fixRightRenderIndex: searchBtnIndex, items: button.map(function (_a, index) {
var toolbar = _a.toolbar, child = _a.dom;
return ({
key: index,
children: (react_1.default.createElement("div", { key: index, className: cx_1('Crud-toolbar-item', 'toolbar-btn-item', toolbar.className) },
" ",
child,
" "))
});
}) }))))));
}
return null;
}
var result = toolbarRenderer
? toolbarRenderer(toolbar, index)
: undefined;
if (result !== void 0) {
return result;
}
var $$editable = childProps.$$editable;
return render("toolbar/".concat(index), toolbar, {
// 包两层,主要是为了处理以下 case
// 里面放了个 form,form 提交过来的时候不希望把 items 这些发送过来。
// 因为会把数据呈现在地址栏上。
data: (0, helper_1.createObject)((0, helper_1.createObject)(inModal ? this.filterData : store.filterData, {
items: childProps.items,
selectedItems: childProps.selectedItems,
unSelectedItems: childProps.unSelectedItems
}), {}),
headerCanShow: (0, utils_2.headerCanShow)(header, filter, filtercont, this.tableStore),
page: store.page,
lastPage: store.lastPage,
perPage: store.perPage,
total: store.total,
onQuery: this.handleQuery,
onAction: this.handleAction,
onChangePage: this.handleChangePage,
onBulkAction: this.handleBulkAction,
renderToolbar: this.renderToolbar,
$$editable: $$editable,
updateAutoFillHeight: (_e = this === null || this === void 0 ? void 0 : this.tableInstance) === null || _e === void 0 ? void 0 : _e.updateAutoFillHeight
});
};
CRUD.prototype.renderHeaderToolbar = function (childProps, toolbarRenderer, renderPagenation) {
var _a = this.props, toolbar = _a.toolbar, toolbarInline = _a.toolbarInline, headerToolbar = _a.headerToolbar;
var privateHeadrToolBar = tslib_1.__spreadArray([], headerToolbar, true);
if (renderPagenation) {
privateHeadrToolBar.push({
type: 'paginator',
align: 'left',
renderPagenation: renderPagenation
});
}
if (toolbar) {
if (Array.isArray(privateHeadrToolBar)) {
privateHeadrToolBar = toolbarInline
? privateHeadrToolBar.concat(toolbar)
: [privateHeadrToolBar, toolbar];
}
else if (privateHeadrToolBar) {
privateHeadrToolBar = [privateHeadrToolBar, toolbar];
}
else {
privateHeadrToolBar = toolbar;
}
}
return this.renderToolbar(privateHeadrToolBar || [], 0, childProps, toolbarRenderer);
};
CRUD.prototype.renderFooterToolbar = function (childProps, toolbarRenderer, customToolbar // Aug
) {
var footerToolbar = customToolbar || this.props.footerToolbar; // Aug
var _a = this.props, toolbar = _a.toolbar, toolbarInline = _a.toolbarInline;
if (toolbar || footerToolbar) {
if (Array.isArray(footerToolbar)) {
if (footerToolbar.length) {
footerToolbar = (toolbarInline
? footerToolbar.concat(toolbar)
: [footerToolbar, toolbar]).filter(Boolean);
if (footerToolbar.find(function (item) { return item.type == 'pagination'; })) {
!footerToolbar.find(function (item) { return item.type == 'switch-per-page'; }) && footerToolbar.push({
"type": "switch-per-page",
"align": "right"
});
}
}
else {
footerToolbar = null;
}
}
else if (footerToolbar) {
footerToolbar = [footerToolbar, toolbar];
}
else {
footerToolbar = toolbar || null;
}
}
else {
footerToolbar = null;
}
return this.renderToolbar(footerToolbar, 0, childProps, toolbarRenderer, true);
};
CRUD.prototype.renderSelection = function () {
var _this = this;
var _a = this.props, store = _a.store, cx = _a.classnames, labelField = _a.labelField, labelTpl = _a.labelTpl, primaryField = _a.primaryField, __ = _a.translate;
if (!store.selectedItems.length) {
return null;
}
// this?.tableInstance?.updateAutoFillHeight?.()
return (react_1.default.createElement("div", { className: cx('Crud-selection') },
react_1.default.createElement("div", { className: cx('Crud-selectionLabel') }, __('CRUD.selected')),
store.selectedItems.map(function (item, index) {
return react_1.default.createElement("div", { key: index, className: cx("Crud-value") },
react_1.default.createElement("span", { "data-tooltip": __('delete'), "data-position": "bottom", className: cx('Crud-valueIcon'), onClick: _this.unSelectItem.bind(_this, item, index) }, "\u00D7"),
react_1.default.createElement("span", { className: cx('Crud-valueLabel') }, labelTpl ? (react_1.default.createElement(Html_1.default, { html: (0, tpl_1.filter)(labelTpl, item) })) : ((0, helper_1.getVariable)(item, labelField || 'label') ||
(0, helper_1.getVariable)(item, primaryField || 'id'))));
}),
react_1.default.createElement("a", { onClick: this.clearSelection, className: cx('Crud-selectionClear') }, __('clear'))));
};
// Aug
CRUD.prototype.renderFilter = function (isFilter) {
var _this = this;
var _a, _b, _c, _d, _e;
if (isFilter === void 0) { isFilter = false; }
var _f = this.props, name = _f.name, initFetch = _f.initFetch, _filter = _f.filter, store = _f.store, useMobileUI = _f.useMobileUI, render = _f.render, __ = _f.translate, cx = _f.classnames, advancedFilter = _f.advancedFilter, advancedFilterApi = _f.advancedFilterApi, globalFilter = _f.globalFilter;
var mobileUI = useMobileUI && (0, helper_1.isMobile)();
var filter = _filter || (0, crudFilter_1.defaultFilterSchma)(this.props.name || '', !!((_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.length));
var _g = this.state, filterExist = _g.filterExist, filtertpl = _g.filtertpl;
// 高级查询条件
var columns = (_e = (_d = advancedFilter === null || advancedFilter === void 0 ? void 0 : advancedFilter.body.find(function (item) { return item.name == 'advancedFilter'; })) === null || _d === void 0 ? void 0 : _d.body) !== null && _e !== void 0 ? _e : [];
var advancedFilters = advancedFilter ? (0, lodash_1.flatMap)(filtertpl, function (item, index) {
var _a, _b, _c, _d;
var val;
if (typeof (item === null || item === void 0 ? void 0 : item.value) === "number") {
if ((_a = item === null || item === void 0 ? void 0 : item.labelName) === null || _a === void 0 ? void 0 : _a.includes(",")) {
val = (item === null || item === void 0 ? void 0 : item.labelName).split(",")[0] + "...";
}
else {
val = item === null || item === void 0 ? void 0 : item.labelName;
}
}
var values = item.value;
if (values && typeof values == 'string' && values.includes('(') && values.includes(')') && columns) {
// 做一个从小到大的排序
var compareField = (_b = columns.filter(function (item) { return values.includes(item.name.split('.').pop()); }).map(function (item) { return item.name.split('.').pop(); })) === null || _b === void 0 ? void 0 : _b.sort(function (cur, next) { return next.length - cur.length; });
var result_1 = values.substring(1, values.length - 1);
compareField.forEach(function (item) {
var match = item;
var regex = new RegExp(match, 'g');
var content = columns.find(function (item) { return item.name.split('.').pop() == match; });
if (content) {
result_1 = result_1.replace(regex, "[".concat(content.label, "]"));
}
});
val = result_1;
}
if (!(val ? val : ((item === null || item === void 0 ? void 0 : item.valuesAlia) || (item === null || item === void 0 ? void 0 : item.value))))
return [];
return { key: (_c = item.keyName) !== null && _c !== void 0 ? _c : item.name, name: item.name, label: (_d = item.label) !== null && _d !== void 0 ? _d : '', value: (val !== null && val !== void 0 ? val : ((item === null || item === void 0 ? void 0 : item.labelName) || (item === null || item === void 0 ? void 0 : item.valuesAlia) || (item === null || item === void 0 ? void 0 : item.value) || '')) };
}) : undefined;
if ((filter || (advancedFilters === null || advancedFilters === void 0 ? void 0 : advancedFilters.length) || globalFilter) && (!store.filterTogggable || store.filterVisible)) {
return !mobileUI
? render(
//默认
'filter', tslib_1.__assign(tslib_1.__assign({ title: __('CRUD.filter'), mode: 'grid', submitText: __('search'), wrapWithPanel: false }, filter), { type: 'form', api: null, showHeader: true, sortable: true }), {
key: 'filter',
crudName: this.props.name,
className: !!filter ? undefined : cx('Form--hidden'),
panelClassName: cx('Crud-filter', (filter === null || filter === void 0 ? void 0 : filter.panelClassName) || 'Panel--default'),
data: store.filterData,
onReset: this.handleFilterReset,
onSubmit: this.handleFilterSubmit,
onInit: _filter ? this.handleFilterInit : undefined,
formStore: undefined,
advancedFilterVisible: false,
advancedFilterApi: advancedFilterApi,
defaultAdvancedQuery: this.defaultAdvancedQuery,
getFilterForm: this.getFilterForm,
handleFilterAdvanced: this.handleFilterAdvanced,
advancedFilter: this.props.advancedFilter,
filtercont: this.state.filtercont,
handleFilterOptions: this.handleFilterOptions,
handledelVisible: this.handledelVisible,
handleReset: this.handleReset,
advancedFilters: advancedFilters,
onAdvancedFilterRemove: function (name) {
if (name == 'all') {
_this.handledelVisible(undefined, true);
}
else {
var item = filtertpl.find(function (item) { var _a; return ((_a = item.keyName) !== null && _a !== void 0 ? _a : item.name) === name; });
item && _this.handledelVisible(item, false, undefined, item.advancedFilterIndex);
}
},
globalFilters: globalFilter ? globalFilter.body : null,
onGlobalFilterChange: function (values) {
var query = tslib_1.__assign(tslib_1.__assign({}, store.query), { globalFilterParam: values });
store.updateQuery(query);
_this.search(undefined, undefined, undefined, true, _this.afterSearchFn);
}
})
:
react_1.default.createElement("div", { className: cx('Mobile-filter'), onClick: function () {
// this.setState({ mobileFilterShow: true })
return _this.handleFilterAdvanced();
} },
react_1.default.createElement(icons_1.Icon, { icon: "#icon-tooltool_filter", style: { fill: (filterExist || isFilter || (advancedFilters === null || advancedFilters === void 0 ? void 0 : advancedFilters.length)) ? '#3574ee' : undefined } }),
react_1.default.createElement("span", { className: "filter-text ".concat((filterExist || isFilter || (advancedFilters === null || advancedFilters === void 0 ? void 0 : advancedFilters.length)) ? 'has-filter' : '') }, __('CRUD.filter')));
}
else if (mobileUI && advancedFilter) {
return react_1.default.createElement("div", { className: cx('Mobile-filter'), onClick: function () {
return _this.handleFilterAdvanced();
} },
react_1.default.createElement(icons_1.Icon, { icon: "#icon-tooltool_filter", style: { fill: (filterExist || isFilter) ? '#3574ee' : undefined } }),
react_1.default.createElement("span", { className: "filter-text ".concat((filterExist || isFilter) ? 'has-filter' : '') }, __('CRUD.filter')));
}
return null;
};
CRUD.prototype.renderAdvacendFilterQuery = function () {
var _this = this;
var _a, _b;
var _c = this.props, classnames = _c.classnames, advancedFilter = _c.advancedFilter;
var _d = this.state, filt = _d.filtercont, filtertpl = _d.filtertpl;
var filtboolean = (0, utils_2.filtBoolean)(filt, this.tableStore);
if (!filtboolean)
return null;
if (!(filtertpl === null || filtertpl === void 0 ? void 0 : filtertpl.length))
return null;
var columns = (_b = (_a = advancedFilter === null || advancedFilter === void 0 ? void 0 : advancedFilter.body.find(function (item) { return item.name == 'advancedFilter'; })) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : [];
return (react_1.default.createElement(antd_1.Space, { style: { padding: '8px 8px 0 8px' }, size: [4, 8], wrap: true },
(filtertpl === null || filtertpl === void 0 ? void 0 : filtertpl.length) > 0 && filtertpl.map(function (item, index) {
var _a, _b;
var val;
if (typeof (item === null || item === void 0 ? void 0 : item.value) === "number") {
if ((_a = item === null || item === void 0 ? void 0 : item.labelName) === null || _a === void 0 ? void 0 : _a.includes(",")) {
val = (item === null || item === void 0 ? void 0 : item.labelName).split(",")[0] + "...";
}
else {
val = item === null || item === void 0 ? void 0 : item.labelName;
}
// } else if (item?.value?.includes(",")) {
// val = (item?.valuesAlia || item?.value).split(",")[0] + "..."
}
var values = item.value;
if (values && typeof values == 'string' && values.includes('(') && values.includes(')') && columns) {
// 做一个从小到大的排序
var compareField = (_b = columns.filter(function (item) { return values.includes(item.name.split('.').pop()); }).map(function (item) { return item.name.split('.').pop(); })) === null || _b === void 0 ? void 0 : _b.sort(function (cur, next) { return next.length - cur.length; });
var result_2 = values.substring(1, values.length - 1);
compareField.forEach(function (item) {
var match = item;
var regex = new RegExp(match, 'g');
var content = columns.find(function (item) { return item.name.split('.').pop() == match; });
if (content) {
result_2 = result_2.replace(regex, "[".concat(content.label, "]"));
}
});
val = result_2;
}
if (!(val ? val : ((item === null || item === void 0 ? void 0 : item.valuesAlia) || (item === null || item === void 0 ? void 0 : item.value))))
return null;
return react_1.default.createElement(antd_1.Popover, { getPopupContainer: function () { return document.getElementById('amis-modal-container') || document.body; }, key: item.name + String(index), content: react_1.default.createElement("div", { className: classnames('Form-query-Tag-content') },
react_1.default.createElement("label", null, item.label + ":"),
react_1.default.createElement("span", null, (val ? val : (item.labelName || item.valuesAlia || item.value)))), overlayStyle: { maxWidth: 500 } },
react_1.default.createElement(antd_1.Tag, { className: classnames('Form-query'), color: "blue", closable: true, onClose: function (e) { _this.handledelVisible(item, false, e, item.advancedFilterIndex); } },
react_1.default.createElement("span", { className: classnames('Form-queryConstent') }, item.label + ":" + "".concat(val ? val : ((item === null || item === void 0 ? void 0 : item.labelName) || (item === null || item === void 0 ? void 0 : item.valuesAlia) || (item === null || item === void 0 ? void 0 : item.value))))));
}),
(filtertpl === null || filtertpl === void 0 ? void 0 : filtertpl.length) > 0 &&
react_1.default.createElement(antd_1.Tag, { className: classnames("Form-site-tag-plus"), onClick: function () { var _a; (_a = _this.handledelVisible) === null || _a === void 0 ? void 0 : _a.call(_this, _this.props.data, true); } },
react_1.default.createElement(icons_1.Icon, { icon: '#icon-tooltool_delete', symbol: true }))));
};
CRUD.prototype.getTableInstance = function (table) {
var _a, _b;
this.tableInstance = table;
(_b = (_a = this.props).getTableInstance) === null || _b === void 0 ? void 0 : _b.call(_a, table);
};
CRUD.prototype.getFilterColumns = function () {
var _a;
return (_a = this.tableStore) === null || _a === void 0 ? void 0 : _a.filteredColumns;
};
CRUD.prototype.editHeader = function () {
return react_1.default.createElement("div", { className: 'edit-row-header Modle_edit-row-header' },
react_1.default.createElement("span", { className: 'close-edit', onClick: this.hideAdvancedFilter },
react_1.default.createElement(icons_1.Icon, { icon: 'title-left', className: "icon", style: { width: '16px', height: '16px' } })),
react_1.default.createElement("div", { className: 'close-title' }, "\u641C\u7D22"),
react_1.default.createElement("span", { className: 'close-edit' }));
};
CRUD.prototype.render = function () {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var _r = this.props, className = _r.className, bodyClassName = _r.bodyClassName, filter = _r.filter, render = _r.render, store = _r.store, mode = _r.mode, syncLocation = _r.syncLocation, children = _r.children, headerBulkActions = _r.headerBulkActions, footerBulkActions = _r.footerBulkActions, pickerMode = _r.pickerMode, multiple = _r.multiple, showIndex = _r.showIndex, valueField = _r.valueField, primaryField = _r.primaryField, value = _r.value, hideQuickSaveBtn = _r.hideQuickSaveBtn, itemActions = _r.itemActions, cx = _r.classnames, keepItemSelectionOnPageChange = _r.keepItemSelectionOnPageChange, maxKeepItemSelectionLength = _r.maxKeepItemSelectionLength, onAction = _r.onAction, popOverContainer = _r.popOverContainer, __ = _r.translate, onQuery = _r.onQuery, autoGenerateFilter = _r.autoGenerateFilter, onSelect = _r.onSelect, autoFillHeight = _r.autoFillHeight, useMobileUI = _r.useMobileUI, // Aug
columns = _r.columns, advancedFilter = _r.advancedFilter, advancedQueryFields = _r.advancedQueryFields, onImageEnlarge = _r.onImageEnlarge, offlineSchema = _r.offlineSchema, advancedFilterApi = _r.advancedFilterApi, tableLayout = _r.tableLayout, header = _r.header, footer = _r.footer, rest = tslib_1.__rest(_r, ["className", "bodyClassName", "filter", "render", "store", "mode", "syncLocation", "children", "headerBulkActions", "footerBulkActions", "pickerMode", "multiple", "showIndex", "valueField", "primaryField", "value", "hideQuickSaveBtn", "itemActions", "classnames", "keepItemSelectionOnPageChange", "maxKeepItemSelectionLength", "onAction", "popOverContainer", "translate", "onQuery", "autoGenerateFilter", "onSelect", "autoFillHeight", "useMobileUI", "columns", "advancedFilter", "advancedQueryFields", "onImageEnlarge", "offlineSchema", "advancedFilterApi", "tableLayout", "header", "footer"]);
// Aug
var mobileUI = useMobileUI && (0, helper_1.isMobile)();
var language = (0, locale_1.makeTranslator)();
var _s = this.state, foldColumns = _s.foldColumns, tableRotate = _s.tableRotate, flowModalProps = _s.flowModalProps, defaultVisible = _s.defaultVisible, multipleDefault = _s.multipleDefault, defaultList = _s.defaultList, selectTmpShow = _s.selectTmpShow, filtercont = _s.filtercont, formSwitch = _s.formSwitch, modes = _s.modes;
return (react_1.default.createElement("div", { ref: this.crudRef, className: cx('Crud', className, {
'is-loading': !mobileUI && store.loading,
tableRotate: tableRotate
}) },
react_1.default.createElement(mobx_react_1.Provider, { tableCtxMenuStore: tableCtxMenuStore_1.default },
(!(0, helper_1.isMobile)() || (0, utils_2.headerCanShow)(header, filter, filtercont, this.tableStore)) &&
react_1.default.createElement("div", { className: cx('Crud-head') },
header && !(0, helper_1.isMobile)() ? render('alert', header, { style: { marginBottom: this.hasToolBars ? 'unset' : '8px' }, cx: cx, pageUniqueMark: this.props.name + 'header', data: store.data }) : null,
!mobileUI && this.renderFilter()),
(((0, utils_2.hasBulkActions)({
headerBulkActions: this.props.headerBulkActions,
footerBulkActions: this.props.footerBulkActions,
itemActions: this.props.itemActions
}, store, this.tableStore)) ||
multiple) &&
keepItemSelectionOnPageChange &&
!mobileUI
? this.renderSelection()
: null,
render('body', tslib_1.__assign(tslib_1.__assign({}, rest), { foldColumns: foldColumns, columns: (_a = store.columns) !== null && _a !== void 0 ? _a : columns, type: modes, setLoading: this.setLoading, tableLayout: (0, helper_1.isMobile)() ? tableLayout : 'horizontal' }), {
key: 'body',
foldColumns: foldColumns,
tipsHeader: this.props.header,
tipsFooter: this.props.footer,
className: cx('Crud-body', bodyClassName),
ref: this.controlRef,
autoGenerateFilter: !filter && autoGenerateFilter,
autoFillHeight: autoFillHeight,
selectable: !!(((0, utils_2.hasBulkActions)({
headerBulkActions: this.props.headerBulkActions,
footerBulkActions: this.props.footerBulkActions,
itemActions: this.props.itemActions
}, store, this.tableStore) ||
pickerMode ||
multiple) // Jay multiple true 显示勾选框
),
itemActions: itemActions,
multiple: multiple === void 0
? (headerBulkActions && headerBulkActions.length > 0) ||
(footerBulkActions && footerBulkActions.length > 0)
? true
: false
: multiple,
selected: pickerMode || keepItemSelectionOnPageChange
? store.selectedItems
: undefined,
keepItemSelectionOnPageChange: keepItemSelectionOnPageChange,
showIndex: showIndex,
maxKeepItemSelectionLength: maxKeepItemSelectionLength,
valueField: valueField || primaryField,
primaryField: primaryField,
hideQuickSaveBtn: hideQuickSaveBtn,
items: store.data.items,
itemsRaw: store.data.itemsRaw,
query: store.query,
orderBy: store.query.orderBy,
orderDir: store.query.orderDir,
popOverContainer: popOverContainer,
setChildStore: store.setChildStore,
onAction: this.handleAction,
onSave: this.handleSave,
dataCheckRegist: this.dataCheckRegist,
onSaveOrder: this.handleSaveOrder,
onQuery: this.handleQuery,
onSelect: this.handleSelect,
onPopOverOpened: this.handleChildPopOverOpen,
onPopOverClosed: this.handleChildPopOverClose,
onSearchableFromReset: this.handleFilterReset,
onSearchableFromSubmit: this.handleFilterSubmit,
onSearchableFromInit: this.handleFilterInit,
headerToolbarRender: this.renderHeaderToolbar,
footerToolbarRender: this.renderFooterToolbar,
crudRenderToolbarFunc: this.renderToolbar,
bulkActionRender: this.bulkActionRender,
markSort: this.markSort,
// chencicsy
data: store.mergedData,
// Aug
filterRender: this.renderFilter,
onLoadMore: this.handleLoadMore,
handleResetData: this.handleResetData,
loadHasMore: (((_b = store.data.items) === null || _b === void 0 ? void 0 : _b.length) > 0 && store.data.total > 0 && store.data.total > store.data.items.length) ||
(!((_c = store.data.items) === null || _c === void 0 ? void 0 : _c.length) && store.loading) ||
!!((store.data.total || store.data.count) && !(store.page > store.lastPage ||
((_d = store.data.items) === null || _d === void 0 ? void 0 : _d.length) >=
((_e = store.data.total) !== null && _e !== void 0 ? _e : store.data.count))),
// Jay
placeholder: rest.placeholder ||
(!this.props.initFetch && !this.state.hasFetch && filter
? 'placeholder.trySearch'
: undefined),
saveColApi: this.props.saveColApi,
crudName: this.props.name,
columnInfo: this.props.columnInfo,
setBorder: this.props.setBorder,
getTableStore: this.getTableStore,
getTableInstance: this.getTableInstance,
setLoading: this.setLoading,
setTotal: this.setTotal,
showColumnsFilter: this.state.showColumnsFilter,
preSortAble: this.props.preSortAble,
loading: store.loading,
headerBulkActions: (0, helper_1.isMobile)() ? (0, utils_2.unitBulkActions)({
headerActions: this.props.headerActions,
headerToolbar: this.props.headerToolbar,
headerBulkActions: this.props.headerBulkActions
}) : headerBulkActions,
footerBulkActions: footerBulkActions,
clearSelectedItems: this.clearSelectedItems,
tableRotate: tableRotate,
handleTableRotate: this.handleTableRotate,
handleClickOffline: this.handleClickOffline,
offlineSchema: offlineSchema,
autoWidth: this.state.autoWidth,
handleJump: this.handleJump,
tabsdefer: this.props.tabsdefer,
filterData: filtercont,
changeSelectedRow: this.changeSelectedRow,
getAllData: this.getAllData,
// originColumns: columns,
currentSelectedRow: this.currentSelectedRow,
/** 透传store给ai-tool */
storeForAiTool: store,
renderAggregate: this.renderAggregate,
headerCanShow: (0, utils_2.headerCanShow)(header, filter, filtercont, this.tableStore),
crudRef: this.crudRef,
afterSearchFn: this.afterSearchFn,
}),
footer && !(0, helper_1.isMobile)() ? render('alert', footer, { cx: cx, pageUniqueMark: this.props.name + 'footer', data: store.data }) : null,
react_1.default.createElement(components_1.Spinner, { overlay: true, size: this.props.formStore ? undefined : 'md', key: "info", show: store.loading || store.filterLoading, className: "".concat(tableRotate ? 'horizontal-mode' : '') }),
this.state.printType && (react_1.default.createElement(LabelPrint_1.ModalPrint, tslib_1.__assign({ printType: this.state.printType }, this.props, this.state.ModalProps, { columns: (_g = (_f = this.tableStore) === null || _f === void 0 ? void 0 : _f.filteredColumns) !== null && _g !== void 0 ? _g : this.props.columns, query: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, store.query), this.state.filtercont), { advancedFilter: (_j = (_h = this.state.filtercont) === null || _h === void 0 ? void 0 : _h.advancedFilter) === null || _j === void 0 ? void 0 : _j.filter(function (item) { return !_this.advancefilterValueIsLegalEmptyValue(item); }) }), orderParam: (_k = this.tableStore) === null || _k === void 0 ? void 0 : _k.orderColumnsParam() }))),
react_1.default.createElement(Workflow_1.default, tslib_1.__assign({ visible: this.state.flowModalVisible, onClose: function (reload) {
_this.setState({ flowModalVisible: false, flowModalProps: { flowDetail: undefined } });
if (reload) {
_this.search(undefined, undefined, true, true);
}
}, env: this.props.env, render: this.props.render, onImageEnlarge: onImageEnlarge, language: language, classnames: cx }, flowModalProps)),
(filter || advancedFilter) ?
(0, helper_1.isMobile)() ? react_1.default.createElement(antdComponentsProxy_1.Drawer, { visible: this.state.advancedFilterVisible, placement: "bottom", height: "100%", zIndex: this.props.isPick ? 1012 : 1011, forceRender: true, className: "".concat(advancedFilter ? 'drawer-advanced' : "row-edit-drawer"), closable: false, getContainer: this.props.env.getTopModalContainer, onClose: function () { return _this.hideAdvancedFilter(); }, footer: advancedFilter ?
this.state.advancedFilterAction ? react_1.default.createElement(react_1.default.Fragment, null, this.renderAdvancedModalFooter()) : this.renderAdvancedFilterAction :
react_1.default.createElement(antd_1.Button, { onClick: function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
this.handleScrollToTop();
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
// 将关闭Drawer逻辑放在查询逻辑之后
return [4 /*yield*/, this.handleFilterSubmit(this.filterForm.props.data)];
case 2:
// 将关闭Drawer逻辑放在查询逻辑之后
_b.sent();
this.hideAdvancedFilter();
return [3 /*break*/, 4];
case 3:
_a = _b.sent();
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); }, type: 'primary' }, __('search')), bodyStyle: { padding: 0 }, footerStyle: { background: 'var(--saas-main-bg)' } }, advancedFilter ? react_1.default.createElement(react_1.default.Fragment, null, this.handleAdvanced()) :
react_1.default.createElement(react_1.default.Fragment, null,
this.editHeader(),
render('filter', tslib_1.__assign(tslib_1.__assign({ type: 'form' }, filter), { title: '', api: null }), {
className: 'Form-advanced is-mobile',
data: store.filterData,
onReset: this.handleFilterReset,
onSubmit: this.handleFilterSubmit,
// onInit: this.handleFilterInit,
formStore: null,
getFilterForm: this.getFilterForm,
handleFilterAdvanced: this.handleFilterAdvanced,
advancedFilter: this.props.advancedFilter,
advancedFilterApi: advancedFilterApi,
filtercont: this.state.filtercont,
filtertpl: this.state.filtertpl,
filterMap: (_l = this.tableStore) === null || _l === void 0 ? void 0 : _l.filterColumns,
handleFilterOptions: this.handleFilterOptions,
handledelVisible: this.handledelVisible,
handleReset: this.handleReset
}))) : (react_1.default.createElement(react_1.default.Fragment, null, (react_1.default.createElement(antd_1.Modal, { zIndex: 9, title: this.renderAdvancedModalHeader(), width: 1000, className: 'Modal-advanced common-modal-component', bodyStyle: { overflowY: 'auto' }, maskClosable: false, visible: this.state.advancedFilterVisible, onCancel: this.hideAdvancedFilter, getContainer: this.props.env.getTopModalContainer, footer: react_1.default.createElement(react_1.default.Fragment, null,
react_1.default.createElement("span", { style: { display: 'inline-block', marginRight: 10 } },
react_1.default.createElement(Button_1.default, { size: 'sm', onClick: this.hideAdvancedFilter }, this.props.translate('cancel'))),
react_1.default.createElement(Button_1.default, { size: 'sm', level: "primary", onClick: this.handleAdvanceSearch }, this.props.translate('confirm'))) }, this.handleAdvanced()))
// (<DragModal
// title={__('CRUD.advancedFilter') + (advancedTitle ? ` - ${advancedTitle}` : '')}
// className={'Modal-advanced common-modal-component'}
// width={1100}
// minWidth={800}
// minHeight={400}
// bounds="window"
// dialogVisible={this.state.advancedFilterVisible}
// mask={true}
// hide={!this.state.advancedFilterVisible}
// onCancel={this.hideAdvancedFilter}
// // getContainer={this.props.env.getTopModalContainer}
// getContainer={(this.props.env.container ?? this.props.env.getModalContainer) as () => HTMLElement}
// footer={<>{this.renderAdvancedModalFooter()} </>}
// resizeable={true}
// modalZIndex={9}
// heightFitContent={true}
// destroyOnClose={false}
// showMinTitle={false}
// centered
// initOffset={{ y: 10}}
// >
// {this.handleAdvanced()}
// </DragModal>)
))
: null,
react_1.default.createElement(DefaultListPopup_1.default, { onCancel: function () { return _this.setState({ defaultVisible: false }); }, defaultVisible: defaultVisible, defaultList: defaultList, defaultOnOk: this.defaultOnOk, defaultClose: this.defaultClose, defaultDelete: this.defaultDelete, multipleDefault: multipleDefault, onChange: function (tempName) { return _this.setState({ multipleDefault: tempName }); }, props: this.props, defaultModify: this.defaultModify, selectTmpShow: selectTmpShow, onDrawerCancel: function () { return _this.setState({ selectTmpShow: false }); }, defaultAdvancedQuery: this.defaultAdvancedQuery }),
react_1.default.createElement(SecondFilterDrawer_1.SecondFilterDrawer, { visible: this.state.filterDrawerVisible, showColumnsFilter: this.state.showColumnsFilter, columns: (_o = (_m = this.tableStore) === null || _m === void 0 ? void 0 : _m.filteredColumns.map(function (column) { return ({ type: column.type, name: column.name, label: (0, commonTableFunction_1.getColumnShowLabel)(column), map: column.map, format: column.pristine.valueFormat }); })) !== null && _o !== void 0 ? _o : [], filterMap: (_q = (_p = this.tableStore) === null || _p === void 0 ? void 0 : _p.filterColumns) !== null && _q !== void 0 ? _q : new Map(), getContainer: this.props.env.getModalContainer, crudName: this.props.name, onClose: function () { return _this.setState({ filterDrawerVisible: false }); }, onCheckedChange: function (checked, filterMap, caseSensitive) {
var _a, _b, _c;
_this.setState({ showColumnsFilter: checked });
checked ? (_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.update({ filterColumns: filterMap }) : (_b = _this.tableStore) === null || _b === void 0 ? void 0 : _b.filterColumns.clear();
var items = (_c = _this.tableStore) === null || _c === void 0 ? void 0 : _c.handleMutilSort(_this.props.loadDataOnce, caseSensitive);
if (_this.props.loadDataOnce && Array.isArray(items))
_this.setTotal(items.length);
if (_this.props.itemAction) {
var ctx = (0, helper_1.createObject)(store.query, items[0], {}, true);
_this.handleAction(undefined, _this.props.itemAction, ctx);
}
}, onConfirm: function (filterMap, caseSensitive) {
var _a, _b;
(_a = _this.tableStore) === null || _a === void 0 ? void 0 : _a.update({ filterColumns: filterMap });
_this.setState({ filterDrawerVisible: false });
var items = (_b = _this.tableStore) === null || _b === void 0 ? void 0 : _b.handleMutilSort(_this.props.loadDataOnce, caseSensitive);
if (_this.props.loadDataOnce && Array.isArray(items))
_this.setTotal(items.length);
if (_this.props.itemAction) {
var ctx = (0, helper_1.createObject)(store.query, items[0], {}, true);
_this.handleAction(undefined, _this.props.itemAction, ctx);
}
}, translate: __, classPrefix: this.props.classPrefix, classnames: cx }),
offlineSchema && react_1.default.createElement(Offline_1.default, { offlineMode: this.state.offlineMode, offlineSchema: offlineSchema, store: store, render: render, env: this.props.env, aliasTitle: this.props.aliasTitle, menuName: this.props.menuName, primaryField: primaryField, name: this.props.name, filtercont: this.state.filtercont, translate: this.props.translate, classPrefix: this.props.classPrefix, columns: this.props.columns, tableLayout: tableLayout, search: this.search, curdRef: this.crudRef }),
!(0, helper_1.isMobile)() && this.state.staticExportShow && react_1.default.createElement(antd_1.Modal, { title: react_1.default.createElement("div", { className: 'dialog-title' },
react_1.default.createElement("div", { className: 'disabled-move-title' }, "\u6587\u4EF6\u5BFC\u51FA")), className: 'common-modal-component', visible: this.state.staticExportShow, closable: false, okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88", width: 320, style: { top: 200 }, maskClosable: false, bodyStyle: { padding: '8 16' }, onCancel: function () {
_this.setState({ staticExportShow: false });
}, zIndex: 1011, onOk: this.props.mode === 'cross' ? this.handleExportCross : this.handleExportStatic, getContainer: this.props.env.getModalContainer },
react_1.default.createElement("div", null,
react_1.default.createElement("div", null,
react_1.default.createElement("div", { style: { marginBottom: '4px' } }, "\u5BFC\u51FA\u8303\u56F4"),
react_1.default.createElement(antd_1.Select, { style: { width: '100%' }, options: [{ label: '当前页数据', value: '0' }, { label: '选中数据', value: '1' }, { label: '全部数据', value: '2' }], placeholder: __('Select.placeholder'), value: this.state.staticExportRange, onChange: function (value) { return _this.setState({ staticExportRange: value }); } })),
react_1.default.createElement("div", { style: { marginTop: '16px' } },
react_1.default.createElement("div", { style: { marginBottom: '4px' } }, "\u6570\u636E\u683C\u5F0F"),
react_1.default.createElement("div", null,
react_1.default.createElement(antd_1.Select, { style: { width: '100%' }, options: [{ label: '保留数据格式', value: '1' }, { label: '导出为原始数据', value: '0' }], placeholder: '\u5BFC\u51FA\u65B9\u5F0F', value: this.state.keepDataFormat, onChange: function (type) { return _this.setState({ keepDataFormat: type }); } }))))),
this.props.store.dialogOpen ?
render('dialog', tslib_1.__assign(tslib_1.__assign({}, (store.action &&
store.action.dialog)), { type: 'dialog' }), {
key: 'dialog',
data: store.dialogData,
onConfirm: this.handleDialogConfirm,
onClose: this.handleDialogClose,
show: store.dialogOpen,
replace: store.replace
}) : null,
this.props.store.drawerOpen ?
render('drawer', tslib_1.__assign(tslib_1.__assign({}, (store.action &&
store.action.drawer)), { type: 'drawer' }), {
key: 'drawer',
data: store.drawerData,
onConfirm: this.handleDrawerConfirm,
onClose: this.handleDrawerClose,
show: store.drawerOpen,
onAction: this.handleAction,
}) : null)));
};
CRUD.propsList = [
'headerBulkActions',
'footerBulkActions',
'itemActions',
'mode',
'orderField',
'syncLocation',
'toolbar',
'toolbarInline',
'messages',
'value',
'options',
'multiple',
'valueField',
'defaultParams',
'bodyClassName',
'perPageAvailable',
'pageField',
'perPageField',
'hideQuickSaveBtn',
'autoJumpToTopOnPagerChange',
'interval',
'silentPolling',
'stopAutoRefreshWhen',
'stopAutoRefreshWhenModalIsOpen',
'api',
'affixHeader',
'columnsTogglable',
'placeholder',
'tableClassName',
'headerClassName',
'footerClassName',
// 'toolbarClassName',
'headerToolbar',
'footerToolbar',
'filterTogglable',
'filterDefaultVisible',
'autoGenerateFilter',
'syncResponse2Query',
'keepItemSelectionOnPageChange',
'labelTpl',
'labelField',
'loadDataOnce',
'loadDataOnceFetchOnFilter',
'source',
'header',
'columns',
'size',
'onChange',
'onInit',
'onSaved',
'onQuery',
'formStore',
'autoFillHeight',
'preSortAble',
'showIndex'
];
CRUD.defaultProps = {
toolbarInline: true,
headerToolbar: ['headerBulkActions'],
footerToolbar: [],
primaryField: 'id',
syncLocation: true,
pageField: 'page',
perPageField: 'perPage',
hideQuickSaveBtn: false,
autoJumpToTopOnPagerChange: true,
silentPolling: false,
filterTogglable: false,
filterDefaultVisible: true,
loadDataOnce: false,
loadDataOnceFetchOnFilter: true,
autoFillHeight: true,
infinteLoad: (0, helper_1.isMobile)(),
setBorder: true,
preSortAble: true,
tableLayout: 'horizontal',
showIndex: false
};
return CRUD;
}(react_1.default.Component));
exports.default = CRUD;
var CRUDRenderer = /** @class */ (function (_super) {
tslib_1.__extends(CRUDRenderer, _super);
function CRUDRenderer(props, context) {
var _this = this;
var _a, _b;
_this = _super.call(this, props) || this;
var scoped = context;
sub_1.EventSub.emit(sub_1.EventEnum.ClearMappingAcahe, (_a = _this === null || _this === void 0 ? void 0 : _this.props) === null || _a === void 0 ? void 0 : _a.name);
sub_1.EventSub.emit(sub_1.EventEnum.ClearSelectCache, (_b = _this === null || _this === void 0 ? void 0 : _this.props) === null || _b === void 0 ? void 0 : _b.name);
scoped.registerComponent(_this);
return _this;
}
CRUDRenderer.prototype.componentWillUnmount = function () {
_super.prototype.componentWillUnmount.call(this);
var scoped = this.context;
scoped.unRegisterComponent(this);
// 卸载的时候清除定时器
clearTimeout(this.state.showFilterTimer);
};
CRUDRenderer.prototype.reload = function (subpath, query, ctx, isItemAction) {
var scoped = this.context;
if (subpath) {
return scoped.reload(query ? "".concat(subpath, "?").concat((0, helper_1.qsstringify)(query)) : subpath, ctx);
}
return _super.prototype.reload.call(this, subpath, query, ctx, isItemAction);
};
CRUDRenderer.prototype.receive = function (values, subPath) {
var scoped = this.context;
if (subPath) {
return scoped.send(subPath, values);
}
return _super.prototype.receive.call(this, values);
};
CRUDRenderer.prototype.reloadTarget = function (target, data) {
var scoped = this.context;
scoped.reload(target, data);
};
CRUDRenderer.prototype.closeTarget = function (target) {
var scoped = this.context;
scoped.close(target);
};
var _a;
CRUDRenderer.contextType = Scoped_1.ScopedContext;
CRUDRenderer = tslib_1.__decorate([
(0, factory_1.Renderer)({
type: 'crud',
storeType: crud_1.CRUDStore.name,
isolateScope: true
}),
tslib_1.__metadata("design:paramtypes", [Object, typeof (_a = typeof Scoped_1.IScopedContext !== "undefined" && Scoped_1.IScopedContext) === "function" ? _a : Object])
], CRUDRenderer);
return CRUDRenderer;
}(CRUD));
exports.CRUDRenderer = CRUDRenderer;
//# sourceMappingURL=./renderers/CRUD.js.map