Skip to content
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

Merged
merged 2 commits into from
Jun 19, 2023
Merged

feat: Tree组件选项支持配置是否可拖拽 #331

merged 2 commits into from
Jun 19, 2023

Conversation

wanchun
Copy link
Collaborator

@wanchun wanchun commented Jun 19, 2023

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

Related issue (if exists):

Other information:

@@ -9,6 +9,7 @@ export interface TreeOption {
disabled?: boolean;
selectable?: boolean;
checkable?: boolean;
draggable?: boolean;
isLeaf?: boolean;
prefix?: string | (() => VNodeChild);
suffix?: string | (() => VNodeChild);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码补丁似乎是在 TreeOption 接口中添加了一个新属性 draggable。从代码上看,它似乎没有明显的潜在风险或问题。

由于缺少完整的上下文和详细的说明,我无法提供更深入的建议或改进。如果您有相关问题或其他具体需求,请随时提交。

import { extractPropsDefaultValue } from '../_util/utils';
import { CHECK_STRATEGY } from './const';
import type { ExtractPropTypes, PropType, InjectionKey, Ref } from 'vue';

import type {
TreeOption,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 code patch 主要对代码的 import 顺序进行了调整,把 import { CHECK_STRATEGY } from './const'; 挪到了前面。这样做可以避免潜在的命名冲突,并提高代码可读性。

除此之外,我没有发现其他的错误风险和需要改进的地方。

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此代码补丁对导入的依赖库lodash-es进行了修改,添加了isUndefined方法,并对树节点对象中的draggable属性做了判断,默认设置为true。从代码上来看,没有明显的bug风险。但是如果可拖拽功能并不是所有情况下都需要开启,那么可以根据实际需求,通过配置或者其他方式动态设置draggable属性值。

if (!node.draggable) {
event.preventDefault();
return;
}
emit('dragend', { node, event });
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码是Vue.js组件库中“TreeNode”的一部分。它从文件接口中导入InnerTreeOption、TreeNodeKey和DropPosition三个类型,并定义了一个名为prefixCls的常量。
代码中包含了两个处理拖放事件的函数handleDragstart和handleDragend,根据节点是否可拖拽来设置dragNode变量,确定是否触发'dragend'或'dragstart'事件,并在执行完成后重置状态。

在代码方面,可以看到差异性非常小,只有顺序上的改变,交换导入模块和获取样式类名的位置。因此如果没问题,并且符合规范,请忽略这个提交。

@winixt winixt merged commit 07a3276 into main Jun 19, 2023
1 check passed
@winixt winixt deleted the feat-tree branch June 19, 2023 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants