瀏覽代碼

update: width非必选

xyhxx 2 年之前
父節點
當前提交
cec397e5b0

+ 26 - 17
packages/app/src/components/table/hooks.tsx

@@ -52,11 +52,20 @@ function parseColumn<T extends Record<string, unknown>>(
   let rightPosition = parseColumns.reduce(function(prev, next) {
     if (next.fixed !== 'right') return prev;
 
-    return prev + next.width;
+    return prev + (next.width ?? TABLE_CELL_WIDTH.normal);
   }, 0);
 
   const columnList = parseColumns.map(function(val) {
-    const {dataIndex, title, render, align, fixed, width, sort, children} = val;
+    const {
+      dataIndex,
+      title,
+      render,
+      align,
+      fixed,
+      width = TABLE_CELL_WIDTH.normal,
+      sort,
+      children,
+    } = val;
 
     let fixedStyle: CSSProperties = {};
 
@@ -91,7 +100,10 @@ function parseColumn<T extends Record<string, unknown>>(
         header: title,
         columns,
         minSize: 0,
-        size: width,
+        size: columns.reduce(
+          (prev, next) => prev + (next.size ?? TABLE_CELL_WIDTH.normal),
+          0,
+        ),
         meta,
       });
 
@@ -120,6 +132,7 @@ function parseColumn<T extends Record<string, unknown>>(
     return helper.accessor(dataIndex.toString(), {
       header: title?.toString(),
       cell: props => props.getValue(),
+      minSize: 0,
       size: width,
       meta,
     });
@@ -208,20 +221,16 @@ export function useTable<T extends Record<string, any>>(
 
   const preloadData = useContextSection(settingContext, state => state[0]);
 
-  const [columnSizing, setColumnSizing] = useState(function() {
-    if (preloadData?.tableWidth)
-      return JSON.parse(preloadData.tableWidth) as Record<string, number>;
-
-    return {};
-  });
-  const [columnOrder, setColumnOrder] = useState(function() {
-    if (preloadData?.tableOrder)
-      return JSON.parse(preloadData?.tableOrder) as string[];
-
-    const nextList = columns.map(val => val.dataIndex.toString());
-
-    return hasGroup ? [] : ['select', 'no', ...nextList];
-  });
+  const [columnSizing, setColumnSizing] = useState(
+    preloadData?.tableWidth
+      ? JSON.parse(preloadData.tableWidth) as Record<string, number>
+      : {},
+  );
+  const [columnOrder, setColumnOrder] = useState(
+    preloadData?.tableOrder
+      ? JSON.parse(preloadData?.tableOrder) as string[]
+      : [],
+  );
   const [sorting, setSorting] = useState<SortingState>([]);
   const onSortingChangeFn = useLatest(onSortingChange);
   useEffect(function() {

+ 1 - 2
packages/app/src/components/table/index.tsx

@@ -30,7 +30,7 @@ type GroupKey<T extends Record<string, unknown>> = keyof T extends string
 export type LDColumnsType<T extends Record<string, unknown>> = {
   dataIndex: keyof T | GroupKey<T>,
   title: string,
-  width: number,
+  width?: number,
   render?: (info: T, index: number, row: Row<Record<string, any>>) => ReactNode,
   align?: 'left' | 'right' | 'center',
   fixed?: 'left' | 'right',
@@ -175,7 +175,6 @@ export const modifyDataColumns: LDColumnsType<ModifyData>[] = [
   {
     title: '最后修改人',
     dataIndex: 'modifyUser',
-    width: TABLE_CELL_WIDTH.normal,
   },
   {
     title: '最后修改时间',

+ 0 - 2
packages/app/src/pages/menu-second/table/hooks.tsx

@@ -8,12 +8,10 @@ const tableColumns: LDColumnsType<MenuListData>[] = [
   {
     title: '菜单名称',
     dataIndex: 'name',
-    width: TABLE_CELL_WIDTH.normal,
   },
   {
     title: '菜单路径',
     dataIndex: 'url',
-    width: TABLE_CELL_WIDTH.normal,
   },
   {
     title: '菜单排序',

+ 0 - 2
packages/app/src/pages/menu/table/hooks.tsx

@@ -13,12 +13,10 @@ const tableColumns: LDColumnsType<MenuListData>[] = [
   {
     title: '菜单名称',
     dataIndex: 'name',
-    width: TABLE_CELL_WIDTH.normal,
   },
   {
     title: '菜单路径',
     dataIndex: 'url',
-    width: TABLE_CELL_WIDTH.normal,
   },
   {
     title: '菜单排序',

+ 0 - 1
packages/app/src/pages/role/table/hooks.tsx

@@ -8,7 +8,6 @@ const tableColumns: LDColumnsType<RoleListData>[] = [
   {
     title: '角色名称',
     dataIndex: 'roleName',
-    width: TABLE_CELL_WIDTH.normal,
     sort: true,
   },
   {

+ 4 - 4
packages/app/src/pages/user/table/hooks.tsx

@@ -7,11 +7,11 @@ import {TABLE_CELL_WIDTH} from '@utils';
 import {App} from 'antd';
 
 const tableColumns: LDColumnsType<UserListData>[] = [
-  {title: '用户名称', dataIndex: 'userName', width: TABLE_CELL_WIDTH.normal},
-  {title: '真实姓名', dataIndex: 'realName', width: TABLE_CELL_WIDTH.normal},
-  {title: '角色名称', dataIndex: 'role', width: TABLE_CELL_WIDTH.normal},
+  {title: '用户名称', dataIndex: 'userName'},
+  {title: '真实姓名', dataIndex: 'realName'},
+  {title: '角色名称', dataIndex: 'role'},
   {title: '邮箱', dataIndex: 'email', width: TABLE_CELL_WIDTH.middle},
-  {title: '手机号', dataIndex: 'phone', width: TABLE_CELL_WIDTH.normal},
+  {title: '手机号', dataIndex: 'phone'},
   ...modifyDataColumns,
 ];