UNPKG

@flatbiz/antd

Version:
72 lines (68 loc) 2.31 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { _ as _objectWithoutProperties, a as _slicedToArray, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { hooks } from '@wove/react/hooks'; import { useState, isValidElement } from 'react'; import { message, Upload, Button } from 'antd'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["onImportFinish", "buttonName"]; /** * 文件导入 * ``` * demo:https://fex.qa.tcshuke.com/docs/admin/main/widget?key=file-export * 1. accept默认值 '.xlsx,.xls', * 2. formData 上传key默认值 file * * 例如: <FileImport action={'https://xxx/xxx/xx'} onImportFinish={(data) => { console.log('上传接口响应数据', data); }} > <Button>文件上传</Button> </FileImport> * ``` */ var FileImport = function FileImport(props) { var _props$children; var onImportFinish = props.onImportFinish, buttonName = props.buttonName, otherProps = _objectWithoutProperties(props, _excluded); var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), loading = _useState2[0], setLoading = _useState2[1]; var onChange = hooks.useCallbackRef(function (info) { if (info.file.status === 'uploading') { setLoading(true); } else if (info.file.status === 'done') { setLoading(false); var respData = info.file.response; if (respData.code === '0000') { onImportFinish(respData.data); } else { void message.error(respData.message || '文件导入异常...'); } } }); return /*#__PURE__*/jsx(Upload, _objectSpread2(_objectSpread2({ showUploadList: false, maxCount: 1 }, otherProps), {}, { onChange: onChange, children: typeof props.children === 'function' ? (_props$children = props.children) === null || _props$children === void 0 ? void 0 : _props$children.call(props, { loading: loading }) : /*#__PURE__*/isValidElement(props.children) ? props.children : /*#__PURE__*/jsx(Button, { type: "primary", ghost: true, loading: loading, children: buttonName || '选择文件' }) })); }; FileImport.defaultProps = { name: 'file', accept: '.xlsx,.xls' }; export { FileImport as F }; //# sourceMappingURL=file-import-CZfgKmrO.js.map