UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

181 lines (180 loc) 9.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LionShowFileRenderer = exports.LionShowFile = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importDefault)(require("react")); var Item_1 = require("../../../../Form/Item"); var Upload_1 = (0, tslib_1.__importDefault)(require("antd/lib/Upload")); var Button_1 = (0, tslib_1.__importDefault)(require("antd/lib/Button")); require("../../../font/iconfont.css"); var style_1 = require("./style"); var react_dom_1 = require("react-dom"); var LionFilePreview_1 = (0, tslib_1.__importDefault)(require("../../../Table/LionCellFile/LionFilePreview")); var LionShowFile = /** @class */ (function (_super) { (0, tslib_1.__extends)(LionShowFile, _super); function LionShowFile() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { visible: false, current: null, fileList: [], showfilelist: [], params: '', turtyfilelist: [] }; _this.handleOpenPdf = function (file) { _this.setState({ current: file }, function () { _this.setState({ visible: true }); }); }; _this.matchLocalhost = function (str) { return /localhost\:(\d)+/.test(str); }; _this.openDownloadDialog = function (url, saveName) { return new Promise(function (resolve, reject) { resolve(''); }).then(function (res) { if (typeof url == 'object' && url instanceof Blob) { url = URL.createObjectURL(url); // 创建blob地址 } var aLink = document.createElement('a'); aLink.href = url; aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效 var event; if (window.MouseEvent) event = new MouseEvent('click'); else { event = document.createEvent('MouseEvents'); event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); } aLink.dispatchEvent(event); }); }; return _this; } LionShowFile.prototype.componentDidMount = function () { var _a, _b; ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChange) && ((_b = this.props) === null || _b === void 0 ? void 0 : _b.onChange('')); this.initFileData(); }; LionShowFile.prototype.componentDidUpdate = function (prevProps, prevState) { if (this.props !== prevProps) { this.initFileData(); } }; LionShowFile.prototype.initFileData = function () { var _a, _b; var _c = this.props, data = _c.data, name = _c.name, env = _c.env, store = _c.store; var 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); var content = data[name] || (store === null || store === void 0 ? void 0 : store.data[name]); if (content) { var info = content.info, value = content.value; if (info && value && info.length !== 0) { var initialList_1 = []; info.map(function (ele) { initialList_1.push({ uid: ele.name, status: 'done', name: ele.name, url: (baseUrl ? baseUrl : '') + ((ele === null || ele === void 0 ? void 0 : ele.addr) || (ele === null || ele === void 0 ? void 0 : ele.url)) }); }); this.setState({ params: value, showfilelist: (0, tslib_1.__spreadArray)([], initialList_1, true), turtyfilelist: (0, tslib_1.__spreadArray)([], initialList_1, true) }); } } }; LionShowFile.prototype.getThatDom = function () { return (0, react_dom_1.findDOMNode)(this); }; LionShowFile.prototype.render = function () { var _this = this; var _a, _b; var _c = this.state, showfilelist = _c.showfilelist, visible = _c.visible, current = _c.current; var env = this.props.env; var 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); var that = this; var uploadButton = (react_1.default.createElement("div", { style: { display: 'inline-block', textAlign: 'center', cursor: 'pointer', outline: 'none', marginTop: '12px', fontSize: '12px', color: '#444' } }, react_1.default.createElement(Button_1.default, { size: 'middle', style: { width: '56px', height: '32px', border: '1px solid #ebeef5', borderRadius: '4px', fontWeight: 500, display: 'flex', justifyContent: 'center', alignItems: 'center', fontSize: '14px !important', padding: '9px 15px', cursor: 'not-allowed', color: "#c0c4cc", backgroundImage: 'none', backgroundColor: "#fff" }, disabled: true }, "\u4E0A\u4F20"))); var uploadProps = { listType: "text", disabled: false, iconRender: function () { return react_1.default.createElement("span", { className: "fa fa-file-text-o" }); }, showUploadList: { showPreviewIcon: true, showRemoveIcon: true, showDownloadIcon: true, downloadIcon: react_1.default.createElement("span", { style: { fontSize: '12px' }, className: "fa fa-cloud-download" }), removeIcon: react_1.default.createElement("span", { style: { color: 'rgb(24,144,255)', fontSize: '12px' }, className: "fa fa-folder-open-o" }) }, onDownload: function (file) { // baseUrlAddr (!baseUrl ? '' : (this.matchLocalhost(baseUrl) ? '' : baseUrl)) var downloadFileUlr = (file === null || file === void 0 ? void 0 : file.url) || (file === null || file === void 0 ? void 0 : file.addr); _this.openDownloadDialog(downloadFileUlr, file === null || file === void 0 ? void 0 : file.name); }, onPreview: function (file) { return false; }, onRemove: function (file) { var _a; _this.handleOpenPdf((0, tslib_1.__assign)((0, tslib_1.__assign)({}, file), { url: (_a = file === null || file === void 0 ? void 0 : file.url) === null || _a === void 0 ? void 0 : _a.replace(baseUrl, '') })); Promise.resolve().then(function () { var _a; return (_a = _this.getThatDom()) === null || _a === void 0 ? void 0 : _a.click(); }); return false; }, fileList: showfilelist }; return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(style_1.Wrapper, null, react_1.default.createElement(Upload_1.default, (0, tslib_1.__assign)({ style: { width: '70px', fontSize: '12px' } }, uploadProps), uploadButton)), react_1.default.createElement(LionFilePreview_1.default, (0, tslib_1.__assign)({}, this.props, { visible: visible, current: current, setVisible: function () { that.setState({ visible: false }); } })))); }; return LionShowFile; }(react_1.default.PureComponent)); exports.LionShowFile = LionShowFile; var LionShowFileRenderer = /** @class */ (function (_super) { (0, tslib_1.__extends)(LionShowFileRenderer, _super); function LionShowFileRenderer() { return _super !== null && _super.apply(this, arguments) || this; } LionShowFileRenderer = (0, tslib_1.__decorate)([ (0, Item_1.FormItem)({ type: 'lion-show-file', strictMode: false }) ], LionShowFileRenderer); return LionShowFileRenderer; }(LionShowFile)); exports.LionShowFileRenderer = LionShowFileRenderer; //# sourceMappingURL=./renderers/Lion/File/components/LionShowFile/LionShowFile.js.map