Skip to content

Commit

Permalink
feat: tree disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
PengYYYYY committed Aug 10, 2023
1 parent 6b4dde5 commit 7391731
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/tree/tree-node-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,14 @@ export class TreeNodeModel {
public setData(data: OptionData) {
const node = this[nodeKey];
// 详细细节可见 https://github.com/Tencent/tdesign-common/issues/655
const _data = omit(data, ['children', 'value', 'label']);
const _data = omit(data, ['children', 'value', 'label', 'disabled']);
const { keys } = node.tree.config;
const dataValue = data[keys?.value || 'value'];
const dataLabel = data[keys?.label || 'label'];
const dataDisabled = data[keys?.disabled || 'disabled'];
if (!isUndefined(dataValue)) _data.value = dataValue;
if (!isUndefined(dataLabel)) _data.label = dataLabel;
if (!isUndefined(dataDisabled)) _data.disable = dataDisabled;

Object.assign(node.data, _data);
Object.assign(node, _data);
Expand Down
7 changes: 4 additions & 3 deletions js/tree/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const setableStatus: Record<string, boolean | null> = {
expandMutex: null,
activable: null,
checkable: null,
disabled: null,
draggable: null,
loading: false,
};
Expand Down Expand Up @@ -140,6 +139,7 @@ export class TreeNode {
const propChildren = keys.children || 'children';
const propLabel = keys.label || 'label';
const propValue = keys.value || 'value';
const propsDisabled = keys.disabled || 'disabled';

// 节点自身初始化数据
this.model = null;
Expand Down Expand Up @@ -168,7 +168,6 @@ export class TreeNode {
// 这种处理方式主要是解决 treeStore.setConfig 方法配置全局属性导致的状态切换与保留的问题
this.activable = null;
this.checkable = null;
this.disabled = null;
this.expandMutex = null;
this.draggable = null;

Expand All @@ -189,6 +188,8 @@ export class TreeNode {

// 设置标签
this.label = data[propLabel] || '';
// 设置是否禁用
this.disabled = data[propsDisabled];

// 设置子节点
const children = data[propChildren];
Expand Down Expand Up @@ -557,7 +558,7 @@ export class TreeNode {
const { tree } = this;
const keys = Object.keys(item);
keys.forEach((key) => {
if (hasOwnProperty.call(setableStatus, key) || key === 'label') {
if (hasOwnProperty.call(setableStatus, key) || key === 'label' || key === 'disabled') {
this[key] = item[key];
}
});
Expand Down
1 change: 1 addition & 0 deletions js/tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface KeysType {
value?: string;
label?: string;
children?: string;
disabled?: string;
}

export interface TreeNodeState {
Expand Down

0 comments on commit 7391731

Please sign in to comment.