Browse Source

update: 优化subComponent状态下checkbox

xyh 2 years ago
parent
commit
50ba69f69f

+ 3 - 2
packages/app/src/components/table/hooks.tsx

@@ -137,6 +137,8 @@ function parseColumn<T extends Record<string, unknown>>(
         );
       },
       cell({row}) {
+        if (row.depth) return null;
+
         return (
           <TableCheck
             checked={row.getIsSelected()}
@@ -149,9 +151,8 @@ function parseColumn<T extends Record<string, unknown>>(
       size: TABLE_CELL_WIDTH.checkbox,
       meta: {
         align: 'center',
-        fixed: 'left',
         disabledSort: true,
-        fixedStyle: {left: 0},
+        fixedStyle: {},
       },
     }),
   );

+ 9 - 5
packages/app/src/hooks/use-table-row-select/index.ts

@@ -14,13 +14,17 @@ export function useTableRowSelect<T extends Record<string, unknown>>(
 
   const selectId = useMemo(function() {
     const result: string[] = [];
-
     for (const [key, value] of Object.entries(rowSelection)) {
-      if (value) {
-        // key返回的对应的数组索引
-        const id = data[Number(key)][rawKey ?? 'id'] as string;
+      // 防止有subComponent时key值获取异常(eg. 1_nosub)
+      try {
+        if (value) {
+          // key返回的对应的数组索引
+          const id = data[Number(key)][rawKey ?? 'id'] as string;
 
-        result.push(id);
+          result.push(id);
+        }
+      } catch {
+        continue;
       }
     }