mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-21 04:50:14 +08:00
refactor(tree-select): show path
This commit is contained in:
parent
60448314c2
commit
bf56a4c668
@ -249,13 +249,11 @@ export default defineComponent({
|
||||
if (tmNode !== null) {
|
||||
return showPath
|
||||
? treeOption2SelectOptionWithPath(
|
||||
tmNode.rawNode,
|
||||
treeMate
|
||||
.getPath(mergedValue)
|
||||
.treeNodePath.map(({ rawNode }) => rawNode.label),
|
||||
tmNode,
|
||||
treeMate.getPath(mergedValue).treeNodePath,
|
||||
separator
|
||||
)
|
||||
: treeOption2SelectOption(tmNode.rawNode)
|
||||
: treeOption2SelectOption(tmNode)
|
||||
}
|
||||
}
|
||||
return null
|
||||
@ -273,13 +271,11 @@ export default defineComponent({
|
||||
res.push(
|
||||
showPath
|
||||
? treeOption2SelectOptionWithPath(
|
||||
tmNode.rawNode,
|
||||
treeMate
|
||||
.getPath(value)
|
||||
.treeNodePath.map(({ rawNode }) => rawNode.label),
|
||||
tmNode,
|
||||
treeMate.getPath(value).treeNodePath,
|
||||
separator
|
||||
)
|
||||
: treeOption2SelectOption(tmNode.rawNode)
|
||||
: treeOption2SelectOption(tmNode)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { TreeNode } from 'treemate'
|
||||
import { InjectionKey, Ref } from 'vue'
|
||||
import { TreeOptionBase } from '../../tree/src/interface'
|
||||
|
||||
@ -9,6 +10,8 @@ TreeOptionBase,
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
export type TreeSelectTmNode = TreeNode<TreeSelectOption>
|
||||
|
||||
export type OnUpdateValue = (
|
||||
value: string &
|
||||
number &
|
||||
|
@ -1,25 +1,27 @@
|
||||
import { SelectBaseOption } from '../../select/src/interface'
|
||||
import { Key } from '../../tree/src/interface'
|
||||
import { TreeSelectOption } from './interface'
|
||||
import { TreeSelectTmNode, TreeSelectOption } from './interface'
|
||||
|
||||
export function treeOption2SelectOption (
|
||||
treeOpt: TreeSelectOption
|
||||
tmNode: TreeSelectTmNode
|
||||
): SelectBaseOption {
|
||||
const { rawNode } = tmNode
|
||||
return {
|
||||
...treeOpt,
|
||||
value: treeOpt.key
|
||||
...rawNode,
|
||||
value: rawNode.key
|
||||
}
|
||||
}
|
||||
|
||||
export function treeOption2SelectOptionWithPath (
|
||||
treeOpt: TreeSelectOption,
|
||||
treeNodePath: Key[],
|
||||
tmNode: TreeSelectTmNode,
|
||||
path: TreeSelectTmNode[],
|
||||
separator: string
|
||||
): SelectBaseOption {
|
||||
const { rawNode } = tmNode
|
||||
return {
|
||||
disabled: treeOpt.disabled,
|
||||
value: treeOpt.key,
|
||||
label: treeNodePath.join(separator)
|
||||
...rawNode,
|
||||
value: rawNode.key,
|
||||
label: path.map((v) => v.rawNode.label).join(separator)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user