@aliretail/react-materials-components
Version:
307 lines (255 loc) • 9.46 kB
JavaScript
import _Drawer from "@alifd/next/es/drawer";
import _Pagination from "@alifd/next/es/pagination";
import _Table from "@alifd/next/es/table";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import ReactDOM from 'react-dom';
import cls from 'classnames';
import { callApi, getDownloadUrl } from "../utils";
var History = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(History, _React$Component);
function History() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.state = {
loading: false,
pageNo: 1,
pageSize: 20,
total: 0,
items: []
};
_this.init = function (options) {
if (options === void 0) {
options = {};
}
_this.setState(_extends({
visible: true,
loading: false,
pageNo: 1,
pageSize: 20,
total: 0,
items: [],
inputQuery: []
}, options), function () {
_this.load();
});
};
_this.toggle = function (visible) {
_this.setState({
visible: visible
});
};
_this.handleClose = function () {
_this.toggle(false);
};
_this.handlePageChange = function (current) {
_this.load(current);
};
_this.load = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageNo) {
var _ret$result, _ret$total;
var _this$state, pageSize, sceneId, flowCode, appCode, inputQuery, start, limit, input, query, ret, items, total;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (pageNo === void 0) {
pageNo = 1;
}
_this$state = _this.state, pageSize = _this$state.pageSize, sceneId = _this$state.sceneId, flowCode = _this$state.flowCode, appCode = _this$state.appCode, inputQuery = _this$state.inputQuery;
_this.setState({
loading: true
});
start = pageSize * Math.max(0, pageNo - 1);
limit = pageSize;
input = inputQuery || [];
query = {
inputQuery: input,
flowCode: flowCode
}; // 提供了场景ID时,同时按照场景ID查询,and
if (sceneId) {
input.push({
field: 'input.parameters.sceneId',
value: sceneId
});
}
_context.next = 10;
return callApi({
app: 'epoch_client',
code: 'epoch_io_job_get_list',
data: _extends({
jobType: 'excel_import',
appCode: appCode,
start: start,
limit: limit
}, query),
onError: function onError() {
_this.setState({
loading: false
});
}
});
case 10:
ret = _context.sent;
items = (_ret$result = ret === null || ret === void 0 ? void 0 : ret.result) !== null && _ret$result !== void 0 ? _ret$result : [];
total = (_ret$total = ret === null || ret === void 0 ? void 0 : ret.total) !== null && _ret$total !== void 0 ? _ret$total : 0;
_this.setState({
items: items,
total: total,
loading: false,
pageNo: pageNo
});
case 14:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
return _this;
}
var _proto = History.prototype;
_proto.renderInputFile = function renderInputFile(value, index, record) {
var _record$inputFile = record === null || record === void 0 ? void 0 : record.inputFile,
file = _record$inputFile[0];
if (file) {
return file.name;
}
};
_proto.renderStatus = function renderStatus(value, index, record) {
var text = '';
if (value === 'executing') {
text = '导入中';
}
if (value === 'success') {
text = '已导入';
}
if (value === 'partialSuccess') {
text = '部分成功';
}
if (value === 'failed') {
text = '失败';
}
return /*#__PURE__*/React.createElement("span", {
className: cls('cz5-import-history-status', value)
}, text);
};
_proto.renderSuccessNum = function renderSuccessNum(value, index, record) {
var _record$output;
var _ref2 = (_record$output = record === null || record === void 0 ? void 0 : record.output) !== null && _record$output !== void 0 ? _record$output : {},
successNum = _ref2.successNum;
if (typeof successNum === 'undefined') {
return /*#__PURE__*/React.createElement("span", null, "0");
}
return /*#__PURE__*/React.createElement("span", null, successNum);
};
_proto.renderFailNum = function renderFailNum(value, index, record) {
var _record$output2;
var _ref3 = (_record$output2 = record === null || record === void 0 ? void 0 : record.output) !== null && _record$output2 !== void 0 ? _record$output2 : {},
successNum = _ref3.successNum,
totalNum = _ref3.totalNum;
if (typeof successNum === 'undefined' || typeof totalNum === 'undefined') {
return /*#__PURE__*/React.createElement("span", null, "0");
}
var failNum = totalNum - successNum;
return /*#__PURE__*/React.createElement("span", null, failNum);
};
_proto.renderOperation = function renderOperation(value, index, record) {
var _record$outputFile;
var _ref4 = (_record$outputFile = record === null || record === void 0 ? void 0 : record.outputFile) !== null && _record$outputFile !== void 0 ? _record$outputFile : {},
file = _ref4[0];
if (file !== null && file !== void 0 && file.name && file !== null && file !== void 0 && file.path && record.success !== 'success') {
var url = getDownloadUrl(file);
return /*#__PURE__*/React.createElement("a", {
className: "cz5-import-history-link",
href: url
}, "\u4E0B\u8F7D\u5904\u7406\u7ED3\u679C");
}
};
_proto.render = function render() {
var _this$state2 = this.state,
visible = _this$state2.visible,
pageNo = _this$state2.pageNo,
pageSize = _this$state2.pageSize,
total = _this$state2.total,
loading = _this$state2.loading,
items = _this$state2.items,
subTitle = _this$state2.subTitle;
var title = '导入历史';
if (subTitle) {
title = title + " [" + subTitle + "]";
}
return /*#__PURE__*/React.createElement(_Drawer, {
width: 1000,
visible: visible,
onClose: this.handleClose,
title: title
}, /*#__PURE__*/React.createElement("div", {
className: "cz5-import-history"
}, /*#__PURE__*/React.createElement(_Table, {
className: "cz5-import-history-table",
dataSource: items,
loading: loading,
hasBorder: false
}, /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u5BFC\u5165\u65F6\u95F4",
dataIndex: "gmtCreate"
}), /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u6587\u4EF6\u540D\u79F0",
cell: this.renderInputFile
}), /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u5BFC\u5165\u72B6\u6001",
cell: this.renderStatus,
dataIndex: "success"
}), /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u6210\u529F\u5BFC\u5165\u6570\u91CF",
cell: this.renderSuccessNum
}), /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u5931\u8D25\u6570\u636E\u91CF",
cell: this.renderFailNum
}), /*#__PURE__*/React.createElement(_Table.Column, {
title: "\u64CD\u4F5C",
cell: this.renderOperation
})), /*#__PURE__*/React.createElement(_Pagination, {
className: "cz5-import-history-page",
onChange: this.handlePageChange,
current: pageNo,
pageSize: pageSize,
total: total
})));
};
return History;
}(React.Component);
var instance = null;
var dom = null;
var init = function init(options) {
if (!dom) {
dom = document.createElement('div');
document.body.appendChild(dom);
}
if (!instance) {
// eslint-disable-next-line react/no-render-return-value
instance = ReactDOM.render( /*#__PURE__*/React.createElement(History, null), dom);
}
instance.init(options);
return instance;
};
/**
* 支持全局唤起
* 场景:
* 1. 表单全局导入操作,完成后唤起导入历史
* 2. 表单行操作列,点击导入,完成后唤起
*/
export default (function (options) {
return init(options);
});