-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: declare Tree Component type #3178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,4 +1,4 @@ | ||
import { defineComponent, inject } from 'vue'; | ||
import { defineComponent, inject, VNode } from 'vue'; | ||
import classNames from '../_util/classNames'; | ||
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; | ||
import FileOutlined from '@ant-design/icons-vue/FileOutlined'; | ||
|
@@ -14,6 +14,47 @@ import { cloneElement } from '../_util/vnode'; | |
import { defaultConfigProvider } from '../config-provider'; | ||
|
||
const TreeNode = VcTree.TreeNode; | ||
|
||
export interface TreeDataItem { | ||
key?: string | number; | ||
title?: string; | ||
isLeaf?: boolean; | ||
selectable?: boolean; | ||
children?: TreeDataItem[]; | ||
disableCheckbox?: boolean; | ||
disabled?: boolean; | ||
class?: string; | ||
style?: any; | ||
checkable?: boolean; | ||
icon?: any; | ||
slots?: any; | ||
scopedSlots?: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没有 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看逻辑上这个属性还是在的,文档上是没了 我给他去掉 |
||
switcherIcon?: any; | ||
} | ||
|
||
interface DefaultEvent { | ||
nativeEvent: MouseEvent; | ||
node: any; | ||
} | ||
|
||
export interface CheckEvent extends DefaultEvent { | ||
checked: boolean; | ||
checkedNodes: VNode[]; | ||
checkedNodesPositions: { node: VNode; pos: string | number }[]; | ||
event: string; | ||
halfCheckedKeys: (string | number)[]; | ||
} | ||
|
||
export interface ExpendEvent extends DefaultEvent { | ||
expanded: boolean; | ||
} | ||
|
||
export interface SelectEvent extends DefaultEvent { | ||
event: string; | ||
selected: boolean; | ||
selectedNodes: VNode[]; | ||
} | ||
|
||
function TreeProps() { | ||
return { | ||
showLine: PropTypes.looseBool, | ||
|
@@ -32,30 +73,36 @@ function TreeProps() { | |
/** 默认展开对应树节点 */ | ||
defaultExpandParent: PropTypes.looseBool, | ||
/** 默认展开指定的树节点 */ | ||
defaultExpandedKeys: PropTypes.array, | ||
defaultExpandedKeys: PropTypes.arrayOf( | ||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
), | ||
/** (受控)展开指定的树节点 */ | ||
expandedKeys: PropTypes.array, | ||
expandedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
/** (受控)选中复选框的树节点 */ | ||
checkedKeys: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
PropTypes.shape({ | ||
checked: PropTypes.array, | ||
halfChecked: PropTypes.array, | ||
checked: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
halfChecked: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
}).loose, | ||
]), | ||
/** 默认选中复选框的树节点 */ | ||
defaultCheckedKeys: PropTypes.array, | ||
defaultCheckedKeys: PropTypes.arrayOf( | ||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
), | ||
/** (受控)设置选中的树节点 */ | ||
selectedKeys: PropTypes.array, | ||
selectedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
/** 默认选中的树节点 */ | ||
defaultSelectedKeys: PropTypes.array, | ||
defaultSelectedKeys: PropTypes.arrayOf( | ||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
), | ||
selectable: PropTypes.looseBool, | ||
|
||
/** filter some AntTreeNodes as you need. it should return true */ | ||
filterAntTreeNode: PropTypes.func, | ||
/** 异步加载数据 */ | ||
loadData: PropTypes.func, | ||
loadedKeys: PropTypes.array, | ||
loadedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])), | ||
// onLoaded: (loadedKeys: string[], info: { event: 'load', node: AntTreeNode; }) => void, | ||
/** 响应右键点击 */ | ||
// onRightClick: (options: AntTreeNodeMouseEvent) => void, | ||
|
@@ -123,7 +170,7 @@ export default defineComponent({ | |
}, | ||
TreeNode, | ||
methods: { | ||
renderSwitcherIcon(prefixCls: string, switcherIcon, { isLeaf, loading, expanded }) { | ||
renderSwitcherIcon(prefixCls: string, switcherIcon: VNode, { isLeaf, loading, expanded }) { | ||
const { showLine } = this.$props; | ||
if (loading) { | ||
return <LoadingOutlined class={`${prefixCls}-switcher-loading-icon`} />; | ||
|
@@ -148,7 +195,7 @@ export default defineComponent({ | |
<CaretDownFilled class={switcherCls} /> | ||
); | ||
}, | ||
updateTreeData(treeData) { | ||
updateTreeData(treeData: TreeDataItem[]) { | ||
const { $slots } = this; | ||
const defaultFields = { children: 'children', title: 'title', key: 'key' }; | ||
const replaceFields = { ...defaultFields, ...this.$props.replaceFields }; | ||
|
@@ -179,18 +226,18 @@ export default defineComponent({ | |
return treeNodeProps; | ||
}); | ||
}, | ||
setTreeRef(node) { | ||
setTreeRef(node: VNode) { | ||
this.tree = node; | ||
}, | ||
handleCheck(checkedObj, eventObj) { | ||
handleCheck(checkedObj: (number | string)[], eventObj: CheckEvent) { | ||
this.$emit('update:checkedKeys', checkedObj); | ||
this.$emit('check', checkedObj, eventObj); | ||
}, | ||
handleExpand(expandedKeys, eventObj) { | ||
handleExpand(expandedKeys: (number | string)[], eventObj: ExpendEvent) { | ||
this.$emit('update:expandedKeys', expandedKeys); | ||
this.$emit('expand', expandedKeys, eventObj); | ||
}, | ||
handleSelect(selectedKeys: string[], eventObj) { | ||
handleSelect(selectedKeys: (number | string)[], eventObj: SelectEvent) { | ||
this.$emit('update:selectedKeys', selectedKeys); | ||
this.$emit('select', selectedKeys, eventObj); | ||
}, | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
很多字段是可选的吧