fastlion-amis
Version:
一种MIS页面生成工具
931 lines (930 loc) • 113 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CRUDRenderer = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, 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 = (0, tslib_1.__importDefault)(require("../components/Button"));
var filter_schema_1 = (0, tslib_1.__importDefault)(require("../utils/filter-schema"));
var pick_1 = (0, tslib_1.__importDefault)(require("lodash/pick"));
var react_dom_1 = require("react-dom");
var tpl_1 = require("../utils/tpl");
var api_1 = require("../utils/api");
var omit_1 = (0, tslib_1.__importDefault)(require("lodash/omit"));
var find_1 = (0, tslib_1.__importDefault)(require("lodash/find"));
var findIndex_1 = (0, tslib_1.__importDefault)(require("lodash/findIndex"));
var Html_1 = (0, tslib_1.__importDefault)(require("../components/Html"));
var components_1 = require("../components");
var icons_1 = require("../components/icons");
var tpl_builtin_1 = require("../utils/tpl-builtin");
// Jay
var LabelPrint_1 = require("./Lion/LabelPrint");
var Workflow_1 = (0, tslib_1.__importDefault)(require("./Lion/Workflow"));
var print_1 = require("../utils/print");
var LodopFuncs_1 = require("../utils/print/LodopFuncs");
var ExpressPrint_1 = require("./Lion/ExpressPrint/ExpressPrint");
var select_1 = (0, tslib_1.__importDefault)(require("antd/lib/select"));
var modal_1 = (0, tslib_1.__importDefault)(require("antd/lib/modal"));
var message_1 = (0, tslib_1.__importDefault)(require("antd/lib/message"));
var ActionSheet_1 = (0, tslib_1.__importDefault)(require("../components/Lion/ActionSheet"));
var utils_1 = require("./Lion/utils/utils");
var util_1 = require("../utils/print/util");
var Submission_1 = (0, tslib_1.__importDefault)(require("./Lion/Submission"));
var CRUD = /** @class */ (function (_super) {
(0, tslib_1.__extends)(CRUD, _super);
function CRUD(props) {
var _this = _super.call(this, props) || this;
_this.sort = false;
_this.saveData = new Map();
_this.filterData = {};
_this.markSort = function () {
_this.sort = true;
};
// 上拉加载更多数据
_this.lionPullRequest = function (values, init) {
return new Promise(function (resolve, reject) {
var _a;
var _b = _this.props, defaultParams = _b.defaultParams, data = _b.data, store = _b.store;
var _c = _this.props, syncLocation = _c.syncLocation, pageField = _c.pageField, perPageField = _c.perPageField;
values = syncLocation
? (0, helper_1.qsparse)((0, helper_1.qsstringify)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultParams), values), store.query), undefined, true))
: values;
store.changePage(init ? store.page : (store.page + 1), _this.props.perPage);
store.updateQuery((0, tslib_1.__assign)((0, 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 () {
_this.search({ page: _this.props.store.page + 1, loadDataMode: 'load-more' });
};
_this.renderAdvancedModalFooter = 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 () {
var _a;
(_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.resetAdvancedFilter();
} }, _this.props.translate('reset'))),
react_1.default.createElement(Button_1.default, { level: "primary", onClick: function () {
var _a;
var queryParams = (_a = _this.advanceFilterForm) === null || _a === void 0 ? void 0 : _a.confirmAdvancedFilter();
var _b = queryParams.filterOptionData, isChecked = _b.isChecked, optionsParam = _b.optionsParam;
var itemCount = optionsParam.itemCount, itemSumCount = optionsParam.itemSumCount, showFields = optionsParam.showFields, sortFields = optionsParam.sortFields, groupByFields = optionsParam.groupByFields;
if (!itemCount && !itemSumCount) {
if (!isChecked) {
message_1.default.warning('显示字段不能为空');
return;
}
}
if (sortFields.length > 0 && groupByFields.length > 0) {
var temp = true;
var _loop_1 = function (i) {
var sortField = sortFields[i];
var include = showFields.some(function (showField) { return sortField.includes(showField); });
if (!include) {
temp = false;
return "break";
}
};
for (var i = 0; i < sortFields.length; i++) {
var state_1 = _loop_1(i);
if (state_1 === "break")
break;
}
if (!temp) {
message_1.default.warning('同时使用排序和分组时,排序字段必须出现在显示字段中');
return;
}
}
_this.props.store.updateQuery(queryParams);
_this.setState({ filtercont: queryParams }, function () {
_this.handlefilters();
_this.search(undefined, undefined, undefined, true, function (res) {
if (optionsParam.itemCount) {
if (res.status === 0) {
modal_1.default.info({ icon: null, title: '提示', content: "\u9879\u6570: " + res.data.total + " ", okText: '确定' });
}
}
}, undefined, undefined, queryParams);
});
_this.hideAdvancedFilter();
} }, _this.props.translate('confirm')));
_this.state = {
printType: undefined,
flowModalVisible: false,
hasFetch: false,
ModalProps: {
show: false,
onHide: null
},
advancedFilterVisible: false,
moreIsOpened: false,
isRequestItem: false,
foldColumns: [],
filtercont: {},
filterOptions: {},
filtertpl: [],
transferSubmission: {},
submissionModal: false //表单送签弹窗
};
_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.handleDialogClose = _this.handleDialogClose.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.handleQuery = _this.handleQuery.bind(_this);
_this.renderHeaderToolbar = _this.renderHeaderToolbar.bind(_this);
_this.renderFooterToolbar = _this.renderFooterToolbar.bind(_this);
_this.clearSelection = _this.clearSelection.bind(_this);
//aug
_this.renderFilter = _this.renderFilter.bind(_this);
// Jay
_this.pageSwitchRef = react_1.default.createRef();
_this.dom = react_1.default.createRef();
_this.handleFilterAdvanced = _this.handleFilterAdvanced.bind(_this);
_this.hideAdvancedFilter = _this.hideAdvancedFilter.bind(_this);
_this.getTableStore = _this.getTableStore.bind(_this);
_this.getTableInstance = _this.getTableInstance.bind(_this);
_this.getFilterColumns = _this.getFilterColumns.bind(_this);
// chencicsy 多列排序
_this.handleMutilSort = _this.handleMutilSort.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: []
});
}
return _this;
}
CRUD.prototype.componentDidMount = function () {
var store = this.props.store;
var useMobileUI = this.props.useMobileUI;
var mobileUI = (0, helper_1.isMobile)() && useMobileUI;
if (this.props.perPage) {
store.changePage(store.page, this.props.perPage);
}
if (!this.props.filter || (store.filterTogggable && !store.filterVisible)) {
this.handleFilterInit({});
}
else if (mobileUI) {
this.handleFilterInit({});
}
var val;
if (this.props.pickerMode && (val = (0, helper_1.getPropValue)(this.props))) {
store.setSelectedItems(val);
}
};
CRUD.prototype.componentDidUpdate = function (prevProps) {
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 && ((_a = props.data) === null || _a === void 0 ? void 0 : _a.items.length) && this.handleAction(undefined, props.itemAction, props.data.items[0], undefined, undefined, true);
}
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;
clearTimeout(this.timer);
};
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;
if (throwErrors === void 0) { throwErrors = false; }
if (isItemAction === void 0) { isItemAction = false; }
var _l = this.props, onAction = _l.onAction, store = _l.store, messages = _l.messages, pickerMode = _l.pickerMode, env = _l.env, pageField = _l.pageField, stopAutoRefreshWhenModalIsOpen = _l.stopAutoRefreshWhenModalIsOpen;
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;
}
if (action.actionType === 'dialog') {
store.setCurrentAction(action);
var idx = ctx.index;
var length = store.items.length;
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
store.openDialog(ctx, {
hasNext: idx < length - 1,
nextIndex: idx + 1,
hasPrev: idx > 0,
prevIndex: idx - 1,
index: idx
});
}
else if (action.actionType === 'ajax') {
store.setCurrentAction(action);
var data = ctx;
// 由于 ajax 一段时间后再弹出,肯定被浏览器给阻止掉的,所以提前弹。
var redirect = action.redirect && (0, tpl_1.filter)(action.redirect, data);
redirect && action.blank && env.jumpTo(redirect, action);
return store
.saveRemote(action.api, data, {
successMessage: (action.messages && action.messages.success) ||
(messages && messages.saveSuccess),
errorMessage: (action.messages && action.messages.failed) ||
(messages && messages.saveFailed)
})
.then(function (payload) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var data, redirect;
var _a;
return (0, tslib_1.__generator)(this, function (_b) {
switch (_b.label) {
case 0:
data = (0, helper_1.createObject)(ctx, payload);
// Jay 菜鸟预览 预览按钮是放在操作列,actionType 为 'ajax',根据状态码判断
if (((_a = data) === null || _a === void 0 ? void 0 : _a.status) === 20002) {
(0, ExpressPrint_1.expressLabels)(data, env.fetcher, this.props.translate, true);
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:
_b.sent();
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
_b.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);
action.close && this.closeTarget(action.close);
return [2 /*return*/, null];
}
});
}); })
.catch(function () { });
}
else if (pickerMode &&
(action.actionType === 'confirm' || action.actionType === 'submit')) {
store.setCurrentAction(action);
return Promise.resolve({
items: store.selectedItems.concat()
});
}
else if (action.onClick) {
store.setCurrentAction(action);
var onClick = action.onClick;
if (typeof onClick === 'string') {
onClick = (0, api_1.str2function)(onClick, 'event', 'props', 'data');
}
onClick && onClick(e, this.props, ctx);
}
else if (action.actionType === 'label-design') {
(0, print_1.templateDesign)(ctx, function (value) {
modal_1.default.confirm({
title: '确认提交该模板吗?',
okText: '确认',
cancelText: '取消',
getContainer: env.getModalContainer,
onOk: function () {
if (action.api) {
var labelTemplate = (0, util_1.buildLabelTemplate)(value);
var tableFields = labelTemplate.labelTables.map(function (table) { var _a; return (_a = table.fieldName) !== null && _a !== void 0 ? _a : ''; }).join(',');
env.fetcher(action.api, {
tableFields: tableFields,
tempId: ctx.TEMP_ID,
content: value
}).then(function (res) {
if (res.status === 0) {
message_1.default.success(res.msg);
// 重新获取数据列表
_this.search(undefined, undefined, true, true);
}
else {
message_1.default.error(res.msg);
}
});
}
}
});
});
}
else if (action.actionType === 'export') {
store.setCurrentAction(action);
var exportData = {};
var _ids_1 = '';
var _selectedItems = (_e = (_d = (_c = this.props) === null || _c === void 0 ? void 0 : _c.store) === null || _d === void 0 ? void 0 : _d.selectedItems) === null || _e === void 0 ? void 0 : _e.toJSON();
_selectedItems.map(function (_select) {
_ids_1 += _select.hasOwnProperty(_this.props.primaryField) ? _select[_this.props.primaryField] + ',' : '';
});
exportData = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, exportData), (_g = (_f = this.props) === null || _f === void 0 ? void 0 : _f.store) === null || _g === void 0 ? void 0 : _g.query);
exportData.selectedItems = _selectedItems;
exportData.primaryField = this.props.primaryField;
exportData.ids = _ids_1.slice(0, _ids_1.length - 1);
exportData.tempIds = ctx[this.props.primaryField];
var exportSetColumnFields_1 = [];
(_h = this.tableInstance) === null || _h === void 0 ? void 0 : _h.sortCols.forEach(function (col) {
if (!col.hidden && col.name) {
exportSetColumnFields_1.push(col.name);
}
});
exportData.exportSetColumnFields = exportSetColumnFields_1;
var orderBy = (_j = this.tableStore) === null || _j === void 0 ? void 0 : _j.orderColumnsParam();
orderBy && (exportData.orderParam = { orderBy: orderBy });
store.openLionExport((0, tslib_1.__assign)((0, tslib_1.__assign)({}, exportData), ctx), env, undefined, function (isReload) {
if (isReload) {
action.reload && _this.reloadTarget(action.reload, {});
}
});
return false;
}
else if (action.actionType === 'loginAmazon') {
store.setCurrentAction(action);
store.openAmazonLoginPage(ctx, env);
}
else if (action.actionType === 'label-print' || action.actionType === 'bill-print') {
// Jay
store.setCurrentAction(action);
var primaryField = this.props.primaryField;
var __ = this.props.translate;
var LODOP = (0, LodopFuncs_1.getLodop)();
if (LODOP) {
this.setState({
ModalProps: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, action), { show: true, isRow: true, ctx: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, ctx), { primaryField: primaryField }), onHide: function () { _this.setState({ printType: undefined }); } }),
printType: action.actionType === 'label-print' ? 'label' : 'bill',
});
}
}
else if (action.actionType === 'bpm_detail') {
if (action.api) {
env.fetcher(action.api, ctx).then(function (res) {
if (res.status === 0) {
_this.flowModalProps = { flowDetail: res.data, ctx: ctx };
_this.setState({ flowModalVisible: true });
}
else {
message_1.default.error(res.msg);
}
});
}
}
else if (action.actionType === 'bpm_submit') {
if (action.api) {
env.fetcher(action.api, ctx).then(function (res) {
if (res.status === 0) {
_this.setState({
transferSubmission: { submission: res.data, ctx: ctx },
submissionModal: true
});
}
else {
message_1.default.error(res.msg);
}
}).catch(function (res) {
});
}
}
else if (action.actionType === 'batch-image-view') {
// Aug 批量查看图片
var onImageEnlarge = this.props.onImageEnlarge;
if (!onImageEnlarge)
return;
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 (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var onImageEnlarge, baseURL, prints;
var _a, _b;
return (0, 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);
}
});
this.openImageEnlarge(prints, baseURL, onImageEnlarge);
return [2 /*return*/];
});
}); })
.catch(function () { });
}
else if ((_k = action.actionType) === null || _k === void 0 ? void 0 : _k.includes('scale')) {
var foldColumns = this.state.foldColumns;
if (foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.includes(action.actionType)) {
var newFoldCols = foldColumns === null || foldColumns === void 0 ? void 0 : foldColumns.filter(function (col) { return col != action.actionType; });
this.setState({ foldColumns: newFoldCols });
}
else {
this.setState({ foldColumns: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], foldColumns, true), [action.actionType], false) });
}
}
else {
onAction(e, action, ctx, throwErrors, delegate || this.context);
}
};
// 打开预览组件
CRUD.prototype.openImageEnlarge = function (data, baseURL, onImageEnlarge) {
var isNotImg = false;
var list = data.map(function (item) {
isNotImg = !(0, utils_1.isImg)(item.name);
return {
src: isNotImg ? (0, utils_1.getMediaIcon)(item.name) : baseURL + (item.thumbnailAddr || (item === null || item === void 0 ? void 0 : item.addr)),
originalSrc: baseURL + item.preview,
downloadSrc: baseURL + (item === null || item === void 0 ? void 0 : item.addr),
title: item.name || '',
isNotImg: isNotImg
};
});
onImageEnlarge && onImageEnlarge({
src: list[0].src,
originalSrc: list[0].originalSrc,
index: 0,
list: list
});
};
CRUD.prototype.handleBulkAction = function (selectedItems, unSelectedItems, e, action) {
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;
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, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, selectedItems[0]), { rows: selectedItems, items: selectedItems, unSelectedItems: unSelectedItems, ids: ids }));
var fn = function () {
if ((action === null || action === void 0 ? void 0 : action.actionType) === 'dialog') {
return _this.handleAction(e, (0, tslib_1.__assign)((0, 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 (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var data, redirect;
var _a;
var _b;
return (0, tslib_1.__generator)(this, function (_c) {
switch (_c.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:
_c.sent();
stopAutoRefreshWhenModalIsOpen && clearTimeout(this.timer);
_c.label = 2;
case 2:
// Jay 菜鸟打印 打印按钮是bulkActions,actionType 为 'ajax',根据状态码判断
if (((_b = data) === null || _b === void 0 ? void 0 : _b.status) === 20001) {
(0, ExpressPrint_1.expressLabels)(data, env.fetcher, this.props.translate);
}
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 undefined;
};
if (action.confirmText && env.confirm) {
env
.confirm((0, tpl_1.filter)(action.confirmText, ctx))
.then(function (confirmed) { return confirmed && fn(); });
}
else {
fn();
}
};
CRUD.prototype.handleItemAction = function (action, ctx) {
this.doAction(action, ctx);
};
CRUD.prototype.handleFilterInit = function (values, isChild) {
if (isChild === void 0) { isChild = false; }
var _a = this.props, defaultParams = _a.defaultParams, data = _a.data, store = _a.store;
this.handleFilterSubmit((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, defaultParams), values), store.query), false, true, this.props.initFetch !== false, isChild);
store.setPristineQuery();
var _b = this.props, pickerMode = _b.pickerMode, options = _b.options;
pickerMode &&
store.updateData({
items: options || []
});
};
CRUD.prototype.handleFilterReset = function (values) {
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;
this.search();
};
CRUD.prototype.handleFilterSubmit = function (values, jumpToFirstPage, replaceLocation, search, isChild) {
var _a;
if (jumpToFirstPage === void 0) { jumpToFirstPage = true; }
if (replaceLocation === void 0) { replaceLocation = false; }
if (search === void 0) { search = true; }
var _b = this.props, store = _b.store, syncLocation = _b.syncLocation, env = _b.env, pageField = _b.pageField, perPageField = _b.perPageField, loadDataOnceFetchOnFilter = _b.loadDataOnceFetchOnFilter;
values = syncLocation
? (0, helper_1.qsparse)((0, helper_1.qsstringify)(values, undefined, true))
: values;
store.updateQuery((0, tslib_1.__assign)((0, tslib_1.__assign)({}, values), (_a = {}, _a[pageField || 'page'] = jumpToFirstPage ? 1 : store.page, _a)), 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, undefined, undefined, isChild);
};
// 点击高级查询按钮
CRUD.prototype.handleFilterAdvanced = function () {
this.setState({ advancedFilterVisible: true });
};
CRUD.prototype.hideAdvancedFilter = function () {
this.setState({ advancedFilterVisible: false });
};
// 获取普同查寻的数据
CRUD.prototype.handleFilterOptions = function (value) {
this.setState({ filterOptions: value });
};
CRUD.prototype.handleSaveData = function (val, cont) {
this.saveData.set(val, cont);
};
// 判断是否有高级查询的数据将基础查询重置
CRUD.prototype.handleReset = function () {
var filtercont = this.state.filtercont;
if (Object.keys(filtercont).length) {
filtercont.filterParam = this.state.filterOptions.filterParam;
this.setState({ filtercont: filtercont });
}
};
// 删除高级查询条件
CRUD.prototype.handledelVisible = function (value, whole, e) {
var _this = this;
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
if (whole === void 0) { whole = false; }
e === null || e === void 0 ? void 0 : e.preventDefault();
var filtercont = (0, tslib_1.__assign)({}, this.state.filtercont);
filtercont.filterParam = this.state.filterOptions.filterParam;
if (whole) {
filtercont.advancedFilter = [];
filtercont.advancedFilterSub = [];
filtercont.advancedHeader = {};
(_d = (_c = (_b = (_a = this.dom.current) === null || _a === void 0 ? void 0 : _a.ref) === null || _b === void 0 ? void 0 : _b.ref) === null || _c === void 0 ? void 0 : _c.handlerenew) === null || _d === void 0 ? void 0 : _d.call(_c, whole);
}
else {
var head = value.name.split(".")[0];
var name_1 = value.name.split(".")[1];
if (head.includes('advancedFilter')) {
var newArr = filtercont[head].filter(function (item) { return item.field != name_1; });
filtercont[head] = newArr;
}
else {
var replacement = {};
for (var key in filtercont[head]) {
if (key !== name_1) {
replacement[key] = (_e = filtercont[head]) === null || _e === void 0 ? void 0 : _e[key];
}
}
filtercont[head] = replacement;
}
(_j = (_h = (_g = (_f = this.dom.current) === null || _f === void 0 ? void 0 : _f.ref) === null || _g === void 0 ? void 0 : _g.ref) === null || _h === void 0 ? void 0 : _h.handlerenew) === null || _j === void 0 ? void 0 : _j.call(_h, whole, value.name);
}
this.setState({
filtercont: filtercont,
}, function () {
_this.handlefilters();
});
};
// 高级查询内容展示
CRUD.prototype.handlefilters = function () {
var _this = this;
var _a, _b;
var filtertpl = [];
var advancedFilter = this.props.advancedFilter;
var filtercont = this.state.filtercont;
if (!advancedFilter)
return;
var body = advancedFilter.body;
var filters = Array.isArray(body) ? body : body
? [body] : [];
(((_a = filtercont === null || filtercont === void 0 ? void 0 : filtercont.advancedFilter) === null || _a === void 0 ? void 0 : _a.length) || ((_b = filtercont === null || filtercont === void 0 ? void 0 : filtercont.advancedFilterSub) === null || _b === void 0 ? void 0 : _b.length)) &&
(0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], filtercont === null || filtercont === void 0 ? void 0 : filtercont.advancedFilter, true), filtercont === null || filtercont === void 0 ? void 0 : filtercont.advancedFilterSub, true).forEach(function (value) {
filters.forEach(function (item) {
if (item.name.includes("advancedFilter")) {
item.body.forEach(function (items) {
var long = items.name.split(".");
if (long[long.length - 1] === value.field) {
var cop = {};
cop.value = value.values;
cop.label = items.label;
cop.name = items.name;
filtertpl.push(cop);
}
});
}
});
});
if (filtercont && Object.keys(filtercont.advancedHeader || {}).length) {
var _loop_2 = 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 cop = {};
var currentValue = _this.saveData.get(it.name);
if (currentValue) {
var currentLabel = currentValue.find(function (opp) { return opp.value == filtercont.advancedHeader[key]; });
cop.labelName = currentLabel === null || currentLabel === void 0 ? void 0 : currentLabel.label;
}
cop.value = filtercont.advancedHeader[key];
cop.label = it.placeholder;
cop.name = it.name;
filtertpl.push(cop);
}
});
}
else {
var long = items.name.split(".");
if (long[long.length - 1] === key) {
var cop = {};
var currentValue = _this.saveData.get(items.name);
if (currentValue) {
var currentLabel = currentValue.find(function (opp) { return opp.value == filtercont.advancedHeader[key]; });
cop.labelName = currentLabel === null || currentLabel === void 0 ? void 0 : currentLabel.label;
}
cop.value = filtercont.advancedHeader[key];
cop.label = items.placeholder;
cop.name = items.name;
filtertpl.push(cop);
}
}
});
}
});
};
for (var key in filtercont.advancedHeader) {
_loop_2(key);
}
}
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;
modal_1.default.warning({
title: '提示',
content: '当前表格存在已修改的数据,请先提交或放弃,再进行其他操作!',
getContainer: env.getModalContainer,
zIndex: 1020,
okText: __('confirm'),
});
};
CRUD.prototype.handleDialogConfirm = function (values, action, ctx, components, tableInstance) {
var _a, _b, _c;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var _d, store, pageField, stopAutoRefreshWhenModalIsOpen, interval, silentPolling, env, dialogAction, count, count, value, component, reload_1, reload, redirect;
var _e;
return (0, tslib_1.__generator)(this, function (_f) {
_d = this.props, store = _d.store, pageField = _d.pageField, stopAutoRefreshWhenModalIsOpen = _d.stopAutoRefreshWhenModalIsOpen, interval = _d.interval, silentPolling = _d.silentPolling, env = _d.env;
// Jay 下一个、上一个不用关闭
if (!['next', 'prev'].includes(action.actionType || '')) {
store.closeDialog(true);
}
dialogAction = store.action;
if (stopAutoRefreshWhenModalIsOpen && interval) {
this.timer = setTimeout(silentPolling ? this.silentSearch : this.search, Math.max(interval, 1000));
}
if (action.actionType === 'next' &&
typeof ctx.nextIndex === 'number' &&
store.data.items[ctx.nextIndex]) {
if (tableInstance) {
count = tableInstance.props.store.modified;
if (count > 0) {
this.showModal();
return [2 /*return*/];
}
}
return [2 /*return*/, this.handleAction(undefined, (0, tslib_1.__assign)({}, dialogAction), (0, helper_1.createObject)((0, helper_1.createObject)(store.data, {
index: ctx.nextIndex,
// Jay
// initApiDisable: 0
}), store.data.items[ctx.nextIndex]))];
}
else if (action.actionType === 'prev' &&
typeof ctx.prevIndex === 'number' &&
store.data.items[ctx.prevIndex]) {
if (tableInstance) {
count = tableInstance.props.store.modified;
if (count > 0) {
this.showModal();
return [2 /*return*/];
}
}
return [2 /*return*/, this.handleAction(undefined, (0, tslib_1.__assign)({}, dialogAction), (0, helper_1.createObject)((0, helper_1.createObject)(store.data, {
index: ctx.prevIndex,
// Jay
// initApiDisable: 0
}), store.data.items[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 = (_a = action.reload) !== null && _a !== void 0 ? _a : dialogAction.reload;
// 配置了 reload 则跳过自动更新。
reload_1 ||
this.search(dialogAction.__from ? (_e = {}, _e[pageField || 'page'] = 1, _e) : undefined, undefined, true, true);
}
else if (value &&
((value.hasOwnProperty('items') && value.items) ||
value.hasOwnProperty('ids')) &&
this.control.bulkUpdate) {
this.control.bulkUpdate(value, value.items);
}
}
}
reload = (_b = action.reload) !== null && _b !== void 0 ? _b : dialogAction.reload;
if (reload) {
this.reloadTarget(reload, ctx);
}
redirect = (_c = action.redirect) !== null && _c !== void 0 ? _c : dialogAction.redirect;
redirect = redirect && (0, tpl_1.filter)(redirect, ctx);
redirect && env.jumpTo(redirect, dialogAction);
return [2 /*return*/];
});
});
};
CRUD.prototype.handleDialogClose = function (confirmed, formInstance, tableInstance) {
var _this = this;
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) {
modal_1.default.confirm({
content: '新的修改没有保存,确认要离开?',
getContainer: env.getModalContainer,
zIndex: 1020,
okText: __('confirm'),
cancelText: __('cancel'),
onOk: function () { return _this.closeDialog(); }
});
return;
}
}
this.closeDialog();
};
CRUD.prototype.closeDialog = function () {
var _a = this.props, store = _a.store, stopAutoRefreshWhenModalIsOpen = _a.stopAutoRefreshWhenModalIsOpen, silentPolling = _a.silentPolling, interval = _a.interval;
store.closeDialog();
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
});