|
@@ -1,5 +1,5 @@
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import React, { useRef, useState } from 'react'
|
|
|
+import React, { useEffect, useState } from 'react'
|
|
|
import { Button, Tag } from 'antd'
|
|
|
import { ColumnsType } from 'antd/lib/table'
|
|
|
import styles from './index.less'
|
|
@@ -7,6 +7,8 @@ import useModal from '@/components/Modal'
|
|
|
import AddAssemblyModal from './AddAssemblyModal'
|
|
|
import { queryMatterDetail } from '@/services/api/business'
|
|
|
import consts from '@/utils/consts'
|
|
|
+import useEventEmitter from '@/utils/emit'
|
|
|
+import { EmitterType } from '@/enums/emit'
|
|
|
|
|
|
export enum Assembly {
|
|
|
FORM = 'form', // 表单
|
|
@@ -28,16 +30,57 @@ interface IState {
|
|
|
matterDetail: API.MatterTreeItem
|
|
|
}
|
|
|
|
|
|
-const AssemblyDetail: React.FC<AssemblyDetailProps> = ({ refresh, record }) => {
|
|
|
+const AssemblyDetail: React.FC<AssemblyDetailProps> = ({ refresh, assemblyID }) => {
|
|
|
const [state, setState] = useState<IState>({
|
|
|
matterDetail: {}
|
|
|
})
|
|
|
+
|
|
|
const [modal, ModalDOM] = useModal()
|
|
|
- const tRef = useRef()
|
|
|
- // 刷新
|
|
|
- const refreshData = () => {
|
|
|
- tRef.current.reload()
|
|
|
+
|
|
|
+ const initData = async params => {
|
|
|
+ const { data = {}, code = -1 } = await queryMatterDetail(params)
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ setState({ ...state, matterDetail: data })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // // 刷新
|
|
|
+ // const refreshData = () => {
|
|
|
+ // initData({ ID: assemblyID })
|
|
|
+ // }
|
|
|
+
|
|
|
+ const event$ = useEventEmitter({ global: true })
|
|
|
+ event$.useSubscription(EmitterType.BUSINESS_MATTER_REFRESH, ({ params }) => {
|
|
|
+ const { ID } = params[0]
|
|
|
+
|
|
|
+ initData({ ID })
|
|
|
+ })
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (assemblyID) {
|
|
|
+ initData({ ID: assemblyID })
|
|
|
+ }
|
|
|
+ }, [assemblyID])
|
|
|
+
|
|
|
+ const openModal = () => {
|
|
|
+ modal.open({
|
|
|
+ title: '添加组件',
|
|
|
+ okText: '确认',
|
|
|
+ cancelText: '取消',
|
|
|
+ width: 1000,
|
|
|
+ wrapClassName: 'modalTableBox',
|
|
|
+ children: (
|
|
|
+ <AddAssemblyModal
|
|
|
+ defaultData={state.matterDetail}
|
|
|
+ // refreshData={refreshData}
|
|
|
+ refresh={refresh}
|
|
|
+ close={() => modal.close()}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ footer: null
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
const columns: ColumnsType<API.AssemblyItem> = [
|
|
|
{
|
|
|
title: '组件名称',
|
|
@@ -69,49 +112,23 @@ const AssemblyDetail: React.FC<AssemblyDetailProps> = ({ refresh, record }) => {
|
|
|
}
|
|
|
]
|
|
|
|
|
|
+ // drawerTableBox
|
|
|
return (
|
|
|
- <div className={styles.drawerTableBox}>
|
|
|
- <ProTable
|
|
|
- search={false}
|
|
|
- rowKey="type"
|
|
|
- actionRef={tRef}
|
|
|
- params={{ ID: record?.ID }}
|
|
|
- columns={columns}
|
|
|
- request={async params => {
|
|
|
- const { data = {}, code = -1 } = await queryMatterDetail(params)
|
|
|
- setState({ ...state, matterDetail: data })
|
|
|
- return {
|
|
|
- data:
|
|
|
- data?.assembly?.map(item => ({
|
|
|
- type: item
|
|
|
- })) || [],
|
|
|
- success: code === consts.RET_CODE.SUCCESS
|
|
|
- }
|
|
|
- }}
|
|
|
- className="absolute"
|
|
|
- pagination={false}
|
|
|
- toolBarRender={false}
|
|
|
- />
|
|
|
- <Button
|
|
|
- className="buttonBox"
|
|
|
- onClick={() => {
|
|
|
- modal.open({
|
|
|
- title: '添加组件',
|
|
|
- okText: '确认',
|
|
|
- cancelText: '取消',
|
|
|
- width: 1000,
|
|
|
- wrapClassName: 'modalTableBox',
|
|
|
- children: (
|
|
|
- <AddAssemblyModal
|
|
|
- defaultData={state.matterDetail}
|
|
|
- refreshData={refreshData}
|
|
|
- refresh={refresh}
|
|
|
- close={() => modal.close()}
|
|
|
- />
|
|
|
- ),
|
|
|
- footer: null
|
|
|
- })
|
|
|
- }}>
|
|
|
+ <div className={[styles.assemblyContent, 'mt-24px'].join(' ')}>
|
|
|
+ {state.matterDetail ? (
|
|
|
+ <ProTable
|
|
|
+ search={false}
|
|
|
+ rowKey="type"
|
|
|
+ columns={columns}
|
|
|
+ dataSource={state.matterDetail.assembly?.map(item => ({ type: item }))}
|
|
|
+ className="absolute"
|
|
|
+ bordered
|
|
|
+ size="small"
|
|
|
+ pagination={false}
|
|
|
+ toolBarRender={false}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
+ <Button className="buttonBox" onClick={() => openModal()}>
|
|
|
添加组件
|
|
|
</Button>
|
|
|
{ModalDOM}
|