提交 4b5d6d43 authored 作者: 钟是志's avatar 钟是志

导出组件 导入组件2.0

上级 f2ca1880
import React, { useCallback, useState, useEffect } from 'react'; import React, { useCallback, useState, useEffect } from 'react';
import { Button, Modal, Alert, Transfer, message } from 'antd'; import { Modal, Alert, Transfer, message } from 'antd';
import qs from 'qs'; import qs from 'qs';
import config from '@config/config';
import { getToken } from '@/utils/authority'; import { getToken } from '@/utils/authority';
import reqwest from 'reqwest'; import reqwest from 'reqwest';
import ButtonDiy from '@/baseComponent/ButtonDiy';
function getThisInfo(data, url, callBack) { function getThisInfo(data, url) {
return reqwest({ return reqwest({
url, url,
type: 'json', type: 'json',
...@@ -21,9 +21,6 @@ function getThisInfo(data, url, callBack) { ...@@ -21,9 +21,6 @@ function getThisInfo(data, url, callBack) {
message.warning('网络故障'); message.warning('网络故障');
}, },
success: (res) => { success: (res) => {
if(callBack){
return callBack(res);
}
return res; return res;
}, },
}); });
...@@ -58,24 +55,47 @@ export default function DynamicExportButton( ...@@ -58,24 +55,47 @@ export default function DynamicExportButton(
} }
function defaultUrl() { function defaultUrl() {
return config.mockServer + api + '/exportApi'; return api + '/exportApi';
} }
function getColumns() { function getColumns() {
let url = defaultUrl() + '/findExportColumnHeader'; let url = defaultUrl() + '/findExportColumnHeader?token=' + getToken();
let data = { let data = {
serviceKey, serviceKey,
serviceBean, serviceBean,
serviceParam, serviceParam,
token: getToken(),
}; };
getThisInfo(data, url).then((y) => { getThisInfo(data, url).then((y) => {
debugger; if(y){
setColumns(formateObjToArr(y));
}
}) })
} }
function exportExcel(){ function exportExcel(){
let data = {
serviceKey,
serviceBean,
serviceParam,
fieldNames: targetKeys.length ? targetKeys : columns.map((y) => y.key),
};
let url = defaultUrl() + '/exportData?token=' + getToken();
getThisInfo(data, url).then((y) => {
if(y){
let data = {
serviceBean,
serviceKey,
fileKey: y.cacheKey,
token: getToken(),
};
window.open(defaultUrl() + '/downLoadExcel?' + qs.stringify(data));
setVisible(false);
message.success('正在下载导出文件');
return true;
}
})
} }
useEffect(() => { useEffect(() => {
...@@ -85,21 +105,33 @@ export default function DynamicExportButton( ...@@ -85,21 +105,33 @@ export default function DynamicExportButton(
}, [visible]); }, [visible]);
return ( return (
<> <>
<Button {...buttonProps} onClick={btnClick}> <ButtonDiy name={text}
{text} type='default'
</Button> className='defaultBlue'
handleClick={btnClick}/>
<Modal <Modal
visible={visible} visible={visible}
width={1000} width={1000}
title='自定义导出' title='自定义导出'
bodyStyle={{ padding: '24px 36px' }} bodyStyle={{
padding: '24px 36px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
}}
{...modalProps} {...modalProps}
onOk={exportExcel} onOk={exportExcel}
onCancel={() => setVisible(false)} onCancel={() => setVisible(false)}
> >
<Transfer <Transfer
showSearch showSearch
style={{ flex: '1' }} style={{ flex: '1',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
}}
dataSource={columns} dataSource={columns}
titles={['可选项目', '已选项目']} titles={['可选项目', '已选项目']}
targetKeys={targetKeys} targetKeys={targetKeys}
...@@ -107,6 +139,7 @@ export default function DynamicExportButton( ...@@ -107,6 +139,7 @@ export default function DynamicExportButton(
onChange={handleChange} onChange={handleChange}
operations={['增加导出项', '移除导出项']} operations={['增加导出项', '移除导出项']}
render={item => item.title || ''} render={item => item.title || ''}
/> />
<Alert showIcon <Alert showIcon
style={{ marginTop: 12 }} style={{ marginTop: 12 }}
...@@ -119,7 +152,4 @@ export default function DynamicExportButton( ...@@ -119,7 +152,4 @@ export default function DynamicExportButton(
DynamicExportButton.defaultProps = { DynamicExportButton.defaultProps = {
text: '自定义导出', text: '自定义导出',
columnsUrl: '/exportApi/findExportColumnHeader',
exportUrl: '/exportApi/exportData',
downloadUrl: '/exportApi/downLoadExcel',
}; };
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论