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

refactor(tree): tree 组件 vue2,vue3 统一业务代码 #2820

Merged
merged 72 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
62de8c5
docs(tree): 添加分支维护备忘
TabSpace Sep 4, 2023
b300a5e
docs(tree): 完善分支维护说明
TabSpace Sep 4, 2023
b3952bc
refactor(tree): 改进代码与 vue3 api 的适配能力
TabSpace Sep 4, 2023
9ce887d
refactor(tree): 修正 treeItem 组件与 vue3 代码适配的问题
TabSpace Sep 4, 2023
3ee8de7
refactor(tree): tree 类型文件更名为 tree-types.ts
TabSpace Sep 11, 2023
cfcab48
refactor(tree): tree 组件使用 useVModel 改进受控逻辑
TabSpace Sep 11, 2023
3e14344
fix(tree): tree 组件,修正受控形态下,赋值结果为空时依然更新了选中状态的问题
TabSpace Sep 11, 2023
b7a5373
test(tree): tree 组件添加测试: actived 受控处理可赋值空值
TabSpace Sep 11, 2023
c7ead0b
test(tree): tree 组件还原 state 示例
TabSpace Sep 11, 2023
69707b6
refactor(tree): tree 组件适配 useVModel 方法,完善 vue3 适配方式
TabSpace Sep 14, 2023
fb6f52d
refactor(tree): tree 组件,改进类型的 vue3 适配
TabSpace Sep 14, 2023
e804c49
refactor(tree): tree 组件解决 vue3 类型警告问题
TabSpace Sep 14, 2023
b0dbbba
refactor(tree): 解决 vue3 类型告警问题
TabSpace Sep 14, 2023
8a0d49c
refactor(tree): 解决组件引用方式在 vue3 告警的问题
TabSpace Sep 14, 2023
e4c6992
refactor(tree): 对照 vue3 代码,改进 useVModel 的使用方式
TabSpace Sep 14, 2023
8351567
test(tree): 解决示例在控制台告警的问题
TabSpace Sep 14, 2023
394bd0c
Merge branch 'develop' into refactor/tree/next
TabSpace Sep 14, 2023
a8ba4e0
refactor(tree): 解决 vue3 h 方法差异问题
TabSpace Sep 14, 2023
d6d6623
refactor(tree): tree 组件,修正 vue3 下 slots 获取方式差异
TabSpace Sep 15, 2023
8d3cd47
refactor(tree): 示例消除 vue2, vue3 差异
TabSpace Sep 15, 2023
85be093
refactor(tree): 解决与 vue3 受控代码保持一致的问题
TabSpace Sep 18, 2023
f7241f2
refactor(tree): tree 组件统一受控示例
TabSpace Sep 18, 2023
29dffaf
refactor(tree): 解决 tree 组件 数据变更示例适配 vue3 环境需要调整逻辑的问题
TabSpace Sep 18, 2023
c280f84
refactor(tree): tree 组件完善示例样式
TabSpace Sep 18, 2023
b4fd750
refactor(tree): tree 组件完善示例样式
TabSpace Sep 18, 2023
9d0e180
refactor(tree): tree 组件,示例代码与 vue3 统一
TabSpace Sep 18, 2023
97a956d
refactor(tree): 改进代码结构,使用共享对象传递公共数据
TabSpace Sep 18, 2023
9935040
refactor(tree): tree 组件改进代码结构
TabSpace Sep 19, 2023
8e8fc2d
refactor(tree): 解决 vue3 未能触发 item render 的问题
TabSpace Sep 19, 2023
efe0b27
refactor(tree): 改进组件结构
TabSpace Sep 19, 2023
91fba44
refactor(tree): 解决 vue3 props.disableCheck 未能正常工作的问题
TabSpace Sep 19, 2023
5c00c8e
refactor(tree): 解决 empty 示例废弃 api 未生效的问题
TabSpace Sep 19, 2023
ba52159
refactor(tree): 解决与 vue3 的示例差异
TabSpace Sep 19, 2023
eac5928
refactor(tree): tree 组件完善节点操作示例
TabSpace Sep 19, 2023
6b87b57
refactor(tree): tree 组件完善属性变更逻辑
TabSpace Sep 20, 2023
cc77610
refactor(tree): tree 组件,解决 setData 方法未能触发新增属性变更的问题
TabSpace Sep 20, 2023
6326b35
refactor(tree): tree 组件,完善同步属性的示例
TabSpace Sep 20, 2023
6b55a30
refactor(tree): tree 组件虚拟滚动示例,降低节点数量便于调试
TabSpace Sep 21, 2023
024c444
refactor(tree): tree 组件,解决虚拟滚动数据变更的状态异常
TabSpace Sep 21, 2023
57fabdd
test(tree): tree 组件,屏蔽动画带来的测试概率性差异
TabSpace Sep 21, 2023
c7910c5
test(tree): tree 组件测试代码格式改进,适配 vue3 项目
TabSpace Sep 21, 2023
90c5295
test(tree): tree 组件,测试代码与 vue3 版本统一
TabSpace Sep 21, 2023
0c071b6
refactor(tree): tree 组件虚拟滚动事件绑定适配 vue3
TabSpace Sep 21, 2023
9a74630
test(tree): tree 组件统一vue2/vue3测试代码形式
TabSpace Sep 22, 2023
d35ea18
test(tree): tree 组件测试用例适配 vue-next 项目
TabSpace Sep 22, 2023
d6beb44
test(tree): tree 组件,vue2,vue3 统一测试用例
TabSpace Sep 22, 2023
83fb4cd
test(tree): tree 组件,vue2,vue3 统一测试用例
TabSpace Sep 22, 2023
ecd6b4e
fix(tree): tree 组件虚拟滚动解决滚动条样式异常问题
TabSpace Sep 22, 2023
81c79ac
refactor(tree): tree 组件文件名称按规范重命名
TabSpace Sep 25, 2023
f5a38be
refactor(tree): tree 组件完善 expand-all 示例
TabSpace Sep 25, 2023
ab0a463
refactor(tree): tree 组件示例样式改进
TabSpace Sep 25, 2023
5a4c7ab
refactor(tree): tree 组件改进示例
TabSpace Sep 25, 2023
2bf4ce5
refactor(tree): 完善组件示例
TabSpace Sep 25, 2023
cbca8dd
refactor(tree): tree 组件完善示例,分拆不同形式虚拟滚动示例
TabSpace Sep 25, 2023
5716e91
refactor(tree): tree 组件改进清空节点的性能
TabSpace Sep 25, 2023
c0e6e5c
refactor(tree): tree 组件,完善虚拟滚动示例。变更受控实现
TabSpace Sep 26, 2023
75ebc63
fix(tree): tree 组件修正受控表现
TabSpace Sep 26, 2023
9c8ee78
fix(tree): tree 组件修正事件触发规则
TabSpace Sep 27, 2023
5248289
test(tree): tree 组件完善单元测试
TabSpace Sep 27, 2023
71cfca5
chore(tree): tree 组件修改,更新 src/_common
TabSpace Oct 10, 2023
273ebb6
chore(tree): merge develop
TabSpace Oct 10, 2023
34935f0
fix(tree): tree 组件, update api
TabSpace Oct 10, 2023
591a52d
test(tree): tree, update snapshot
TabSpace Oct 10, 2023
a74831b
refactor(tree-select): 修正类型告警问题
TabSpace Oct 10, 2023
bd693fe
chore(tree): update common
TabSpace Oct 10, 2023
1a2697b
chore(tree): update example
TabSpace Oct 10, 2023
8c5eae4
test(tree): update snapshot
TabSpace Oct 10, 2023
e569a26
chore: update common
uyarn Oct 11, 2023
69924e7
Merge branch 'develop' into refactor/tree/next
TabSpace Oct 11, 2023
4ec6dd1
chore(tree): update common
TabSpace Oct 11, 2023
64ac2d5
Merge branch 'refactor/tree/next' of github.com:TabSpace/tdesign-vue …
TabSpace Oct 11, 2023
240224e
chore: revert style dir delete
uyarn Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type OptionData = {
} & PlainObject;

