提交 e9468a37 authored 作者: tb53863844's avatar tb53863844

开发

上级 2e1f5e38
...@@ -105,9 +105,9 @@ export default class ExportCurrentInfo extends React.Component { ...@@ -105,9 +105,9 @@ export default class ExportCurrentInfo extends React.Component {
render() { render() {
const btn = this.props.btn?this.props.btn:{name:'导出', const btn = {name:'导出',
type:'default', type:'default',
className:'defaultBlue'} className:'defaultBlue',...(this.props.btn?this.props.btn:{})}
return ( return (
<span> <span>
<ButtonDiy {...btn} <ButtonDiy {...btn}
......
...@@ -3,6 +3,7 @@ import { Button, Modal, Steps, Upload, Icon, message, Spin, Tabs, Table } from ' ...@@ -3,6 +3,7 @@ import { Button, Modal, Steps, Upload, Icon, message, Spin, Tabs, Table } from '
import styles from './ImportUtil.less'; import styles from './ImportUtil.less';
import ButtonDiy from './ButtonDiy/ButtonDiy'; import ButtonDiy from './ButtonDiy/ButtonDiy';
import FormdataWrapper from '../utils/object-to-formdata-custom';
import config from '@/webPublic/one_stop_public/config'; import config from '@/webPublic/one_stop_public/config';
import { connect } from 'dva'; import { connect } from 'dva';
...@@ -17,8 +18,8 @@ const exportExcel = CLIENT_TYPE == 'mobile' ? null : require('xlsx-oc').exportEx ...@@ -17,8 +18,8 @@ const exportExcel = CLIENT_TYPE == 'mobile' ? null : require('xlsx-oc').exportEx
})) }))
export default class ImportUtil extends React.PureComponent { export default class ImportUtil extends React.PureComponent {
constructor(props) { constructor(props) {
super(props);
super(props);
const exportTemplateUrl = encodeURI( const exportTemplateUrl = encodeURI(
`${config.httpServer}/DataObjApi/importTemplateDownload?objId=${this.props.objId}&name=${props.fileName}`, `${config.httpServer}/DataObjApi/importTemplateDownload?objId=${this.props.objId}&name=${props.fileName}`,
); );
...@@ -33,7 +34,7 @@ export default class ImportUtil extends React.PureComponent { ...@@ -33,7 +34,7 @@ export default class ImportUtil extends React.PureComponent {
sucData: [], sucData: [],
errData: [], errData: [],
column: [], column: [],
confirmLoading:false,
exportTemplateUrl, exportTemplateUrl,
isNextDisabled: false, isNextDisabled: false,
...@@ -87,13 +88,13 @@ export default class ImportUtil extends React.PureComponent { ...@@ -87,13 +88,13 @@ export default class ImportUtil extends React.PureComponent {
} }
import() { import() {
const { dispatch, importParams } = this.props; const { dispatch, importParams,importConfig } = this.props;
dispatch({ dispatch({
type: 'DataObj/importExecute', type: 'DataObj/importExecute',
payload: { payload: {
...(importParams || {}), ...(importParams || {}),
cacheKey: this.state.filekey, cacheKey: this.state.filekey,
importConfig:importConfig?JSON.stringify(importConfig):null,
objId: this.props.objId, objId: this.props.objId,
}, },
callback: res => { callback: res => {
...@@ -192,7 +193,44 @@ export default class ImportUtil extends React.PureComponent { ...@@ -192,7 +193,44 @@ export default class ImportUtil extends React.PureComponent {
} }
exportExcel(_headers, dataSource); exportExcel(_headers, dataSource);
}; };
downloadFile=()=> {
this.setState({ confirmLoading: true });
const {objId,fileName,importParams,importConfig} = this.props;
const params = {
...importParams,
importConfig:importConfig?JSON.stringify(importConfig):null,
objId,fileName
}
fetch(`${config.httpServer}/DataObjApi/importTemplateDownload`, {
method: 'POST',
body: FormdataWrapper(params),
}).then(res => {
if (res.status != '200') {
return res.json();
} else {
return res.blob();
}
}).then(data => {
if (data instanceof Blob) {
let a = document.createElement('a');
let url = window.URL.createObjectURL(data);
let filename = (this.props.fileName ? this.props.fileName : '导入模板.') + (this.props.ext||"xlsx");
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
a = null;
} else {
message.error( `文件导出错误`);
}
}).catch(err => {
message.error( `网络请求超时`);
}).finally(() => {
this.setState({ confirmLoading: false });
});
}
render() { render() {
const props = { const props = {
name: 'file', name: 'file',
...@@ -250,12 +288,14 @@ export default class ImportUtil extends React.PureComponent { ...@@ -250,12 +288,14 @@ export default class ImportUtil extends React.PureComponent {
column2.splice(0, 1); column2.splice(0, 1);
column2 = [{ title: '序号', fixed: 'left', width: 50, render: (v, r, i) => i + 1 }, ...column2]; column2 = [{ title: '序号', fixed: 'left', width: 50, render: (v, r, i) => i + 1 }, ...column2];
const btn = {name:name || '批量导入',
type:'default',
className:'defaultBlue',...(this.props.btn?this.props.btn:{})}
return ( return (
<span> <span>
<ButtonDiy <ButtonDiy {...btn}
name={name || '批量导入'} // 应用里面的批量导入
type="default"
className="defaultBlue"
handleClick={this.showModal} handleClick={this.showModal}
/> />
<Modal <Modal
...@@ -315,9 +355,15 @@ export default class ImportUtil extends React.PureComponent { ...@@ -315,9 +355,15 @@ export default class ImportUtil extends React.PureComponent {
点击上传 点击上传
</Button> </Button>
</Upload> </Upload>
<Button href={this.state.exportTemplateUrl} target="_blank" type="danger"> <ButtonDiy
下载模板 name={'下载模板'}
</Button> type="primary"
// className='primaryBlue'
handleClick={() => this.downloadFile()}
loading={this.state.confirmLoading}
/>
</div> </div>
) : ( ) : (
<Upload {...props}> <Upload {...props}>
......
...@@ -1334,6 +1334,10 @@ class FormList extends React.Component { ...@@ -1334,6 +1334,10 @@ class FormList extends React.Component {
) : ( ) : (
<ImportUtil objId={this.state.objId} callback={() => this.getPage()}/> <ImportUtil objId={this.state.objId} callback={() => this.getPage()}/>
)} )}
{this.props.value &&this.props.value.importConfig?
this.props.value.importConfig.map((r,i)=> <ImportUtil btn={r.btn} ext={r.ext?r.ext:"xlsx"} importConfig={r} objId={this.state.objId} callback={() => this.getPage()}/>
):""}
{rights && !rights.includes('exportCurrent') ? ( {rights && !rights.includes('exportCurrent') ? (
'' ''
) : ( ) : (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论