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

26598 自定义数据导出---导出字段调整,,,注意数据权限

上级 6bfce114
import fetch from 'dva/fetch';
import React from 'react';
import {
Form,
notification,
} from 'antd';
import { connect } from 'dva';
import { getToken } from '../utils/token';
import config from '@/webPublic/one_stop_public/config';
import FormdataWrapper from '../utils/object-to-formdata-custom';
import ButtonDiy from './ButtonDiy/ButtonDiy';
import { queryIsSafe } from '@/webPublic/one_stop_public/utils/queryConfig';
import { giveFilePostData, giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16';
/**
*
* 2019/02/21 修改导出方式为fetch
* 增加 props.fileName 设置导出文件名称
* mustQuerys 设置搜索条件 demo :
* mustQuerys={[{
hql: 'bean.adminStatus',
x: '=',
v: "pass",
c: 'com.zysoft.app.zydxl.entity.base.BaseImportantWatch$Status',
notes: 'com.zysoft.app.zydxl.entity.base.BaseImportantWatch$Status',
}]}
*/
@connect(({ DataObj, loading }) => ({
DataObj,
loading: loading.models.DataObj,
}))
@Form.create()
export default class ExportCurrentInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
confirmLoading: false,
};
}
exportData = () => {
let downloadUrl = config.httpServer + '/DataObjApi/exportCurrent?';
const token = getToken() != null && getToken() != 'null' ? getToken() : '0000';
downloadUrl = `${downloadUrl}token=${token}`;
let param = {
dataObjId: this.props.objId,
query: this.props.query,
custom: this.props.custom,
sql: this.props.sql,
index: this.props.index,
};
this.downloadFile(downloadUrl, param);
};
downloadFile(url, params) {
this.setState({ confirmLoading: true });
let newApi = giveFilePostDataInfoForTrue(params, url);
fetch(newApi.url, {
method: 'POST',
body: FormdataWrapper(newApi.datas,
),
})
.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 {
notification.error({
message: `文件导出错误`,
description: data.errMsg,
});
}
})
.catch((err) => {
notification.error({
message: `网络请求超时`,
});
})
.finally(() => {
this.setState({ confirmLoading: false });
});
}
render() {
const btn = {
name: '导出',
type: 'default',
className: 'defaultBlue',
...(this.props.btn ? this.props.btn : {}),
};
return (
<span>
<ButtonDiy {...btn} loading={this.state.confirmLoading} handleClick={this.exportData} />
<div id="downloadDiv" style={{ display: 'none' }} />
</span>
);
}
}
/**
* 钟是志
* 2022年5月25日
* openSelectFieldsModal 弹窗
*/
import React, { useEffect, useState } from 'react';
import { isJSON } from '@/webPublic/one_stop_public/copy';
import { Checkbox, Col, Modal, Row, message } from 'antd';
import ButtonDiy from '@/webPublic/one_stop_public/App/ButtonDiy/ButtonDiy';
import styles from './style.less';
export default function SelectModal({
custom,
index,
show,
changeShow,
downloadFile,
}) {
const [fields, setFields] = useState([]);
const [buttonName, setButtonName] = useState('全部选中');
const [strInput, setStrInput] = useState([]);
const [inputDisable, setInputDisable] = useState(false); // 点击全部选中整族失效
useEffect(() => {
if (isJSON(custom)) {
let exportConfig = JSON.parse(custom)?.exportConfig;
if (exportConfig && exportConfig.length > index && index >= 0) {
setFields(exportConfig[index].fields);
}
}
}, [custom]);
const arrayChange = (checkedValues) => {
setStrInput(checkedValues);
};
const selectAllAndCancelAll = () => {
const all = fields.map(item => item.k);
if (strInput.length === all.length) {
setStrInput([]);
setButtonName('全部选中');
} else {
setStrInput(all);
setButtonName('全部取消');
}
};
const handleOk = () => {
if (!strInput || !strInput.length) {
message.warning('请选择导出的列');
return false;
}
const newFileds = fields.filter((item) => {
return strInput.includes(item.k);
});
if (!newFileds || !newFileds.length) {
changeShow();
return false;
}
const newCustom = JSON.parse(custom);
newCustom.exportConfig[index].fields = newFileds;
const newParams = {
...show.param,
custom: JSON.stringify(newCustom),
};
downloadFile(show.downloadUrl, newParams);
};
return !!show && <Modal
title={'请选择导出列'}
visible={true}
onOk={handleOk}
onCancel={changeShow}
width={900}
>
<Row>
<Col span={4}>导出列数据
<Col>
<ButtonDiy
name={buttonName}
handleClick={selectAllAndCancelAll}
/>
</Col>
</Col>
<Col span={20}>
<div className={styles.formbody}>
<Checkbox.Group
options={fields.map((g) => {
return {
label: g.n,
value: g.k,
};
})}
onChange={arrayChange}
value={strInput}
disabled={inputDisable}
/>
</div>
</Col>
</Row>
</Modal>;
}
import fetch from 'dva/fetch';
import React from 'react';
import {
Form,
notification,
} from 'antd';
import { connect } from 'dva';
import { getToken } from '../../utils/token';
import config from '@/webPublic/one_stop_public/config';
import FormdataWrapper from '../../utils/object-to-formdata-custom';
import ButtonDiy from '../ButtonDiy/ButtonDiy';
import { giveFilePostData, giveFilePostDataInfoForTrue } from '@/webPublic/one_stop_public/Base16';
import SelectModal from '@/webPublic/one_stop_public/App/ExportCurrentInfo/SelectModal';
/**
*
* 2019/02/21 修改导出方式为fetch
* 增加 props.fileName 设置导出文件名称
* mustQuerys 设置搜索条件 demo :
* mustQuerys={[{
hql: 'bean.adminStatus',
x: '=',
v: "pass",
c: 'com.zysoft.app.zydxl.entity.base.BaseImportantWatch$Status',
notes: 'com.zysoft.app.zydxl.entity.base.BaseImportantWatch$Status',
}]}
*/
@connect(({ DataObj, loading }) => ({
DataObj,
loading: loading.models.DataObj,
}))
@Form.create()
export default class ExportCurrentInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
confirmLoading: false,
showSelectModal: false,
};
}
changeShowSelectModal = () => {
this.setState({
showSelectModal: !this.state.showSelectModal,
})
}
exportData = () => {
let downloadUrl = config.httpServer + '/DataObjApi/exportCurrent?';
const token = getToken() != null && getToken() != 'null' ? getToken() : '0000';
downloadUrl = `${downloadUrl}token=${token}`;
let param = {
dataObjId: this.props.objId,
query: this.props.query,
custom: this.props.custom,
sql: this.props.sql,
index: this.props.index,
};
if(this.props.openSelectFieldsModal){ // 26598 自定义数据导出---导出字段调整,,,注意数据权限
this.setState({
showSelectModal: {
param,
downloadUrl,
}
});
return false;
}
this.downloadFile(downloadUrl, param);
};
downloadFile(url, params) {
this.setState({ confirmLoading: true });
let newApi = giveFilePostDataInfoForTrue(params, url);
fetch(newApi.url, {
method: 'POST',
body: FormdataWrapper(newApi.datas,
),
})
.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 {
notification.error({
message: `文件导出错误`,
description: data.errMsg,
});
}
})
.catch((err) => {
notification.error({
message: `网络请求超时`,
});
})
.finally(() => {
this.setState({ confirmLoading: false });
});
}
render() {
const btn = {
name: '导出',
type: 'default',
className: 'defaultBlue',
...(this.props.btn ? this.props.btn : {}),
};
const { custom, index, openSelectFieldsModal } = this.props;
const { showSelectModal } = this.state;
return (
<span>
<ButtonDiy {...btn} loading={this.state.confirmLoading} handleClick={this.exportData} />
{
openSelectFieldsModal &&
<SelectModal custom={custom}
index={index}
changeShow={this.changeShowSelectModal}
show={showSelectModal}
downloadFile={this.downloadFile.bind(this)}
/>
}
<div id="downloadDiv" style={{ display: 'none' }} />
</span>
);
}
}
.formbody{
display: flex;
flex-wrap: wrap;
height: 450px;
overflow: auto;
label{
width: 30%;
box-sizing: border-box;
}
}
......@@ -65,6 +65,7 @@ export function FormListButtons(props) {
index={r.index}
btn={r.btn}
ext={r.ext ? r.ext : 'xlsx'}
openSelectFieldsModal={r.openSelectFieldsModal || false}
sql={Base16Encode(sql)}
/>;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论