Commit c7abb5e1 by zhaochengxiang

变更目录

parent 47700a11
...@@ -4,23 +4,47 @@ import { Button, Modal, Spin, Tree, AutoComplete } from 'antd' ...@@ -4,23 +4,47 @@ import { Button, Modal, Spin, Tree, AutoComplete } from 'antd'
import { dispatch } from '../../../model' import { dispatch } from '../../../model'
import { generateList } from './tree' import { generateList } from './tree'
import produce from 'immer' import produce from 'immer'
import { highlightSearchContentByTerms, showMessage } from '../../../util' import { highlightSearchContentByTerms, showMessage, showNotifaction } from '../../../util'
const FC = (props) => { const FC = (props) => {
const { visible, items, onCancel } = props const { visible, items, onCancel } = props
const [waiting, setWaiting] = React.useState(false) const [waiting, setWaiting] = React.useState(false)
const [loading, setLoading] = React.useState(false)
const basicRef = React.useRef() const basicRef = React.useRef()
const close = (refresh = false) => { const close = (refresh = false) => {
setWaiting(false) setWaiting(false)
setLoading(false)
onCancel?.(refresh) onCancel?.(refresh)
} }
const save = () => { const save = () => {
const checkedKeys = basicRef.current?.getCheckedKeys()
if ((checkedKeys??[]).length === 0) {
showMessage('warn', '请先选择资产目录')
return
}
setWaiting(true)
dispatch({
type: 'assetmanage.loadDataAssets',
payload: {
params: {
dirId: checkedKeys.join(","),
},
data: (items??[]).map(item => item.id)
},
callback: data => {
setWaiting(false)
if (data?.message) {
showNotifaction('提示', data?.message, 5)
}
onCancel?.(true)
},
error: () => {
setWaiting(false)
}
})
} }
const footer = React.useMemo(() => { const footer = React.useMemo(() => {
...@@ -45,7 +69,7 @@ const FC = (props) => { ...@@ -45,7 +69,7 @@ const FC = (props) => {
centered destroyOnClose centered destroyOnClose
onCancel={() => { close() }} onCancel={() => { close() }}
> >
<Spin spinning={loading || waiting}> <Spin spinning={waiting}>
<Basic ref={basicRef} items={items} /> <Basic ref={basicRef} items={items} />
</Spin> </Spin>
</Modal> </Modal>
...@@ -64,8 +88,13 @@ const Basic = React.forwardRef(function ({ items }, ref) { ...@@ -64,8 +88,13 @@ const Basic = React.forwardRef(function ({ items }, ref) {
const [options, setOptions] = React.useState() const [options, setOptions] = React.useState()
const [keyword, setKeyword] = React.useState() const [keyword, setKeyword] = React.useState()
React.useImperativeHandle(ref, () => ({
getCheckedKeys: () => checkedKeys
}), [checkedKeys])
React.useEffect(() => { React.useEffect(() => {
getTreeData() getTreeData()
getAssetPaths()
}, []) }, [])
const treeData = React.useMemo(() => { const treeData = React.useMemo(() => {
...@@ -90,6 +119,20 @@ const Basic = React.forwardRef(function ({ items }, ref) { ...@@ -90,6 +119,20 @@ const Basic = React.forwardRef(function ({ items }, ref) {
return [] return []
}, [data]) }, [data])
const getAssetPaths = () => {
if ((items??[]).length > 0) {
dispatch({
type: 'assetmanage.getAssetPaths',
payload: {
dataAssetId: items[0].id,
},
callback: data => {
setCheckedKeys((data??[]).map(item => item.dirId))
}
})
}
}
const getTreeData = () => { const getTreeData = () => {
setLoading(true) setLoading(true)
dispatch({ dispatch({
......
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