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

开发

上级 2e1f5e38
......@@ -105,9 +105,9 @@ export default class ExportCurrentInfo extends React.Component {
render() {
const btn = this.props.btn?this.props.btn:{name:'导出',
const btn = {name:'导出',
type:'default',
className:'defaultBlue'}
className:'defaultBlue',...(this.props.btn?this.props.btn:{})}
return (
<span>
<ButtonDiy {...btn}
......
......@@ -3,6 +3,7 @@ import { Button, Modal, Steps, Upload, Icon, message, Spin, Tabs, Table } from '
import styles from './ImportUtil.less';
import ButtonDiy from './ButtonDiy/ButtonDiy';
import FormdataWrapper from '../utils/object-to-formdata-custom';
import config from '@/webPublic/one_stop_public/config';
import { connect } from 'dva';
......@@ -17,8 +18,8 @@ const exportExcel = CLIENT_TYPE == 'mobile' ? null : require('xlsx-oc').exportEx
}))
export default class ImportUtil extends React.PureComponent {
constructor(props) {
super(props);
const exportTemplateUrl = encodeURI(
`${config.httpServer}/DataObjApi/importTemplateDownload?objId=${this.props.objId}&name=${props.fileName}`,
);
......@@ -33,7 +34,7 @@ export default class ImportUtil extends React.PureComponent {
sucData: [],
errData: [],
column: [],
confirmLoading:false,
exportTemplateUrl,
isNextDisabled: false,
......@@ -87,13 +88,13 @@ export default class ImportUtil extends React.PureComponent {
}
import() {
const { dispatch, importParams } = this.props;
const { dispatch, importParams,importConfig } = this.props;
dispatch({
type: 'DataObj/importExecute',
payload: {
...(importParams || {}),
cacheKey: this.state.filekey,
importConfig:importConfig?JSON.stringify(importConfig):null,
objId: this.props.objId,
},
callback: res => {
......@@ -192,7 +193,44 @@ export default class ImportUtil extends React.PureComponent {
}
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() {
const props = {
name: 'file',
......@@ -250,12 +288,14 @@ export default class ImportUtil extends React.PureComponent {
column2.splice(0, 1);
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 (
<span>
<ButtonDiy
name={name || '批量导入'} // 应用里面的批量导入
type="default"
className="defaultBlue"
<ButtonDiy {...btn}
handleClick={this.showModal}
/>
<Modal
......@@ -315,9 +355,15 @@ export default class ImportUtil extends React.PureComponent {
点击上传
</Button>
</Upload>
<Button href={this.state.exportTemplateUrl} target="_blank" type="danger">
下载模板
</Button>
<ButtonDiy
name={'下载模板'}
type="primary"
// className='primaryBlue'
handleClick={() => this.downloadFile()}
loading={this.state.confirmLoading}
/>
</div>
) : (
<Upload {...props}>
......
......@@ -1332,8 +1332,12 @@ class FormList extends React.Component {
{rights && !rights.includes('importData') ? (
''
) : (
<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') ? (
''
) : (
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论