@yqg/permission 1.3.0-alpha.0 → 1.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yqg/permission",
3
- "version": "1.3.0-alpha.0",
3
+ "version": "1.3.0-alpha.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "type": "module",
@@ -5,7 +5,6 @@ export default function useCategory(tree: PermissionType[], checkedIds: string[]
5
5
  const categoryList: CategoryType[] = [];
6
6
  deepTree(tree, (item) => {
7
7
  if (!item.children && checkedIds.includes(item.feature)) {
8
-
9
8
  item.categoryVOS.forEach((category: any) => {
10
9
  category.attributeValueIds_view = category?.attributeValueIds || [];
11
10
  categoryList.push(category);
@@ -9,18 +9,15 @@ const StatusType = {
9
9
  TEMP_OWNER: 'TEMP_OWNER'
10
10
  }
11
11
  export default function useFormat(tree: PermissionListType) {
12
- function sortTree(tree: PermissionListType, sortMap: Map<string | null, number>, levelSortMap: Map<string | null, number>) {
13
- // 对当前层的节点进行排序
14
- tree.sort((a, b) => {
15
- return (sortMap.get(a.businessApplyType) ?? 0) - (sortMap.get(b.businessApplyType) ?? 0)
16
- || (levelSortMap.get(a.securityLevel) ?? 0) - (levelSortMap.get(b.securityLevel) ?? 0);
17
- });
18
-
19
- // 递归对每个节点的子节点进行排序
20
- tree.forEach(node => {
12
+ function sortTree(
13
+ tree: PermissionListType,
14
+ sortMap: Map<string | null, number>,
15
+ levelSortMap: Map<string | null, number>
16
+ ) {
17
+ return tree.map((node) => {
21
18
  node.key = node.feature;
22
- node.desc = 'ddddd'
23
- if (!node.children) {
19
+
20
+ if (!node.children || node.children.length === 0) {
24
21
  node.categoryVOS = (node.categoryVOS || []).filter((item: any) => item.configWay !== Category.AUTO);
25
22
 
26
23
  if ([StatusType.NO].includes(node.businessApplyType)) {
@@ -30,21 +27,30 @@ export default function useFormat(tree: PermissionListType) {
30
27
  if ([StatusType.OWNER, StatusType.PENDING].includes(node.businessApplyType) && !node.categoryVOS.length) {
31
28
  node.disabled = true;
32
29
  }
30
+ } else {
31
+ // 递归对子节点进行排序
32
+ node.children = sortTree(node.children, sortMap, levelSortMap);
33
+
34
+ // 检查所有子节点是否 `disabled === true`
35
+ if (node.children.every((child) => child.disabled)) {
36
+ node.disabled = true;
37
+ }
33
38
  }
34
- if (node.children && node.children.length > 0) {
35
- sortTree(node.children, sortMap, levelSortMap);
36
- }
37
- });
38
39
 
39
- return tree;
40
+ return node;
41
+ }).sort((a, b) => {
42
+ return (sortMap.get(a.businessApplyType) ?? 0) - (sortMap.get(b.businessApplyType) ?? 0)
43
+ || (levelSortMap.get(a.securityLevel) ?? 0) - (levelSortMap.get(b.securityLevel) ?? 0);
44
+ });
40
45
  }
41
46
 
42
47
  // 需要排序,规则:businessApplyType 为 null 在前面, PENDING. OWNER 在中间, NO 在后面
43
48
  // 然后再根据 L1, L2, L3 排序
44
49
  const sort = [null, StatusType.TEMP_OWNER, StatusType.PENDING, StatusType.OWNER, StatusType.NO];
45
- const levelSort = [null, 'L1', 'L2', 'L3'];
50
+ const levelSort = [null, "L1", "L2", "L3"];
46
51
  const sortMap = new Map(sort.map((value, index) => [value, index]));
47
52
  const levelSortMap = new Map(levelSort.map((value, index) => [value, index]));
48
53
 
49
54
  return sortTree(tree, sortMap, levelSortMap);
50
- };
55
+ }
56
+