diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index b9a4d4b..90f88ed 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -120,7 +120,7 @@ async function delResourceCatalog(ctx) { async function getMetadataDatabases(ctx) { try { const models = ctx.fs.dc.models; - const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null } = ctx.query; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null, resourceId } = ctx.query; const where = {}; if (catalog) { where.catalog = catalog; @@ -128,6 +128,10 @@ async function getMetadataDatabases(ctx) { if (id) { where.parent = id; } + if (resourceId) { + where.id = resourceId; + } + if (keywords) { where['$or'] = [{ name: { $iLike: `%${keywords}%` } }, { code: { $iLike: `%${keywords}%` } }, @@ -168,13 +172,16 @@ async function getMetadataDatabases(ctx) { async function getMetadataFiles(ctx) { try { const models = ctx.fs.dc.models; - const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc' } = ctx.query; + const { catalog, limit, offset, keywords, orderBy = 'updateAt', orderDirection = 'desc', resourceId } = ctx.query; const where = { catalog: catalog }; //文件类型关键字查询时需匹配fileName不能为空。 //因存在编辑时将文件删除,但未重新上传直接点击取消的情况,此时文件已删除不可恢复,数据字段fileName更新为null if (keywords) { where['$or'] = [{ name: { $iLike: `%${keywords}%` } }, { type: { $iLike: `%${keywords}%` }, fileName: { $not: null } }] } + if (resourceId) { + where.id = resourceId; + } const findObj = { include: [ // { @@ -210,11 +217,14 @@ async function getMetadataFiles(ctx) { async function getMetadataRestapis(ctx) { try { const models = ctx.fs.dc.models; - const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', resourceId } = ctx.query; const where = { catalog: catalog }; if (keywords) { where.name = { $iLike: `%${keywords}%` }; } + if (resourceId) { + where.id = resourceId; + } const findObj = { include: [ { diff --git a/web/client/src/sections/metadataManagement/containers/databasesTable.js b/web/client/src/sections/metadataManagement/containers/databasesTable.js index 56d081a..55ddb01 100644 --- a/web/client/src/sections/metadataManagement/containers/databasesTable.js +++ b/web/client/src/sections/metadataManagement/containers/databasesTable.js @@ -11,7 +11,7 @@ import MetadataResourceModal from '../components/metadataResourceModal'; const DatabaseTable = (props) => { const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey, - resourceCatalogPath, isRequesting, metadataModels, setView, tagList, metadataResourceApplications } = props; + resourceCatalogPath, isRequesting, metadataModels, setView, tagList, metadataResourceApplications, params } = props; const { metadataManagement } = actions; const SortValues = { 'ascend': 'asc', 'descend': 'desc' }; const [tableData, setTableData] = useState([]); @@ -36,7 +36,7 @@ const DatabaseTable = (props) => { }, [resourceCatalogId]); const initData = (query = {}) => { - dispatch(metadataManagement.getMetadataDatabases({ catalog: resourceCatalogId, keywords, orderBy: 'createAt', ...query })).then(res => { + dispatch(metadataManagement.getMetadataDatabases({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, orderBy: 'createAt', ...query })).then(res => { if (res.success) { setTableData(res.payload.data.rows); setTableDataCount(res.payload.data.count); diff --git a/web/client/src/sections/metadataManagement/containers/filesTable.js b/web/client/src/sections/metadataManagement/containers/filesTable.js index be58619..a0e7ca2 100644 --- a/web/client/src/sections/metadataManagement/containers/filesTable.js +++ b/web/client/src/sections/metadataManagement/containers/filesTable.js @@ -12,7 +12,7 @@ import { RouteTable } from '$utils' const FilesTable = (props) => { const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey, - isRequesting, metadataModels, tagList, metadataResourceApplications } = props; + isRequesting, metadataModels, tagList, metadataResourceApplications, params } = props; const { metadataManagement } = actions; const SortValues = { 'ascend': 'asc', 'descend': 'desc' }; const [tableData, setTableData] = useState([]); @@ -37,7 +37,7 @@ const FilesTable = (props) => { }, []); const initData = (query = {}) => { - dispatch(metadataManagement.getMetadataFiles({ catalog: resourceCatalogId, keywords, orderBy: 'updateAt', ...query })).then(res => { + dispatch(metadataManagement.getMetadataFiles({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, orderBy: 'updateAt', ...query })).then(res => { if (res.success) { setTableData(res.payload.data.rows); setTableDataCount(res.payload.data.count); diff --git a/web/client/src/sections/metadataManagement/containers/latestMetadata.js b/web/client/src/sections/metadataManagement/containers/latestMetadata.js index 1b06efa..369b166 100644 --- a/web/client/src/sections/metadataManagement/containers/latestMetadata.js +++ b/web/client/src/sections/metadataManagement/containers/latestMetadata.js @@ -20,6 +20,12 @@ const LatestMetadata = (props) => { const [resourceCatalogId, setResourceCatalogId] = useState(''); const [resourceCatalogKey, setResourceCatalogKey] = useState(''); const [resourceCatalogPath, setResourceCatalogPath] = useState([]); + const params = GetRequest(location?.search); + + useEffect(() => { + const jumpSelectedKey = sessionStorage.getItem('jumpSelectedKey') || null; + initData(true, jumpSelectedKey); + }, [location?.search]) useEffect(() => { const jumpSelectedKey = sessionStorage.getItem('jumpSelectedKey') || null; @@ -37,8 +43,9 @@ const LatestMetadata = (props) => { if (jumpSelectedKey || selectedKeys.length) expandedKeysData = jumpSelectedKey ? [jumpSelectedKey] : selectedKeys; let expandedKeys = getExpandKeys(expandedKeysData); - setSelectedKeys(expandedKeysData); - setExpandedKeys(expandedKeys); + params?.catalogKey ? setSelectedKeys([params?.catalogKey]) : setSelectedKeys(expandedKeysData); + params?.catalogKey ? setExpandedKeys(getExpandKeys([params?.catalogKey])) : setExpandedKeys(expandedKeys); + params?.treeId && setResourceCatalogId(params?.treeId); expandedKeysData = []; } } else { @@ -52,7 +59,7 @@ const LatestMetadata = (props) => { const keyArr = selectedData[0].split('-'); keyArr.shift();//['rc-2-5']->返回'rc';keyArr:['2','5'] const allExpandedKeys = allTreeNodeKeys.filter(k => keyArr.includes(k.id.toString())); - setResourceCatalogId(keyArr.pop()); + !params?.treeId && setResourceCatalogId(keyArr.pop()); setResourceCatalogKey(selectedData[0]); const resourceCatalogPath = allExpandedKeys.map(a => a.name); setResourceCatalogPath(resourceCatalogPath); @@ -177,6 +184,8 @@ const LatestMetadata = (props) => { const { value } = e.target; onSearch(value); }; + + return @@ -193,6 +202,7 @@ const LatestMetadata = (props) => { expandedKeys={expandedKeys} selectedKeys={selectedKeys} onSelect={(keys, e) => { + history.push(`/metadataManagement/latestMetadata`); if (e.selected) { setSelectedKeys(keys); getExpandKeys(keys); @@ -214,7 +224,14 @@ const LatestMetadata = (props) => { match={match} /> : + resourceCatalogPath={resourceCatalogPath} + params={params} + /> + // } @@ -238,4 +255,17 @@ function mapStateToProps(state) { isRequesting: resourceCatalog.isRequesting }; } -export default connect(mapStateToProps)(LatestMetadata) \ No newline at end of file +export default connect(mapStateToProps)(LatestMetadata) + +function GetRequest(search) { + let url = search; //获取url中"?“符后的字串 + let theRequest = new Object(); + if (url.indexOf("?") != -1) { + let str = url.substr(1); + let strs = str.split("&"); + for (let i = 0; i < strs.length; i++) { + theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); + } + } + return theRequest; +} \ No newline at end of file diff --git a/web/client/src/sections/metadataManagement/containers/metadataTab.js b/web/client/src/sections/metadataManagement/containers/metadataTab.js index ac324cc..a79a43d 100644 --- a/web/client/src/sections/metadataManagement/containers/metadataTab.js +++ b/web/client/src/sections/metadataManagement/containers/metadataTab.js @@ -7,10 +7,11 @@ import RestapisTable from './restapisTable'; import { push } from 'react-router-redux'; const MetadataTab = (props) => { - const { resourceCatalogId, resourceCatalogKey, resourceCatalogPath, actions, dispatch } = props; - const [activeKey, setActiveKey] = useState('databases'); + const { resourceCatalogId, resourceCatalogKey, resourceCatalogPath, actions, dispatch, params } = props; + const [activeKey, setActiveKey] = useState(params?.type || 'databases'); useEffect(() => { - setActiveKey('databases'); + if (!params?.type) + setActiveKey('databases'); }, [resourceCatalogId]); const onTabChange = (key) => { @@ -40,11 +41,11 @@ const MetadataTab = (props) => { ]}> { - activeKey === 'databases' && resourceCatalogId ? : - activeKey === 'files' && resourceCatalogId ? : - activeKey === 'restapis' && resourceCatalogId ? < RestapisTable resourceCatalogId={resourceCatalogId} + activeKey === 'restapis' && resourceCatalogId ? < RestapisTable params={params} resourceCatalogId={resourceCatalogId} resourceCatalogKey={resourceCatalogKey} resourceCatalogPath={resourceCatalogPath} /> : null } diff --git a/web/client/src/sections/metadataManagement/containers/restapisTable.js b/web/client/src/sections/metadataManagement/containers/restapisTable.js index 704df43..2779b8d 100644 --- a/web/client/src/sections/metadataManagement/containers/restapisTable.js +++ b/web/client/src/sections/metadataManagement/containers/restapisTable.js @@ -8,7 +8,7 @@ import MetadataResourceModal from '../components/metadataResourceModal'; const RestapisTable = (props) => { const { user, dispatch, actions, clientHeight, resourceCatalogId, resourceCatalogKey, - isRequesting, metadataModels, tagList, metadataResourceApplications } = props; + isRequesting, metadataModels, tagList, metadataResourceApplications, params } = props; const { metadataManagement } = actions; const [tableData, setTableData] = useState([]); const [tableDataCount, setTableDataCount] = useState(0);//Table数据 @@ -28,7 +28,7 @@ const RestapisTable = (props) => { }, []); const initData = (query = {}) => { - dispatch(metadataManagement.getMetadataRestapis({ catalog: resourceCatalogId, keywords, ...query })).then(res => { + dispatch(metadataManagement.getMetadataRestapis({ resourceId: params?.resourceId, catalog: resourceCatalogId, keywords, ...query })).then(res => { if (res.success) { setTableData(res.payload.data.rows); setTableDataCount(res.payload.data.count); diff --git a/web/client/src/sections/resourceRetrieval/containers/retrieval.js b/web/client/src/sections/resourceRetrieval/containers/retrieval.js index 954f24b..84c124e 100644 --- a/web/client/src/sections/resourceRetrieval/containers/retrieval.js +++ b/web/client/src/sections/resourceRetrieval/containers/retrieval.js @@ -5,17 +5,27 @@ import { useFsRequest, ApiTable } from '$utils'; import { connect } from 'react-redux'; import { downloadImg } from '../utils/index' import KeyModal from '../components/keyModal'; +const METADTA_TYPE = { + '库': 'databases', + '表': 'databases', + '文件': 'files', + '接口': 'restapis', +} import './style.less'; function Retrieval(props) { - const { user } = props; + const { user, catalogs, dispatch, actions } = props; const [keywords, setKeywords] = useState() const [firstInput, setFirstInput] = useState() const [page, setPage] = useState(1) const formRef = React.createRef(); - const { data: catalogs = [] } = useFsRequest({ - url: ApiTable.getResourceCatalog, - }); + // const { data: catalogs = [] } = useFsRequest({ + // url: ApiTable.getResourceCatalog, + // }); + useEffect(() => { + dispatch(actions.metadataManagement.getResourceCatalog()) + }, []) + //检索元数据 const { data: result = {} } = useFsRequest({ url: ApiTable.searchMetadata, query: { @@ -25,6 +35,7 @@ function Retrieval(props) { ready: !!keywords }); + //用户申请资源列表 const { data: approveList = {} } = useFsRequest({ url: ApiTable.approveList, query: { @@ -103,7 +114,7 @@ function Retrieval(props) { 路径:{renderText(catalogText)} 标签:{renderText(tagText)} -
相关操作: { window.open('/metadataManagement/latestMetadata') }}>定位 +
相关操作: { window.open(`/metadataManagement/latestMetadata?type=${METADTA_TYPE[s.type]}&treeId=${s?.catalog}&resourceId=${s.id}&catalogKey=${s.catalogKey}`) }}>定位 {s?.type == '表' || s?.type == '文件' ? user?.role == '数据消费者' ?