-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: Tree组件选项支持配置是否可拖拽 #331
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import type { ExtractPropTypes, PropType, InjectionKey, Ref } from 'vue'; | ||
import { CHECK_STRATEGY } from './const'; | ||
import { extractPropsDefaultValue } from '../_util/utils'; | ||
import { CHECK_STRATEGY } from './const'; | ||
import type { ExtractPropTypes, PropType, InjectionKey, Ref } from 'vue'; | ||
|
||
import type { | ||
TreeOption, | ||
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. 这个 code patch 主要对代码的 import 顺序进行了调整,把 除此之外,我没有发现其他的错误风险和需要改进的地方。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { ref, watch } from 'vue'; | ||
import { isNil } from 'lodash-es'; | ||
import { isNil, isUndefined } from 'lodash-es'; | ||
import { concat } from '../_util/utils'; | ||
import type { InnerTreeOption, TreeNodeKey } from './interface'; | ||
import type { TreeProps } from './props'; | ||
import { concat } from '../_util/utils'; | ||
|
||
let uid = 1; | ||
const getUid = () => { | ||
|
@@ -51,6 +51,7 @@ export default ({ props, emit }: { props: TreeProps; emit: any }) => { | |
disabled: item.disabled, | ||
selectable: item.selectable, | ||
checkable: item.checkable, | ||
draggable: isUndefined(item.draggable) ? true : item.draggable, | ||
value, | ||
label, | ||
isLeaf, | ||
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. 此代码补丁对导入的依赖库lodash-es进行了修改,添加了isUndefined方法,并对树节点对象中的draggable属性做了判断,默认设置为true。从代码上来看,没有明显的bug风险。但是如果可拖拽功能并不是所有情况下都需要开启,那么可以根据实际需求,通过配置或者其他方式动态设置draggable属性值。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { onUnmounted, ref } from 'vue'; | ||
import type { InnerTreeOption, TreeNodeKey, DropPosition } from './interface'; | ||
import getPrefixCls from '../_util/getPrefixCls'; | ||
import type { InnerTreeOption, TreeNodeKey, DropPosition } from './interface'; | ||
|
||
const prefixCls = getPrefixCls('tree-node'); | ||
|
||
|
@@ -35,13 +35,22 @@ export default ({ | |
|
||
const handleDragstart = (value: TreeNodeKey, event: DragEvent) => { | ||
const node = nodeList.get(value); | ||
if (!node.draggable) { | ||
// 阻止默认事件,默认事件会有拖拽效果 | ||
event.preventDefault(); | ||
return; | ||
} | ||
dragNode = node; | ||
emit('dragstart', { node, event }); | ||
}; | ||
|
||
const handleDragend = (value: TreeNodeKey, event: DragEvent) => { | ||
resetDragState(); | ||
const node = nodeList.get(value); | ||
if (!node.draggable) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
emit('dragend', { node, event }); | ||
}; | ||
|
||
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. 这段代码是Vue.js组件库中“TreeNode”的一部分。它从文件接口中导入InnerTreeOption、TreeNodeKey和DropPosition三个类型,并定义了一个名为prefixCls的常量。 在代码方面,可以看到差异性非常小,只有顺序上的改变,交换导入模块和获取样式类名的位置。因此如果没问题,并且符合规范,请忽略这个提交。 |
||
|
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.
这个代码补丁似乎是在 TreeOption 接口中添加了一个新属性 draggable。从代码上看,它似乎没有明显的潜在风险或问题。
由于缺少完整的上下文和详细的说明,我无法提供更深入的建议或改进。如果您有相关问题或其他具体需求,请随时提交。