|
|
@@ -6,6 +6,7 @@ import {
|
|
|
RowSelectionState,
|
|
|
} from '@tanstack/react-table';
|
|
|
import {
|
|
|
+ CSSProperties,
|
|
|
Dispatch,
|
|
|
SetStateAction,
|
|
|
useEffect,
|
|
|
@@ -18,6 +19,7 @@ import {arrayMove} from '@dnd-kit/sortable';
|
|
|
import {createTableSettingContext, useContextSection} from '@hooks';
|
|
|
import TableCheck from './Check';
|
|
|
import {LDColumnsType} from '.';
|
|
|
+import {TABLE_CELL_WIDTH} from '@utils';
|
|
|
|
|
|
function parseColumn<T extends Record<string, unknown>>(
|
|
|
columns: LDColumnsType<T>[],
|
|
|
@@ -25,18 +27,51 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
) {
|
|
|
const helper = createColumnHelper<Record<string, any>>();
|
|
|
|
|
|
- const tableColumns = columns.map(function(val) {
|
|
|
- const {dataIndex, title, render, align, fixed} = val;
|
|
|
+ const parseColumns: LDColumnsType<T>[] = [
|
|
|
+ {
|
|
|
+ title: '序号',
|
|
|
+ dataIndex: 'no',
|
|
|
+ align: 'center',
|
|
|
+ width: TABLE_CELL_WIDTH.no,
|
|
|
+ render(_, index) {
|
|
|
+ return index + 1;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ...columns,
|
|
|
+ ];
|
|
|
+
|
|
|
+ let leftPosition = 0;
|
|
|
+ let rightPosition = parseColumns.reduce(function(prev, next) {
|
|
|
+ if (next.fixed !== 'right') return prev;
|
|
|
+
|
|
|
+ return prev + next.width;
|
|
|
+ }, 0);
|
|
|
+
|
|
|
+ const tableColumns = parseColumns.map(function(val) {
|
|
|
+ const {dataIndex, title, render, align, fixed, width} = val;
|
|
|
+ let fixedStyle: CSSProperties = {};
|
|
|
+
|
|
|
+ if (fixed === 'left') {
|
|
|
+ fixedStyle = {left: leftPosition};
|
|
|
+ leftPosition += width;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fixed === 'right') {
|
|
|
+ rightPosition -= width;
|
|
|
+ fixedStyle = {right: rightPosition};
|
|
|
+ }
|
|
|
+
|
|
|
const meta = {
|
|
|
align,
|
|
|
fixed,
|
|
|
+ fixedStyle,
|
|
|
disabledSort: Boolean(fixed) || dataIndex === 'no',
|
|
|
};
|
|
|
|
|
|
if (render) {
|
|
|
return helper.display({
|
|
|
id: dataIndex.toString(),
|
|
|
- header: title?.toString(),
|
|
|
+ header: title.toString(),
|
|
|
cell(props) {
|
|
|
return render(
|
|
|
props.row.original as T,
|
|
|
@@ -80,21 +115,7 @@ function parseColumn<T extends Record<string, unknown>>(
|
|
|
align: 'center',
|
|
|
fixed: false,
|
|
|
disabledSort: true,
|
|
|
- },
|
|
|
- }),
|
|
|
- );
|
|
|
-
|
|
|
- tableColumns.unshift(
|
|
|
- helper.display({
|
|
|
- header: '序号',
|
|
|
- id: 'no',
|
|
|
- cell({row}) {
|
|
|
- return row.index + 1;
|
|
|
- },
|
|
|
- meta: {
|
|
|
- align: 'center',
|
|
|
- fixed: false,
|
|
|
- disabledSort: true,
|
|
|
+ fixedStyle: {},
|
|
|
},
|
|
|
}),
|
|
|
);
|
|
|
@@ -225,7 +246,7 @@ export function useTableShadow(tableSize: number) {
|
|
|
|
|
|
setScrollProgess(function() {
|
|
|
if (scrollLeft + elWidth === scrollWidth) return 'end';
|
|
|
- if (scrollLeft + elWidth === 0) return 'start';
|
|
|
+ if (scrollLeft === 0) return 'start';
|
|
|
|
|
|
return 'process';
|
|
|
});
|