export type TreeOptionData<T = string | number> = {
children?: Array<TreeOptionData<T>>;
children?: Array<TreeOptionData<T>> | boolean;
/** option label content */
label?: string | TNode;
/** option search text */
Expand Down
5 changes: 4 additions & 1 deletion src/tree-select/useTreeSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ export default function useTreeSelect(props: TdTreeSelectProps, context: SetupCo
return;
}
const onlyLeafNode = Boolean(
!props.multiple && props.treeProps?.valueMode === 'onlyLeaf' && ctx.node?.data?.children?.length,
!props.multiple
&& props.treeProps?.valueMode === 'onlyLeaf'
&& Array.isArray(ctx.node?.data?.children)
&& ctx.node?.data?.children?.length,
);
let current: TreeSelectValue = value;
const nodeValue = Array.isArray(value) ? value[0] : value;
Expand Down
2 changes: 1 addition & 1 deletion src/tree-select/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getNodeDataByValue(
// results.push(item);
results.set(values[index], item);
}
if (item.children?.length) {
if (Array.isArray(item.children) && item.children?.length) {
getTreeNodeData(values, item.children, keys, results);
}
if (results.size >= values.length) {
Expand Down
49 changes: 49 additions & 0 deletions src/tree/__tests__/activable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,55 @@ describe('Tree:activable', () => {
expect(wrapper.find('[data-value="t1.1"]').classes('t-is-active')).toBe(false);
expect(wrapper.find('[data-value="t1.2"]').classes('t-is-active')).toBe(false);
});

it('actived 受控处理可赋值空值', async () => {
const data = [
{
value: 't1',
children: [
{
value: 't1.1',
},
{
value: 't1.2',
},
],
},
];
const wrapper = mount({
data() {
return {
actived: ['t1'],
};
},
methods: {
onActive(vals) {
const actived = vals.filter((val) => val !== 't1');
this.actived = actived;
},
},
render() {
return (
<Tree
ref="tree"
data={data}
activable
actived={this.actived}
onActive={this.onActive}
expand-all
transition={false}
></Tree>
);
},
});
await delay(1);
expect(wrapper.find('[data-value="t1"]').classes('t-is-active')).toBe(true);
await wrapper.find('[data-value="t1"] .t-tree__label').trigger('click');
expect(wrapper.find('[data-value="t1"]').classes('t-is-active')).toBe(false);
await delay(1);
await wrapper.find('[data-value="t1"] .t-tree__label').trigger('click');
expect(wrapper.find('[data-value="t1"]').classes('t-is-active')).toBe(false);
});
});

describe('props.activeMultiple', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/tree/__tests__/adapt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable import/prefer-default-export */
export { defineComponent } from '@vue/composition-api';
44 changes: 21 additions & 23 deletions src/tree/__tests__/api.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});
expect(wrapper.find('[data-value="t1"]').exists()).toBe(true);
expect(wrapper.find('[data-value="t1.1"]').exists()).toBe(true);
expect(wrapper.find('[data-value="t2"]').exists()).toBe(true);

wrapper.vm.$refs.tree.remove('t2');
await delay(10);

expect(wrapper.find('[data-value="t2"]').exists()).toBe(false);
});
});
Expand All @@ -57,7 +55,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -86,7 +84,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand All @@ -109,7 +107,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -146,7 +144,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} checkable />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} checkable />;
},
});

Expand Down Expand Up @@ -186,7 +184,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} />;
return <Tree ref="tree" transition={false} data={data} />;
},
});

Expand Down Expand Up @@ -224,7 +222,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -264,7 +262,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -308,7 +306,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -354,7 +352,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -392,7 +390,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -430,7 +428,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -472,7 +470,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -518,7 +516,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -556,7 +554,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -594,7 +592,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -636,7 +634,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -668,7 +666,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand All @@ -690,7 +688,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -722,7 +720,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down Expand Up @@ -762,7 +760,7 @@ describe('Tree:api', () => {
];
const wrapper = mount({
render() {
return <Tree ref="tree" data={data} expandAll={true} />;
return <Tree ref="tree" transition={false} data={data} expandAll={true} />;
},
});

Expand Down
Loading
Loading