Skip to content

Commit b78e244

Browse files
committed
feat: 调整类型
1 parent fa07266 commit b78e244

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/core/src/tree-operations.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { CheckStatus, TreeNode } from "./types/tree-operations-type";
1+
import type { CheckStatusType, TreeNode } from "./types/tree-operations-type";
2+
import { CheckStatus } from "./types/tree-operations-type";
23

34
/**
45
* ========================
@@ -116,7 +117,7 @@ export function updateTreeCheckStatus(tree: TreeNode[], selectedNodes: TreeNode[
116117
}
117118

118119
// 更新节点及其子节点的选中状态
119-
function updateChildrenCheck(node: TreeNode, checkStatus: CheckStatus): void {
120+
function updateChildrenCheck(node: TreeNode, checkStatus: CheckStatusType): void {
120121
node.check = checkStatus;
121122
if (node.children && node.children.length > 0) {
122123
node.children.forEach((child) => updateChildrenCheck(child, checkStatus));
@@ -186,7 +187,7 @@ export function updateTreeCheckStatusFlat(tree: TreeNode[], selectedNodes: TreeN
186187
});
187188

188189
// 设置节点选中状态
189-
function setCheckStatus(node: TreeNode, status: CheckStatus): void {
190+
function setCheckStatus(node: TreeNode, status: CheckStatusType): void {
190191
node.check = status;
191192
if (pidToChildrenMap.has(node.id)) {
192193
pidToChildrenMap.get(node.id)!.forEach((child) => setCheckStatus(child, status));
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// 节点选择状态枚举
2-
export const CheckStatusMap = {
2+
export type ExtractValue<T> = T[keyof T];
3+
4+
export const CheckStatus = {
35
Unchecked: "0",
46
HalfChecked: "1",
57
Checked: "2"
68
} as const;
79

8-
export type CheckStatus = typeof CheckStatusMap[keyof typeof CheckStatusMap];
10+
export type CheckStatusType = ExtractValue<typeof CheckStatus>;
911

1012
// 树节点类型
1113
export interface TreeNode {
1214
id: string | number;
1315
pid: string | number | null;
14-
check: CheckStatus; // '0':未选中, '1':半选中, '2':选中
16+
check: CheckStatusType; // '0':未选中, '1':半选中, '2':选中
1517
children?: TreeNode[];
1618
[key: string]: any; // 用于支持额外的属性
1719
}

0 commit comments

Comments
 (0)