|
@@ -1,28 +1,40 @@
|
|
|
+import dayjs from 'dayjs'
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import type { ProColumnType, ActionType } from '@ant-design/pro-table'
|
|
|
-import { Button } from 'antd'
|
|
|
import consts from '@/utils/consts'
|
|
|
+import CompanyModal, { ModalType } from '../Detail/components/CompanyModal'
|
|
|
+import { Button } from 'antd'
|
|
|
import { useRef, useState, useEffect } from 'react'
|
|
|
import { connect, history } from 'umi'
|
|
|
+import { queryInstitutionList } from '@/services/api/institution'
|
|
|
+import type { ProColumnType, ActionType } from '@ant-design/pro-table'
|
|
|
import type { ConnectProps } from 'umi'
|
|
|
import type { ProjectModelState } from '../../model'
|
|
|
-import CompanyModal, { ModalType } from '../Detail/components/CompanyModal'
|
|
|
-import { queryInstitutionList } from '@/services/api/institution'
|
|
|
-import dayjs from 'dayjs'
|
|
|
+import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
|
|
|
+import { BaseMenuEnum } from '@/pages/Schema/Base'
|
|
|
// import CompanyName from './CompanyName'
|
|
|
|
|
|
type ListProps = ConnectProps & {
|
|
|
pTypeList: { label: string; value: string }[]
|
|
|
+ base: Record<string, any>
|
|
|
}
|
|
|
|
|
|
-const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
|
|
|
+const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
|
|
|
const tRef = useRef<ActionType>(null)
|
|
|
+ const schema = base?.[BaseMenuEnum.COMPANY]?.schema
|
|
|
useEffect(() => {
|
|
|
if (!pTypeList.length) {
|
|
|
dispatch({
|
|
|
type: 'project/queryProjectTypeList'
|
|
|
})
|
|
|
}
|
|
|
+ if (!base[BaseMenuEnum.COMPANY]) {
|
|
|
+ dispatch({
|
|
|
+ type: 'schemaBase/querySchema',
|
|
|
+ payload: {
|
|
|
+ columnType: BaseMenuEnum.COMPANY
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}, [])
|
|
|
const [state, setState] = useState({
|
|
|
params: {
|
|
@@ -120,13 +132,32 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
|
|
|
)
|
|
|
}
|
|
|
]
|
|
|
+
|
|
|
+ function generateColumns(c, s) {
|
|
|
+ // if (!s) return c
|
|
|
+ console.log(s && JSON.parse(s))
|
|
|
+ // 新的列
|
|
|
+ const nC = [...c]
|
|
|
+ if (s) {
|
|
|
+ const properties = JSON.parse(s).properties
|
|
|
+ const keys = Object.keys(properties)
|
|
|
+ keys.forEach(item => {
|
|
|
+ const isExist = c.some(column => column.dataIndex === item)
|
|
|
+ // 该列在columns中未定义
|
|
|
+ if (!isExist) {
|
|
|
+ nC.splice(-2, 0, { dataIndex: item, title: properties[item].title })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return nC
|
|
|
+ }
|
|
|
return (
|
|
|
<div>
|
|
|
<ProTable<API.InstitutionListItem>
|
|
|
rowKey="ID"
|
|
|
params={state.params}
|
|
|
actionRef={tRef}
|
|
|
- columns={columns}
|
|
|
+ columns={generateColumns(columns, schema)}
|
|
|
request={async (params, filter, sorter) => {
|
|
|
const { code = -1, data: { items = [], totle = 0 } = {} } = await queryInstitutionList({
|
|
|
...params,
|
|
@@ -167,6 +198,9 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-export default connect(({ project }: { project: ProjectModelState }) => ({
|
|
|
- pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID }))
|
|
|
-}))(CompanyList)
|
|
|
+export default connect(
|
|
|
+ ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
|
|
|
+ pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
|
|
|
+ base: schemaBase.base
|
|
|
+ })
|
|
|
+)(CompanyList)
|