-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(search): 新增支持配置字段别名(#2886) * chore: 生成变更记录文件 * feat(search): 修改fieldNames类型 * feat(search): 代码规范 * feat(search): 去掉条件判断 --------- Co-authored-by: xiamiao <[email protected]>
- Loading branch information
1 parent
7fd686e
commit 2e56e30
Showing
4 changed files
with
68 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(search): 支持配置字段别名 |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/search": minor | ||
--- | ||
|
||
feat: 支持配置字段别名 |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HiBaseFieldNameKeys, HiBaseFieldNames } from '@hi-ui/core' | ||
import { SearchDataItem } from './types' | ||
import React from 'react' | ||
|
||
export const transformData = ( | ||
data: SearchDataItem[], | ||
fieldNames?: HiBaseFieldNames | ||
): SearchDataItem[] => { | ||
/** | ||
* 转换对象 | ||
*/ | ||
const getKeyFields = (node: SearchDataItem, key: HiBaseFieldNameKeys) => { | ||
if (fieldNames) { | ||
return node[(fieldNames[key] || key) as keyof SearchDataItem] | ||
} | ||
return node[key as keyof SearchDataItem] | ||
} | ||
|
||
const traverseTreeNode = (node: SearchDataItem): SearchDataItem => { | ||
const newNode: SearchDataItem = { ...node } | ||
|
||
newNode.id = getKeyFields(newNode, 'id') as React.ReactText | ||
newNode.title = getKeyFields(newNode, 'title') as string | ||
newNode.children = getKeyFields(newNode, 'children') as SearchDataItem[] | ||
if (newNode.children) newNode.children = newNode.children.map(traverseTreeNode) | ||
|
||
return newNode | ||
} | ||
|
||
return data.map(traverseTreeNode) | ||
} |