|
|
@@ -29,11 +29,15 @@ import {useLatest} from 'ahooks';
|
|
|
|
|
|
function parseColumn<T extends Record<string, unknown>>(
|
|
|
columns: LDColumnsType<T>[],
|
|
|
- enableSelect?: boolean,
|
|
|
- enableNo?: boolean,
|
|
|
+ options: {
|
|
|
+ enableSelect: boolean,
|
|
|
+ enableNo: boolean,
|
|
|
+ },
|
|
|
) {
|
|
|
+ const {enableSelect, enableNo} = options;
|
|
|
+
|
|
|
const helper = createColumnHelper<Record<string, any>>();
|
|
|
- let hasSort = false, hasGroup = false;
|
|
|
+ let hasSort = false, hasGroup = false, hasEllipsis = false;
|
|
|
|
|
|
const parseColumns: LDColumnsType<T>[] = [...columns];
|
|
|
if (enableNo) {
|
|
|
@@ -65,7 +69,9 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
width = TABLE_CELL_WIDTH.normal,
|
|
|
sort,
|
|
|
children,
|
|
|
+ ellipsis,
|
|
|
} = val;
|
|
|
+ if (ellipsis && !hasEllipsis) hasEllipsis = true;
|
|
|
|
|
|
let fixedStyle: CSSProperties = {};
|
|
|
|
|
|
@@ -85,6 +91,7 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
fixedStyle,
|
|
|
disabledSort: Boolean(fixed) || dataIndex === 'no',
|
|
|
sort,
|
|
|
+ ellipsis,
|
|
|
};
|
|
|
|
|
|
if (children && children.length) {
|
|
|
@@ -92,8 +99,7 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
|
|
|
const {columnList: columns} = parseColumn(
|
|
|
children,
|
|
|
- false,
|
|
|
- false,
|
|
|
+ {enableNo: false, enableSelect: false},
|
|
|
);
|
|
|
|
|
|
const group = helper.group({
|
|
|
@@ -174,6 +180,7 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
columnList,
|
|
|
hasSort,
|
|
|
hasGroup,
|
|
|
+ hasEllipsis,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -201,12 +208,13 @@ export function useTable<T extends Record<string, any>>(
|
|
|
} = options;
|
|
|
|
|
|
const [
|
|
|
- {columnList, hasGroup, hasSort},
|
|
|
+ {columnList, hasGroup, hasSort, hasEllipsis},
|
|
|
setColumns,
|
|
|
] = useState<ReturnType<typeof parseColumn>>({
|
|
|
columnList: [],
|
|
|
hasSort: false,
|
|
|
hasGroup: false,
|
|
|
+ hasEllipsis: false,
|
|
|
});
|
|
|
|
|
|
// 这里不能用useMemo优化 useMemo可能会在useEffect前调用
|
|
|
@@ -214,8 +222,10 @@ export function useTable<T extends Record<string, any>>(
|
|
|
useLayoutEffect(function() {
|
|
|
setColumns(parseColumn(
|
|
|
columns,
|
|
|
- Boolean(setRowSelection),
|
|
|
- true,
|
|
|
+ {
|
|
|
+ enableNo: true,
|
|
|
+ enableSelect: Boolean(setRowSelection),
|
|
|
+ },
|
|
|
));
|
|
|
}, [columns, setRowSelection]);
|
|
|
|
|
|
@@ -297,7 +307,7 @@ export function useTable<T extends Record<string, any>>(
|
|
|
}
|
|
|
|
|
|
return [
|
|
|
- {...table, active, hasSort, hasGroup},
|
|
|
+ {...table, active, hasSort, hasGroup, hasEllipsis},
|
|
|
{onDragStart, onDragEnd},
|
|
|
] as const;
|
|
|
}
|