-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:1.drawerList新增drawerProps属性支持配置抽屉相关属性 2.新增hideColumnNestedObject…
…支持设置drawerList表格内部复杂元素的折叠和隐藏
- Loading branch information
昔梦
committed
Aug 6, 2024
1 parent
8653583
commit 56a6605
Showing
4 changed files
with
128 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,150 @@ | ||
import { Collapse } from 'antd'; | ||
import React from 'react'; | ||
import sortProperties from '../models/sortProperties'; | ||
import FieldItem from './FieldItem'; | ||
import FieldList from './FieldList'; | ||
import sortProperties from '../models/sortProperties'; | ||
import './index.less'; | ||
|
||
interface RenderCoreProps { | ||
schema: any; | ||
rootPath?: any[] | undefined; | ||
parentPath?: any[] | undefined; | ||
[key: string]: any | ||
}; | ||
[key: string]: any; | ||
} | ||
|
||
interface RenderItemProps { | ||
schema: any; | ||
rootPath?: any[] | undefined; | ||
path?: any[] | undefined; | ||
key?: string | undefined; | ||
}; | ||
hideColumnNestedObject?: false | 'hide' | 'collapse'; | ||
} | ||
|
||
const renderItem = (props: RenderItemProps) => { | ||
let { schema, key, path, rootPath } = props; | ||
let { schema, key, path, rootPath, hideColumnNestedObject } = props; | ||
|
||
// render List | ||
if (schema.type === 'array' && schema.items?.type === 'object') { | ||
return ( | ||
<FieldList | ||
key={key} | ||
schema={schema} | ||
path={path} | ||
rootPath={rootPath} | ||
renderCore={RenderCore} | ||
/> | ||
); | ||
if (hideColumnNestedObject === 'hide') { | ||
return '-'; | ||
} else if (hideColumnNestedObject === 'collapse') { | ||
return ( | ||
<Collapse | ||
ghost | ||
items={[ | ||
{ | ||
key: 'detail', | ||
label: '查看详情', | ||
children: ( | ||
<FieldList | ||
key={key} | ||
schema={schema} | ||
path={path} | ||
rootPath={rootPath} | ||
renderCore={RenderCore} | ||
/> | ||
), | ||
}, | ||
]} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<FieldList | ||
key={key} | ||
schema={schema} | ||
path={path} | ||
rootPath={rootPath} | ||
renderCore={RenderCore} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
// render Objiect | field | ||
let child: React.ReactNode = null; | ||
|
||
// has child schema | ||
if (schema?.properties && schema?.widgetType !== 'field') { | ||
child = RenderCore({ schema, parentPath: path, rootPath }) | ||
child = RenderCore({ schema, parentPath: path, rootPath }); | ||
// path = undefined; | ||
} | ||
|
||
if (schema.type === 'object' && hideColumnNestedObject === 'hide') { | ||
return '-'; | ||
} | ||
|
||
if (schema.type === 'object' && hideColumnNestedObject === 'collapse') { | ||
return ( | ||
<Collapse | ||
ghost | ||
items={[ | ||
{ | ||
key: 'detail', | ||
label: '查看详情', | ||
children: ( | ||
<FieldItem | ||
key={key} | ||
schema={schema} | ||
path={path} | ||
rootPath={rootPath} | ||
children={child} | ||
renderCore={RenderCore} | ||
/> | ||
), | ||
}, | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<FieldItem | ||
key={key} | ||
schema={schema} | ||
path={path} | ||
rootPath={rootPath} | ||
children= {child} | ||
children={child} | ||
renderCore={RenderCore} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
const RenderCore = (props: RenderCoreProps) : any => { | ||
const { schema, parentPath = [], rootPath = [] } = props; | ||
const RenderCore = (props: RenderCoreProps): any => { | ||
const { | ||
schema, | ||
parentPath = [], | ||
rootPath = [], | ||
hideColumnNestedObject = false, | ||
} = props; | ||
if (!schema || Object.keys(schema).length === 0) { | ||
return null; | ||
} | ||
|
||
// render List.item | ||
if (schema?.items) { | ||
return renderItem({ schema: schema.items, path: parentPath, rootPath }); | ||
return renderItem({ | ||
schema: schema.items, | ||
path: parentPath, | ||
rootPath, | ||
hideColumnNestedObject, | ||
}); | ||
} | ||
|
||
// render Objiect | field | ||
return sortProperties(Object.entries(schema.properties || {})).map(([key, item]) => { | ||
const path = [...parentPath, key]; | ||
|
||
return renderItem({ schema: item, path, key, rootPath }); | ||
}); | ||
} | ||
return sortProperties(Object.entries(schema.properties || {})).map( | ||
([key, item]) => { | ||
const path = [...parentPath, key]; | ||
|
||
return renderItem({ | ||
schema: item, | ||
path, | ||
key, | ||
rootPath, | ||
hideColumnNestedObject, | ||
}); | ||
} | ||
); | ||
}; | ||
|
||
export default RenderCore; | ||
export default RenderCore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters