Browse Source

文件导出组件

release_0.0.4
巴林闲侠 3 years ago
parent
commit
6553a8b3eb
  1. 2
      api/app/lib/controllers/data/index.js
  2. 40
      web/client/src/components/simpleFileDownButton.js

2
api/app/lib/controllers/data/index.js

@ -78,7 +78,7 @@ async function dataExport (ctx) {
const tableAttributes = models[modalOption.tableName].tableAttributes
let header = []
for (let k in tableAttributes) {
if (k != 'id') {
if (k != 'id' && tableAttributes[k].comment) {
header.push({
title: tableAttributes[k].comment || '-',
key: k,

40
web/client/src/components/simpleFileDownButton.js

@ -0,0 +1,40 @@
import React, { useState, useEffect, useRef } from "react";
import { connect } from "react-redux";
import moment from 'moment'
import { Button } from "antd";
const SimpleFileDownButton = (props) => {
const { src, user } = props
const [downloadUrl, setDownloadUrl] = useState('')
return (
<>
<Button
style={{
width: 65,
height: 32,
background: "#FFFFFF",
borderRadius: 3,
border: "1px solid #1859C1",
}}
onClick={() => {
setDownloadUrl(`${src}?token=${user.token}&timestamp=${moment().valueOf()}`)
}}
>
导出
</Button>
{
downloadUrl ? <iframe src={`/_api/${downloadUrl}`} style={{ display: 'none' }} /> : ''
}
</>
)
}
function mapStateToProps (state) {
const { auth } = state;
return {
user: auth.user,
};
}
export default connect(mapStateToProps)(SimpleFileDownButton);
Loading…
Cancel
Save