refactor(tree-select): show path

This commit is contained in:
07akioni 2021-08-07 20:33:49 +08:00
parent 60448314c2
commit bf56a4c668
3 changed files with 20 additions and 19 deletions

View File

@ -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)
)
}
})

View File

@ -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 &

View File

@ -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)
}
}