|
|
@ -5,6 +5,7 @@ import { useFsRequest, ApiTable } from '$utils'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import { downloadImg, markRedKeywords } from '../utils/index' |
|
|
|
import KeyModal from '../components/keyModal'; |
|
|
|
import xlsx from 'xlsx'; |
|
|
|
const METADTA_TYPE = { |
|
|
|
'库': 'databases', |
|
|
|
'表': 'databases', |
|
|
@ -26,6 +27,8 @@ function Retrieval(props) { |
|
|
|
const [firstInput, setFirstInput] = useState() |
|
|
|
const [page, setPage] = useState(1) |
|
|
|
const [currentData, setCurrentData] = useState(null) |
|
|
|
const [searchDataId, setSearchDataId] = useState(null) |
|
|
|
|
|
|
|
const formRef = React.createRef(); |
|
|
|
// const { data: catalogs = [] } = useFsRequest({
|
|
|
|
// url: ApiTable.getResourceCatalog,
|
|
|
@ -54,6 +57,58 @@ function Retrieval(props) { |
|
|
|
ready: !!(user?.id) |
|
|
|
}); |
|
|
|
|
|
|
|
//检索元数据
|
|
|
|
const { data: tableData = {} } = useFsRequest({ |
|
|
|
url: 'meta/table/data', |
|
|
|
query: { |
|
|
|
id: searchDataId |
|
|
|
}, |
|
|
|
refreshDeps: [searchDataId], |
|
|
|
ready: !!searchDataId |
|
|
|
}); |
|
|
|
|
|
|
|
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`); |
|
|
|
} |
|
|
|
|
|
|
|
const renderIcon = (type) => { |
|
|
|
switch (type) { |
|
|
|
case '库': |
|
|
@ -106,7 +161,13 @@ function Retrieval(props) { |
|
|
|
window.open('/assets/files/common/' + s.fileName) |
|
|
|
} |
|
|
|
} else { |
|
|
|
alert('库表下载待开发') |
|
|
|
if (s.datasourceConfig) { |
|
|
|
setSearchDataId(s.id) |
|
|
|
if (tableData?.rslt && tableData?.metaDataChildren) handleTableExport() |
|
|
|
} else { |
|
|
|
message.warning('数据源信息读取失败,无法下载元数据!') |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|