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

导入组件2.0 心理健康 重点关注学生

上级 d2f0d07b
import React, { useCallback, useState, useEffect } from 'react';
import { Button, Modal, Alert, Transfer, message } from 'antd';
import qs from 'qs';
import config from '@config/config';
import { getToken } from '@/utils/authority';
import reqwest from 'reqwest';
function getThisInfo(data, url, callBack) {
return reqwest({
url,
type: 'json',
method: 'post',
data: JSON.stringify(data),
headers: {
Accept: 'application/json;charset=UTF-8',
'Content-Type': 'application/json',
},
crossOrigin: true,
withCredentials: false,
error: (err) => {
message.warning('网络故障');
},
success: (res) => {
if(callBack){
return callBack(res);
}
return res;
},
});
}
function formateObjToArr(obj) {
return Object.keys(obj).reduce((acc, key) => acc.concat({ key, title: obj[key] }), []);
}
/**
* text: '按钮名称' 默认 自定义导出
* modalProps: '弹窗props'
* */
export default function DynamicExportButton(
{
text,
modalProps,
serviceBean,
serviceKey,
api,
serviceParam,
}) {
const [visible, setVisible] = useState(false);
const [targetKeys, setTargetKeys] = useState([]);
const [columns, setColumns] = useState([]);
const handleChange = useCallback((keys) => {
setTargetKeys(keys)
}, []);
function btnClick() {
setVisible(!visible);
}
function defaultUrl() {
return config.mockServer + api + '/exportApi';
}
function getColumns() {
let url = defaultUrl() + '/findExportColumnHeader';
let data = {
serviceKey,
serviceBean,
serviceParam,
token: getToken(),
};
getThisInfo(data, url).then((y) => {
debugger;
})
}
function exportExcel(){
}
useEffect(() => {
if (visible) {
getColumns();
}
}, [visible]);
return (
<>
<Button {...buttonProps} onClick={btnClick}>
{text}
</Button>
<Modal
visible={visible}
width={1000}
title='自定义导出'
bodyStyle={{ padding: '24px 36px' }}
{...modalProps}
onOk={exportExcel}
onCancel={() => setVisible(false)}
>
<Transfer
showSearch
style={{ flex: '1' }}
dataSource={columns}
titles={['可选项目', '已选项目']}
targetKeys={targetKeys}
listStyle={{ height: 400, flex: 1 }}
onChange={handleChange}
operations={['增加导出项', '移除导出项']}
render={item => item.title || ''}
/>
<Alert showIcon
style={{ marginTop: 12 }}
message="在不选择任何导出项时,默认导出所有项目。"
type="warning"/>
</Modal>
</>
);
}
DynamicExportButton.defaultProps = {
text: '自定义导出',
columnsUrl: '/exportApi/findExportColumnHeader',
exportUrl: '/exportApi/exportData',
downloadUrl: '/exportApi/downLoadExcel',
};
......@@ -161,14 +161,24 @@ export default class ImportUtil extends React.PureComponent {
import() {
const importFileUrl = this.state.importFileUrl;
this.setState({ loading: true });
const { importParams } = this.props;
const { serviceParam, serviceKey, serviceBean } = this.props;
let data = {
cacheKey: this.state.filekey,
serviceBean,
serviceKey,
serviceParam,
};
reqwest({
url: importFileUrl + this.state.filekey
, type: 'json'
, method: 'post'
, data: importParams || {}
, crossOrigin: true
, withCredentials: false
url: importFileUrl,
type: 'json',
method: 'post',
data: JSON.stringify(data),
headers: {
Accept: 'application/json;charset=UTF-8',
'Content-Type': 'application/json',
},
crossOrigin: true,
withCredentials: false
, error: (err) => {
this.setState({ loading: false });
message.warning('网络故障');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论