|
@@ -16,9 +16,14 @@ const MatterTitleEnum = {
|
|
|
[MatterType.CATEGORY]: '分类名称',
|
|
|
[MatterType.MATTER]: '事项名称'
|
|
|
}
|
|
|
+interface IState {
|
|
|
+ rowKeys?: string
|
|
|
+ record?: Nullable<API.MatterTreeItem>
|
|
|
+}
|
|
|
|
|
|
export function useRowScript(modal: ModalAction, dataID: string) {
|
|
|
- const [rowKeys, setRowKeys] = useState<string[]>([])
|
|
|
+ // const [rowKeys, setRowKeys] = useState<string[]>([])
|
|
|
+ const [state, setState] = useState<IState>({})
|
|
|
const {
|
|
|
data,
|
|
|
run: query,
|
|
@@ -32,18 +37,26 @@ export function useRowScript(modal: ModalAction, dataID: string) {
|
|
|
{
|
|
|
manual: true,
|
|
|
onSuccess(data) {
|
|
|
- setRowKeys(flatMapDeep(data, (item: API.MatterTreeItem) => [item.ID]))
|
|
|
+ setState({
|
|
|
+ ...state,
|
|
|
+ rowKeys: flatMapDeep(data, (item: API.MatterTreeItem) => [item.ID]) || [],
|
|
|
+ record: null
|
|
|
+ })
|
|
|
+ // setRowKeys(flatMapDeep(data, (item: API.MatterTreeItem) => [item.ID]))
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+ const handleRowClick = (record: API.MatterTreeItem) => setState({ ...state, record })
|
|
|
+
|
|
|
/** 新建 */
|
|
|
- const add = (mode: MatterType.CATEGORY | MatterType.MATTER) => {
|
|
|
+ const add = (mode: MatterType.CATEGORY | MatterType.MATTER, record) => {
|
|
|
const text = mode === MatterType.CATEGORY ? '新建分类' : '新建事项'
|
|
|
modal.open({
|
|
|
title: text,
|
|
|
okText: '确定',
|
|
|
cancelText: '取消',
|
|
|
+ initialValues: { parentID: record?.parentID || record?.ID },
|
|
|
type: 'form',
|
|
|
children: (
|
|
|
<ProForm submitter={false} layout="horizontal" labelCol={{ span: 5 }} isKeyPressSubmit>
|
|
@@ -160,7 +173,9 @@ export function useRowScript(modal: ModalAction, dataID: string) {
|
|
|
query,
|
|
|
loading,
|
|
|
treeList: data as API.MatterTreeItem[],
|
|
|
- rowKeys,
|
|
|
+ rowKeys: state.rowKeys,
|
|
|
+ record: state.record,
|
|
|
+ rowClick: handleRowClick,
|
|
|
add,
|
|
|
edit,
|
|
|
del,
|