Commit d2e324a6 by zhaochengxiang

分支目录增删改

parent 4e03cefc
...@@ -612,6 +612,10 @@ export function* saveBranch(payload) { ...@@ -612,6 +612,10 @@ export function* saveBranch(payload) {
return yield call(datamodelerService.saveBranch, payload) return yield call(datamodelerService.saveBranch, payload)
} }
export function* getBranch(payload) {
return yield call(datamodelerService.getBranch, payload)
}
export function* deleteBranch(payload) { export function* deleteBranch(payload) {
return yield call(datamodelerService.deleteBranch, payload) return yield call(datamodelerService.deleteBranch, payload)
} }
......
...@@ -559,8 +559,12 @@ export function saveBranch(payload) { ...@@ -559,8 +559,12 @@ export function saveBranch(payload) {
return PostJSON("/datamodeler/easyDataModelerBranching/saveBranch", payload) return PostJSON("/datamodeler/easyDataModelerBranching/saveBranch", payload)
} }
export function getBranch(payload) {
return GetJSON("/datamodeler/easyDataModelerBranching/getBranch", payload)
}
export function deleteBranch(payload) { export function deleteBranch(payload) {
return Delete1("/datamodeler/easyDataModelerBranching/deleteBranch", payload) return Delete("/datamodeler/easyDataModelerBranching/deleteBranch", payload)
} }
export function getCooperationUsers() { export function getCooperationUsers() {
......
...@@ -277,7 +277,7 @@ const ModelTree = (props) => { ...@@ -277,7 +277,7 @@ const ModelTree = (props) => {
}); });
} }
const getBranchTreeData = () => { const getBranchTreeData = (defaultSelectedId) => {
setLoading(true); setLoading(true);
dispatch({ dispatch({
type: 'datamodel.getAllBranches', type: 'datamodel.getAllBranches',
...@@ -295,8 +295,20 @@ const ModelTree = (props) => { ...@@ -295,8 +295,20 @@ const ModelTree = (props) => {
setDataList(_dataList); setDataList(_dataList);
setTreeData(newData); setTreeData(newData);
setItem((newData??[]).length>0?newData[0]:{});
onSelect && onSelect((newData??[]).length>0?newData[0].key:''); if (defaultSelectedId) {
const index = (newData??[]).findIndex(item => item?.id === defaultSelectedId)
if (index !== -1) {
setItem(newData[index])
onSelect?.(newData[index].id)
} else if ((newData??[]).length>0) {
setItem(newData[0])
onSelect?.(newData[0].id)
}
} else if ((newData??[]).length>0) {
setItem(newData[0])
onSelect?.(newData[0].id)
}
}, },
error: () => { error: () => {
setLoading(false); setLoading(false);
...@@ -401,7 +413,7 @@ const ModelTree = (props) => { ...@@ -401,7 +413,7 @@ const ModelTree = (props) => {
} else if (viewSelectedKey === 'state') { } else if (viewSelectedKey === 'state') {
getStateTreeData(item?.key||''); getStateTreeData(item?.key||'');
} else if (viewSelectedKey === 'branch') { } else if (viewSelectedKey === 'branch') {
getBranchTreeData() getBranchTreeData(item?.key)
} }
} }
...@@ -433,26 +445,46 @@ const ModelTree = (props) => { ...@@ -433,26 +445,46 @@ const ModelTree = (props) => {
content: '删除目录会删除相关的模型,您确定删除吗?', content: '删除目录会删除相关的模型,您确定删除吗?',
onOk: () => { onOk: () => {
setLoading(true); setLoading(true);
dispatch({ if (viewSelectedKey === 'dir') {
type: 'datamodel.deleteDataModelCatalog', dispatch({
payload: { type: 'datamodel.deleteDataModelCatalog',
params: { payload: {
easyDataModelerCatalogId: currentRightClickDir.id params: {
easyDataModelerCatalogId: currentRightClickDir.id
}
},
callback: () => {
showMessage('success', '删除目录成功');
if (item && currentRightClickDir && item.id===currentRightClickDir.id) {
getDirTreeData();
} else {
getDirTreeData(item.id);
}
},
error: () => {
setLoading(false);
} }
}, });
callback: () => { } else if (viewSelectedKey === 'branch') {
showMessage('success', '删除目录成功'); dispatch({
type: 'datamodel.deleteBranch',
if (item && currentRightClickDir && item.id===currentRightClickDir.id) { payload: {
getDirTreeData(); id: currentRightClickDir?.id,
} else { },
getDirTreeData(item.id); callback: () => {
showMessage('success', '删除目录成功');
if (item?.id === currentRightClickDir?.id) {
getBranchTreeData()
} else {
getBranchTreeData(item.id)
}
},
error: () => {
setLoading(false);
} }
}, });
error: () => { }
setLoading(false);
}
});
} }
}); });
...@@ -682,7 +714,7 @@ const ModelTree = (props) => { ...@@ -682,7 +714,7 @@ const ModelTree = (props) => {
return <span title={nodeData?.remark||''}>{nodeData?.name||''}</span>; return <span title={nodeData?.remark||''}>{nodeData?.name||''}</span>;
}} }}
onRightClick={({event, node}) => { onRightClick={({event, node}) => {
if (viewSelectedKey==='dir'&& isAdmin) { if ((viewSelectedKey==='dir'&&isAdmin) || viewSelectedKey === 'branch') {
setCurrentRightClickDir(node); setCurrentRightClickDir(node);
displayMenu(event); displayMenu(event);
} }
...@@ -702,8 +734,11 @@ const ModelTree = (props) => { ...@@ -702,8 +734,11 @@ const ModelTree = (props) => {
visible={visible} visible={visible}
type={type} type={type}
item={(type==='add')?item:currentRightClickDir} item={(type==='add')?item:currentRightClickDir}
onCancel={() => { onCancel={(val) => {
setVisible(false) setVisible(false)
if (val) {
getBranchTreeData(val?.id)
}
}} }}
/> />
} }
...@@ -712,12 +747,16 @@ const ModelTree = (props) => { ...@@ -712,12 +747,16 @@ const ModelTree = (props) => {
<RcItem id="edit" onClick={update}> <RcItem id="edit" onClick={update}>
修改目录 修改目录
</RcItem> </RcItem>
<RcItem id="up" onClick={() => { moveNode(-1); }}> {
上移目录 viewSelectedKey === 'dir' && <RcItem id="up" onClick={() => { moveNode(-1); }}>
</RcItem> 上移目录
<RcItem id="down" onClick={() => { moveNode(1); }}> </RcItem>
下移目录 }
</RcItem> {
viewSelectedKey === 'dir' && <RcItem id="down" onClick={() => { moveNode(1); }}>
下移目录
</RcItem>
}
<RcItem id="delete" onClick={deleteNode}> <RcItem id="delete" onClick={deleteNode}>
删除目录 删除目录
</RcItem> </RcItem>
......
...@@ -7,45 +7,75 @@ import produce from 'immer' ...@@ -7,45 +7,75 @@ import produce from 'immer'
import { dispatch } from '../../../../model' import { dispatch } from '../../../../model'
import { AppContext } from '../../../../App' import { AppContext } from '../../../../App'
import SelectModel from './branch-select-model' import SelectModel from './branch-select-model'
import { showMessage } from '../../../../util'
const FC = (props) => { const FC = (props) => {
const { visible, type, item, onCancel} = props const { visible, type, item, onCancel} = props
const [loading, setLoading] = React.useState(false)
const [waiting, setWaiting] = React.useState(false) const [waiting, setWaiting] = React.useState(false)
const [branch, setBranch] = React.useState()
const basicRef = React.useRef() const basicRef = React.useRef()
React.useEffect(() => {
if (visible && type === 'update') {
getBranch()
}
}, [visible, type])
const title = React.useMemo(() => { const title = React.useMemo(() => {
if (type === 'add') return '新增项目' if (type === 'add') return '新增项目'
if (type === 'edit') return '编辑项目' if (type === 'update') return '编辑项目'
return '' return ''
}, [type]) }, [type])
const close = () => { const getBranch = () => {
setLoading(true)
dispatch({
type: 'datamodel.getBranch',
payload: {
id: item?.id,
},
callback: (data) => {
setLoading(false)
setBranch(data)
},
error: () => {
setLoading(false)
}
})
}
const close = (val) => {
setLoading(false)
setWaiting(false) setWaiting(false)
onCancel?.() setBranch()
onCancel?.(val)
} }
const save = async () => { const save = async () => {
if (loading) {
showMessage('warn', '正在获取分支详情, 请稍后')
return
}
try { try {
const basicRows = await basicRef.current?.validate() const basicRows = await basicRef.current?.validate()
setWaiting(true) setWaiting(true)
console.log('basic rows', basicRows)
if (type === 'add') { dispatch({
dispatch({ type: 'datamodel.saveBranch',
type: 'datamodel.saveBranch', payload: {
payload: { data: (type==='add')?basicRows:{...branch, ...basicRows},
data: basicRows, },
}, callback: (data) => {
callback: () => { close(data)
close(true) },
}, error: () => {
error: () => { setWaiting(false)
setWaiting(false) }
} })
})
}
} catch (e) { } catch (e) {
} }
...@@ -73,8 +103,8 @@ const FC = (props) => { ...@@ -73,8 +103,8 @@ const FC = (props) => {
centered destroyOnClose centered destroyOnClose
onCancel={() => { close() }} onCancel={() => { close() }}
> >
<Spin spinning={waiting}> <Spin spinning={loading||waiting}>
<Basic ref={basicRef} type={type} item={item} /> <Basic ref={basicRef} type={type} item={branch} />
</Spin> </Spin>
</Modal> </Modal>
) )
...@@ -105,6 +135,19 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -105,6 +135,19 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
})) }))
] ]
}} }}
} else {
rows = {...rows, easyDataModelerMemberShip: {
easyDataModelerMembers: [
...(rows.admins??[]).map(item => ({
admin: true,
...item,
})),
...(rows.members??[]).map(item => ({
admin: false,
...item,
}))
]
}}
} }
return rows return rows
}, },
...@@ -114,6 +157,16 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -114,6 +157,16 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
getUsers() getUsers()
}, []) }, [])
React.useEffect(() => {
if (item) {
form?.setFieldsValue({
...item,
admins: (item?.easyDataModelerMemberShip?.easyDataModelerMembers??[]).filter(item => item.admin),
members: (item?.easyDataModelerMemberShip?.easyDataModelerMembers??[]).filter(item => !item.admin),
})
}
}, [item])
const marginBottom = React.useMemo(() => { const marginBottom = React.useMemo(() => {
return (type === 'detail') ? 5 : 15 return (type === 'detail') ? 5 : 15
}, [type]) }, [type])
...@@ -169,6 +222,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -169,6 +222,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
label='项目负责人' label='项目负责人'
name='admins' name='admins'
style={{ marginBottom }} style={{ marginBottom }}
rules={[{ required: (type==='update'), message: '请选择项目负责人!' }]}
> >
{ {
type === 'add' ? <span>{app?.user?.userName}</span> : <UsersItem loading={loadingUsers} users={users} /> type === 'add' ? <span>{app?.user?.userName}</span> : <UsersItem loading={loadingUsers} users={users} />
...@@ -210,6 +264,7 @@ const UsersItem = ({ loading, users, value, onChange }) => { ...@@ -210,6 +264,7 @@ const UsersItem = ({ loading, users, value, onChange }) => {
return ( return (
<Select loading={loading} mode='multiple' allowClear <Select loading={loading} mode='multiple' allowClear
value={value?.map(item => item.id)}
searchValue={searchValue} searchValue={searchValue}
onSearch={(val) => { onSearch={(val) => {
setSearchValue(val) setSearchValue(val)
......
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