diff --git a/src/tree-select/src/TreeSelect.tsx b/src/tree-select/src/TreeSelect.tsx index 024cec323..3413ffc75 100644 --- a/src/tree-select/src/TreeSelect.tsx +++ b/src/tree-select/src/TreeSelect.tsx @@ -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) ) } }) diff --git a/src/tree-select/src/interface.ts b/src/tree-select/src/interface.ts index 081e7b5a3..d2f53b85f 100644 --- a/src/tree-select/src/interface.ts +++ b/src/tree-select/src/interface.ts @@ -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 + export type OnUpdateValue = ( value: string & number & diff --git a/src/tree-select/src/utils.ts b/src/tree-select/src/utils.ts index 8100ab2a8..9d2f5e3f5 100644 --- a/src/tree-select/src/utils.ts +++ b/src/tree-select/src/utils.ts @@ -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) } }