Commit a56b2178 by zhaochengxiang

模型当前目录搜索

parent cab522e8
...@@ -7,9 +7,9 @@ import Table from '../../ResizeableTable' ...@@ -7,9 +7,9 @@ import Table from '../../ResizeableTable'
import produce from 'immer' import produce from 'immer'
import { paginate } from '../../../../util' import { paginate } from '../../../../util'
import './branch-select-model.less' import { ModelTree } from './model-compare-select-model'
const FC = ({ visible, items, type, onCancel }) => { const FC = ({ visible, items, onCancel }) => {
const [animated, setAnimated] = React.useState(true) const [animated, setAnimated] = React.useState(true)
const basicRef = React.useRef() const basicRef = React.useRef()
...@@ -51,14 +51,18 @@ const FC = ({ visible, items, type, onCancel }) => { ...@@ -51,14 +51,18 @@ const FC = ({ visible, items, type, onCancel }) => {
centered destroyOnClose centered destroyOnClose
onCancel={() => { close() }} onCancel={() => { close() }}
> >
{ !animated && <Basic ref={basicRef} type={type} items={items} /> } { !animated && <Basic ref={basicRef} items={items} /> }
</Modal> </Modal>
) )
} }
export default FC export default FC
const Basic = React.forwardRef(function ({ type, items }, ref) { const Basic = React.forwardRef(function ({ items }, ref) {
const [treeStates, setTreeStates] = React.useState({
type: 'dir',
node: undefined,
})
const [args, setArgs] = React.useState({ const [args, setArgs] = React.useState({
keyword: undefined, keyword: undefined,
}) })
...@@ -66,78 +70,33 @@ const Basic = React.forwardRef(function ({ type, items }, ref) { ...@@ -66,78 +70,33 @@ const Basic = React.forwardRef(function ({ type, items }, ref) {
page: 1, page: 1,
size: 20, size: 20,
}) })
const [loadingTreeData, setLoadingTreeData] = React.useState(false)
const [treeData, setTreeData] = React.useState()
const [node, setNode] = React.useState()
const [rootNode, setRootNode] = React.useState()
const [loading, setLoading] = React.useState(false) const [loading, setLoading] = React.useState(false)
const [data, setData] = React.useState() const [data, setData] = React.useState()
const [selectedRows, setSelectedRows] = React.useState() const [selectedRows, setSelectedRows] = React.useState()
const [expandedKeys, setExpandedKeys] = React.useState([]) const [expandedKeys, setExpandedKeys] = React.useState([])
const [autoExpandParent, setAutoExpandParent] = React.useState(false) const [autoExpandParent, setAutoExpandParent] = React.useState(false)
const [selectedType, setSelectedType] = React.useState('all') const [selectedType, setSelectedType] = React.useState('all')
const prevNodeRef = React.useRef() const { node } = treeStates
const mountRef = React.useRef(true)
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
selectedRows selectedRows
}), [selectedRows]) }), [selectedRows])
React.useEffect(() => { React.useEffect(() => {
getTreeData()
}, [])
React.useEffect(() => {
if (node) {
setArgsByParams({ keyword: '' })
}
}, [node])
React.useEffect(() => {
setPagination({...pagination, page: 1}) setPagination({...pagination, page: 1})
}, [selectedType, node]) }, [selectedType, node])
React.useEffect(() => { React.useEffect(() => {
if (items) { setSelectedRows(items)
setSelectedRows((prev) => {
return items
})
}
}, [items]) }, [items])
useDebounceEffect(() => { useDebounceEffect(() => {
if (rootNode) { if (node) {
getDataModels() getDataModels()
} }
}, [rootNode, args], { wait: 300 }) }, [node, args], { wait: 300 })
const treeData1 = React.useMemo(() => {
if (treeData) {
const newTreeData = produce(treeData, draft => {
const setNode = (g) => {
g.key = g.id;
g.title = g.name;
g.children = [];
(g.subCatalogs??[]).forEach((child) => {
setNode(child)
g.children.push(child)
});
}
draft.forEach((child) => {
setNode(child)
})
})
return newTreeData
}
return undefined
}, [treeData])
const setArgsByParams = React.useCallback((params) => { const setArgsByParams = React.useCallback((params) => {
setArgs((prev) => { setArgs((prev) => {
...@@ -195,26 +154,6 @@ const Basic = React.forwardRef(function ({ type, items }, ref) { ...@@ -195,26 +154,6 @@ const Basic = React.forwardRef(function ({ type, items }, ref) {
}, },
] ]
const getTreeData = () => {
setLoadingTreeData(true)
dispatch({
type: 'datamodel.refreshDataModelCatalog',
callback: (data) => {
setLoadingTreeData(false)
setRootNode(data)
const newTreeData = data?.subCatalogs??[]
setTreeData(newTreeData)
if ((newTreeData??[]).length > 0) {
setNode(newTreeData[0])
}
},
error: () => {
setLoadingTreeData(false)
}
})
}
const getDataModels = () => { const getDataModels = () => {
setLoading(true) setLoading(true)
...@@ -223,10 +162,12 @@ const Basic = React.forwardRef(function ({ type, items }, ref) { ...@@ -223,10 +162,12 @@ const Basic = React.forwardRef(function ({ type, items }, ref) {
type: 'datamodel.searchModel', type: 'datamodel.searchModel',
payload: { payload: {
term: args.keyword, term: args.keyword,
catalogId: node?.id,
}, },
callback: (data) => { callback: (data) => {
setLoading(false) setLoading(false)
setData((data??[]).filter(item => item.supportBranching)) //只显示已上线且不是衍生表的模型
setData((data??[]).filter(item => item.state?.id === '4' && !item.inherited))
}, },
error: () => { error: () => {
setLoading(false) setLoading(false)
...@@ -267,40 +208,20 @@ const Basic = React.forwardRef(function ({ type, items }, ref) { ...@@ -267,40 +208,20 @@ const Basic = React.forwardRef(function ({ type, items }, ref) {
} }
} }
const onTreeExpand = (expandedKeys) => {
setExpandedKeys(expandedKeys)
setAutoExpandParent(false)
}
const onTreeSelect = (selectedKeys, { selectedNodes }) => {
if (selectedKeys.length === 0 || selectedNodes.length === 0) {
return
}
setNode(selectedNodes[0])
}
const onChange = (val) => { const onChange = (val) => {
setSelectedRows(val) setSelectedRows(val)
} }
return ( return (
<div className='branch-select-model'> <div className='branch-select-model'>
<Row> <Row gutter={10}>
<Col span={4}> <Col span={4}>
<Spin spinning={loadingTreeData}> <ModelTree
<Tree showTypeOptions={false}
className='tree' states={treeStates}
showLine setStates={(val) => setTreeStates(val)}
showIcon={false} treeHeight='calc(80vh - 75px)'
autoExpandParent={autoExpandParent} />
treeData={treeData1}
selectedKeys={node?[node.id]:[]}
expandedKeys={expandedKeys}
onSelect={onTreeSelect}
onExpand={onTreeExpand}
/>
</Spin>
</Col> </Col>
<Col span={20}> <Col span={20}>
<div <div
...@@ -321,13 +242,6 @@ const Basic = React.forwardRef(function ({ type, items }, ref) { ...@@ -321,13 +242,6 @@ const Basic = React.forwardRef(function ({ type, items }, ref) {
value={args.keyword} value={args.keyword}
bordered={true} allowClear bordered={true} allowClear
onChange={(e) => { onChange={(e) => {
if (e.target.value) {
prevNodeRef.current = node
setNode()
} else {
setNode(prevNodeRef.current)
}
setArgsByParams({ keyword: e.target.value, page: 1 }) setArgsByParams({ keyword: e.target.value, page: 1 })
}} }}
style={{ width: 200 }} style={{ width: 200 }}
......
.branch-select-model {
.tree {
height: calc(80vh - 30px);
overflow: auto;
}
}
\ No newline at end of file
...@@ -237,7 +237,9 @@ const Basic = React.forwardRef(function ({}, ref) { ...@@ -237,7 +237,9 @@ const Basic = React.forwardRef(function ({}, ref) {
const getModelsByKeywordAndCatalog = () => { const getModelsByKeywordAndCatalog = () => {
let params = { term: args.keyword } let params = { term: args.keyword }
if (type === 'state') { if (type === 'dir') {
params = {...params, catalogId: node?.id }
} else if (type === 'state') {
params = {...params, stateId: node?.id } params = {...params, stateId: node?.id }
} else if (type === 'branch') { } else if (type === 'branch') {
params = {...params, branchId: node?.id } params = {...params, branchId: node?.id }
...@@ -262,74 +264,72 @@ const Basic = React.forwardRef(function ({}, ref) { ...@@ -262,74 +264,72 @@ const Basic = React.forwardRef(function ({}, ref) {
} }
return ( return (
<div className='branch-select-model'> <Row gutter={10}>
<Row> <Col span={4}>
<Col span={4}> <ModelTree
<ModelTree states={treeStates}
states={treeStates} setStates={(val) => setTreeStates(val)}
setStates={(val) => setTreeStates(val)} />
/> </Col>
</Col> <Col span={20}>
<Col span={20}> <div
<div style={{
display: 'flex',
padding: '0px 0px 15px',
alignItems: 'center',
justifyContent: 'flex-end',
}}>
<Input size="middle"
placeholder="请输入关键字搜索"
value={args.keyword}
bordered={true} allowClear
onChange={(e) => {
setArgsByParams({ keyword: e.target.value })
setPagination({ ...pagination, page: 1 })
}}
style={{ width: 200 }}
/>
</div>
<Table
size='small'
extraColWidth={32}
rowKey='id'
loading={loading}
columns={columns}
dataSource={tableData??[]}
pagination={false}
rowSelection={{
type: 'radio',
selectedRowKeys: (selectedRows??[]).map(item => item.id),
onChange: (selectedRowKeys, selectedRows) => {
setSelectedRows(selectedRows)
},
}}
scroll={{ y: 'calc(80vh - 170px)' }}
/>
{
total!==0 && <Pagination
style={{ style={{
display: 'flex', textAlign: 'center',
padding: '0px 0px 15px', marginTop: 15,
alignItems: 'center', }}
justifyContent: 'flex-end', showSizeChanger
}}> onChange={(page,size) => {
<Input size="middle" setPagination({page, size})
placeholder="请输入关键字搜索"
value={args.keyword}
bordered={true} allowClear
onChange={(e) => {
setArgsByParams({ keyword: e.target.value })
setPagination({ ...pagination, page: 1 })
}}
style={{ width: 200 }}
/>
</div>
<Table
size='small'
extraColWidth={32}
rowKey='id'
loading={loading}
columns={columns}
dataSource={tableData??[]}
pagination={false}
rowSelection={{
type: 'radio',
selectedRowKeys: (selectedRows??[]).map(item => item.id),
onChange: (selectedRowKeys, selectedRows) => {
setSelectedRows(selectedRows)
},
}} }}
scroll={{ y: 'calc(80vh - 170px)' }} current={pagination.page}
pageSize={pagination.size}
defaultCurrent={1}
total={total}
showTotal={(total) => `共${total??0}项`}
/> />
{ }
total!==0 && <Pagination </Col>
style={{ </Row>
textAlign: 'center',
marginTop: 15,
}}
showSizeChanger
onChange={(page,size) => {
setPagination({page, size})
}}
current={pagination.page}
pageSize={pagination.size}
defaultCurrent={1}
total={total}
showTotal={(total) => `共${total??0}项`}
/>
}
</Col>
</Row>
</div>
) )
}) })
const ModelTree = ({ states, setStates }) => { export const ModelTree = ({ states, setStates, showTypeOptions = true, treeHeight }) => {
const { type, node, rootNode } = states const { type, node, rootNode } = states
const [loading, setLoading] = React.useState(false) const [loading, setLoading] = React.useState(false)
const [treeData, setTreeData] = React.useState() const [treeData, setTreeData] = React.useState()
...@@ -493,24 +493,26 @@ const ModelTree = ({ states, setStates }) => { ...@@ -493,24 +493,26 @@ const ModelTree = ({ states, setStates }) => {
return ( return (
<Spin spinning={loading}> <Spin spinning={loading}>
<div className='flex' style={{ alignItems: 'center' }}>
<span>模型视角:</span>
<Select
style={{ width: 100 }}
value={type}
onChange={(val) => {
setStates({ ...states, type: val })
}}
>
{
viewModes.map(item => (
<Select.Option key={item.key} value={item.key}>{item.name}</Select.Option>
))
}
</Select>
</div>
{ {
type !== 'state' && <div style={{ marginTop: 10 }}> showTypeOptions && <div className='flex' style={{ alignItems: 'center', marginBottom: 10 }}>
<span>模型视角:</span>
<Select
style={{ width: 100 }}
value={type}
onChange={(val) => {
setStates({ ...states, type: val })
}}
>
{
viewModes.map(item => (
<Select.Option key={item.key} value={item.key}>{item.name}</Select.Option>
))
}
</Select>
</div>
}
{
type !== 'state' && <div style={{ marginBottom: 10 }}>
<AutoComplete <AutoComplete
allowClear allowClear
value={keyword} value={keyword}
...@@ -518,7 +520,7 @@ const ModelTree = ({ states, setStates }) => { ...@@ -518,7 +520,7 @@ const ModelTree = ({ states, setStates }) => {
onSelect={onAutoCompleteSelect} onSelect={onAutoCompleteSelect}
onSearch={onAutoCompleteSearch} onSearch={onAutoCompleteSearch}
onClear={() => { setKeyword() }} onClear={() => { setKeyword() }}
style={{ width: '95%' }} style={{ width: '100%' }}
> >
{ {
(options||[]).map((item, index) => { (options||[]).map((item, index) => {
...@@ -543,7 +545,7 @@ const ModelTree = ({ states, setStates }) => { ...@@ -543,7 +545,7 @@ const ModelTree = ({ states, setStates }) => {
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
onSelect={onTreeSelect} onSelect={onTreeSelect}
onExpand={onTreeExpand} onExpand={onTreeExpand}
style={{ marginTop: 10, height: 'calc(80vh - 115px)', overflow: 'auto' }} style={{ height: treeHeight?treeHeight:'calc(80vh - 115px)', overflow: 'auto' }}
/> />
</Spin> </Spin>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment