|
|
@ -1,20 +1,25 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { useFsRequest, ApiTable } from '$utils'; |
|
|
|
import ApproveModal from '../components/approveModal'; |
|
|
|
import { downloadImg, markRedKeywords } from '../../resourceRetrieval/utils/index' |
|
|
|
import { Tabs, Form, Input, DatePicker, Button, Table, Select, message } from 'antd'; |
|
|
|
import xlsx from 'xlsx'; |
|
|
|
|
|
|
|
|
|
|
|
import { Tabs, Form, Input, DatePicker, Button, Table, Select } from 'antd'; |
|
|
|
import { v1 } from 'uuid'; |
|
|
|
|
|
|
|
|
|
|
|
function MyApplication({ loading, clientHeight, actions, dispatch, user }) { |
|
|
|
function MyApplication ({ loading, clientHeight, actions, dispatch, user }) { |
|
|
|
|
|
|
|
const { resourceConsumption } = actions |
|
|
|
|
|
|
|
const [query, setQuery] = useState({ page: 0, limit: 10 }); |
|
|
|
const [proTableList, setProTableList] = useState({ rows: [], count: 0 }); |
|
|
|
const [formData, setFormData] = useState({}) |
|
|
|
const [searchDataId, setSearchDataId] = useState(null) |
|
|
|
const [keywords, setKeywords] = useState() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
resourceData() |
|
|
@ -30,6 +35,71 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//检索元数据
|
|
|
|
const { data: tableData = {} } = useFsRequest({ |
|
|
|
url: 'meta/table/data', |
|
|
|
query: { |
|
|
|
id: searchDataId |
|
|
|
}, |
|
|
|
refreshDeps: [searchDataId], |
|
|
|
ready: !!searchDataId, |
|
|
|
}); |
|
|
|
|
|
|
|
//检索元数据
|
|
|
|
const { data: result = {} } = useFsRequest({ |
|
|
|
url: ApiTable.searchMetadata, |
|
|
|
query: { |
|
|
|
keywords: keywords |
|
|
|
}, |
|
|
|
refreshDeps: [keywords], |
|
|
|
ready: !!keywords |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (tableData?.rslt && tableData?.metaDataChildren) handleTableExport() |
|
|
|
}, [tableData]) |
|
|
|
|
|
|
|
const handleTableExport = () => { |
|
|
|
const metaData = result?.rows?.find(s => s.id == searchDataId) |
|
|
|
if (!metaData) return; |
|
|
|
let excelTitle = tableData?.metaDataChildren.map(s => { |
|
|
|
return { k: s, v: s } |
|
|
|
}); |
|
|
|
let workBook = { |
|
|
|
SheetNames: [], //sheet名称
|
|
|
|
Sheets: {} //根据SheetNames名称顺序依次添加每个sheet数据
|
|
|
|
}; |
|
|
|
if (tableData?.rslt && tableData?.rslt?.length > 0) { |
|
|
|
let sheetName = '元数据列表'; |
|
|
|
let sheetDataMap = new Map(); |
|
|
|
let sheetData = [excelTitle]; |
|
|
|
let index = 1; |
|
|
|
tableData?.rslt.map(data => { |
|
|
|
const arr = [] |
|
|
|
tableData?.metaDataChildren.map(s => { |
|
|
|
arr.push( |
|
|
|
{ k: s, v: JSON.stringify(data[s]) }, |
|
|
|
); |
|
|
|
}); |
|
|
|
sheetData.push(arr) |
|
|
|
index = index + 1; |
|
|
|
}) |
|
|
|
|
|
|
|
sheetDataMap.set(sheetName, sheetData); |
|
|
|
sheetDataMap.forEach((values, key) => { |
|
|
|
// 写入excel
|
|
|
|
workBook.Sheets[key] = xlsx.utils.aoa_to_sheet(values); |
|
|
|
workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] |
|
|
|
}) |
|
|
|
workBook.SheetNames = [sheetName]; |
|
|
|
// 将workBook写入文件
|
|
|
|
xlsx.writeFile(workBook, `${metaData?.name}-data.xlsx`); |
|
|
|
} else { |
|
|
|
message.info('当前资源暂无数据!') |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const columns = [{ |
|
|
|
title: '资源名称', |
|
|
@ -80,8 +150,84 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { |
|
|
|
compare: (a, b) => moment(b?.approveAt).valueOf() - moment(a?.approveAt).valueOf(), |
|
|
|
// multiple: 2,
|
|
|
|
}, |
|
|
|
}, { |
|
|
|
title: '操作', |
|
|
|
dataIndex: 'action', |
|
|
|
render: (text, record) => { |
|
|
|
return record?.token && <Button type="link" onClick={async () => { |
|
|
|
console.log(record); |
|
|
|
if (record?.resourceType == '文件') { |
|
|
|
const suffix = record?.metadataFile?.fileName?.substring(record?.metadataFile?.fileName?.length - 3, record?.metadataFile?.fileName?.length) |
|
|
|
if (suffix == 'png' || suffix == 'jpg') { |
|
|
|
downloadImg(record?.metadataFile.fileName) |
|
|
|
} else { |
|
|
|
window.open('/assets/files/common/' + record?.metadataFile.fileName) |
|
|
|
} |
|
|
|
} else if (record?.resourceType == '库表') { |
|
|
|
setKeywords(record?.resourceName) |
|
|
|
setSearchDataId(null) |
|
|
|
setTimeout(() => { |
|
|
|
setSearchDataId(record.metadataDatabase?.id) |
|
|
|
}, 10); |
|
|
|
|
|
|
|
} else if (record?.resourceType == '数据服务') { |
|
|
|
dispatch(resourceConsumption.getRestData({ |
|
|
|
url: record?.restfulApi?.url, |
|
|
|
token: record?.token |
|
|
|
})).then(res => { |
|
|
|
if (res.success) { |
|
|
|
let restData = res.payload.data?.rows |
|
|
|
if (restData.length > 0) { |
|
|
|
restTableExport(record?.resourceName, restData) |
|
|
|
} else { |
|
|
|
message.info('当前资源暂无数据!') |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}}>下载</Button> |
|
|
|
} |
|
|
|
}]; |
|
|
|
|
|
|
|
const restTableExport = (name, data = []) => { |
|
|
|
let dataKey = Object.keys(data[0])||[] |
|
|
|
|
|
|
|
let excelTitle = dataKey.map(s => { |
|
|
|
return { k: s, v: s } |
|
|
|
}); |
|
|
|
let workBook = { |
|
|
|
SheetNames: [], //sheet名称
|
|
|
|
Sheets: {} //根据SheetNames名称顺序依次添加每个sheet数据
|
|
|
|
}; |
|
|
|
|
|
|
|
let sheetName = '元数据列表'; |
|
|
|
let sheetDataMap = new Map(); |
|
|
|
let sheetData = [excelTitle]; |
|
|
|
let index = 1; |
|
|
|
data.map(data => { |
|
|
|
const arr = [] |
|
|
|
dataKey.map(s => { |
|
|
|
arr.push( |
|
|
|
{ k: s, v: JSON.stringify(data[s]) }, |
|
|
|
); |
|
|
|
}); |
|
|
|
sheetData.push(arr) |
|
|
|
index = index + 1; |
|
|
|
}) |
|
|
|
|
|
|
|
sheetDataMap.set(sheetName, sheetData); |
|
|
|
sheetDataMap.forEach((values, key) => { |
|
|
|
// 写入excel
|
|
|
|
workBook.Sheets[key] = xlsx.utils.aoa_to_sheet(values); |
|
|
|
workBook.Sheets[key]['!cols'] = [{ wpx: 50 }, { wpx: 150 }, { wpx: 180 }, { wpx: 230 }, { wpx: 230 }, { wpx: 230 }] |
|
|
|
}) |
|
|
|
workBook.SheetNames = [sheetName]; |
|
|
|
// 将workBook写入文件
|
|
|
|
xlsx.writeFile(workBook, `${name}-data.xlsx`); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return <> |
|
|
@ -143,7 +289,7 @@ function MyApplication({ loading, clientHeight, actions, dispatch, user }) { |
|
|
|
|
|
|
|
</> |
|
|
|
} |
|
|
|
function mapStateToProps(state) { |
|
|
|
function mapStateToProps (state) { |
|
|
|
const { global, auth, resourceCatalog } = state; |
|
|
|
return { |
|
|
|
user: auth.user, |
|
|
|