es-grid-template 1.2.0 → 1.2.2
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/assets/index.css +695 -0
- package/assets/index.scss +1063 -0
- package/es/grid-component/ColumnsChoose.d.ts +1 -0
- package/es/grid-component/ColumnsChoose.js +63 -28
- package/es/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/grid-component/ColumnsGroup/ColumnsGroup.js +223 -0
- package/es/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/es/grid-component/ColumnsGroup/index.js +1 -0
- package/es/grid-component/ConvertColumnTable.d.ts +7 -0
- package/es/grid-component/ConvertColumnTable.js +143 -0
- package/es/grid-component/EditableCell.js +1 -1
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +150 -249
- package/es/grid-component/TableGrid.d.ts +4 -1
- package/es/grid-component/TableGrid.js +31 -70
- package/es/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/es/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/es/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/es/grid-component/hooks/content/HeaderContent.js +79 -0
- package/es/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/es/grid-component/hooks/content/TooltipContent.js +74 -0
- package/es/grid-component/hooks/useColumns.d.ts +16 -0
- package/es/grid-component/hooks/useColumns.js +280 -0
- package/es/grid-component/hooks/utils.d.ts +26 -1
- package/es/grid-component/hooks/utils.js +331 -1
- package/es/grid-component/index.js +3 -1
- package/es/grid-component/styles.scss +365 -68
- package/es/grid-component/table/Grid.d.ts +2 -0
- package/es/grid-component/table/Grid.js +18 -6
- package/es/grid-component/table/GridEdit.d.ts +4 -1
- package/es/grid-component/table/GridEdit.js +941 -307
- package/es/grid-component/table/Group.d.ts +13 -0
- package/es/grid-component/table/Group.js +154 -0
- package/es/grid-component/type.d.ts +39 -2
- package/lib/grid-component/ColumnsChoose.d.ts +1 -0
- package/lib/grid-component/ColumnsChoose.js +62 -27
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +234 -0
- package/lib/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/lib/grid-component/ColumnsGroup/index.js +16 -0
- package/lib/grid-component/ConvertColumnTable.d.ts +7 -0
- package/lib/grid-component/ConvertColumnTable.js +152 -0
- package/lib/grid-component/EditableCell.js +1 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +144 -249
- package/lib/grid-component/TableGrid.d.ts +4 -1
- package/lib/grid-component/TableGrid.js +26 -68
- package/lib/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/lib/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/lib/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/lib/grid-component/hooks/content/HeaderContent.js +86 -0
- package/lib/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/lib/grid-component/hooks/content/TooltipContent.js +81 -0
- package/lib/grid-component/hooks/useColumns.d.ts +16 -0
- package/lib/grid-component/hooks/useColumns.js +291 -0
- package/lib/grid-component/hooks/utils.d.ts +26 -1
- package/lib/grid-component/hooks/utils.js +347 -5
- package/lib/grid-component/index.js +2 -1
- package/lib/grid-component/styles.scss +365 -68
- package/lib/grid-component/table/Grid.d.ts +2 -0
- package/lib/grid-component/table/Grid.js +18 -6
- package/lib/grid-component/table/GridEdit.d.ts +4 -1
- package/lib/grid-component/table/GridEdit.js +939 -305
- package/lib/grid-component/table/Group.d.ts +13 -0
- package/lib/grid-component/table/Group.js +163 -0
- package/lib/grid-component/type.d.ts +39 -2
- package/package.json +106 -105
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
// import type {Key} from 'react';
|
|
3
|
+
import { Fragment, useCallback } from 'react';
|
|
4
|
+
// import Command from "../Command";
|
|
5
|
+
import { Button, Space } from "antd";
|
|
6
|
+
import { Select } from "rc-master-ui";
|
|
7
|
+
import { getTypeFilter } from "./utils";
|
|
8
|
+
import { booleanOperator, numberOperator, stringOperator, translateOption } from "./constant";
|
|
9
|
+
import { flatColumns2, renderContent, renderFilter } from "./columns";
|
|
10
|
+
import { SearchOutlined } from "@ant-design/icons";
|
|
11
|
+
import { ArrowDown, ArrowUp, FilterFill } from "becoxy-icons";
|
|
12
|
+
import classNames from "classnames";
|
|
13
|
+
import HeaderContent from "./content/HeaderContent";
|
|
14
|
+
const ASCEND = 'ascend';
|
|
15
|
+
const DESCEND = 'descend';
|
|
16
|
+
export const SELECTION_COLUMN = {};
|
|
17
|
+
|
|
18
|
+
// const EMPTY_LIST: React.Key[] = [];
|
|
19
|
+
|
|
20
|
+
const useColumns = config => {
|
|
21
|
+
// const {
|
|
22
|
+
// preserveSelectedRowKeys,
|
|
23
|
+
// selectedRowKeys,
|
|
24
|
+
// defaultSelectedRowKeys,
|
|
25
|
+
// onSelectMultiple,
|
|
26
|
+
// columnWidth: selectionColWidth,
|
|
27
|
+
// type: selectionType,
|
|
28
|
+
// selections,
|
|
29
|
+
// fixed,
|
|
30
|
+
// } = rowSelection || {};
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
t,
|
|
34
|
+
dataSourceFilter,
|
|
35
|
+
buddhistLocale,
|
|
36
|
+
locale,
|
|
37
|
+
sortMultiple,
|
|
38
|
+
format,
|
|
39
|
+
handleResize,
|
|
40
|
+
groupAble,
|
|
41
|
+
groupColumns,
|
|
42
|
+
groupSetting
|
|
43
|
+
} = config;
|
|
44
|
+
|
|
45
|
+
// ====================== Selections ======================
|
|
46
|
+
|
|
47
|
+
const handleSearch = (selectedKeys, confirm) => {
|
|
48
|
+
confirm();
|
|
49
|
+
};
|
|
50
|
+
const getColumnSearchProps = useCallback(column => ({
|
|
51
|
+
filterDropdown: ({
|
|
52
|
+
setSelectedKeys,
|
|
53
|
+
selectedKeys,
|
|
54
|
+
confirm,
|
|
55
|
+
// close,
|
|
56
|
+
setOperatorKey,
|
|
57
|
+
operatorKey,
|
|
58
|
+
visible,
|
|
59
|
+
searchValue,
|
|
60
|
+
setSearchValue
|
|
61
|
+
}) => {
|
|
62
|
+
const type = getTypeFilter(column);
|
|
63
|
+
// const operatorOptions = !type || type === 'Text' ? stringOperator : numberOperator
|
|
64
|
+
// const operatorOptions = type === 'Checkbox' || type === 'Dropdown' || type === 'DropTree' || ty
|
|
65
|
+
const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? booleanOperator : !type || type === 'Text' ? stringOperator : numberOperator;
|
|
66
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
67
|
+
style: {
|
|
68
|
+
padding: 8,
|
|
69
|
+
minWidth: 275
|
|
70
|
+
},
|
|
71
|
+
onKeyDown: e => e.stopPropagation()
|
|
72
|
+
}, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: 'mb-1'
|
|
74
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
75
|
+
options: translateOption(operatorOptions, t),
|
|
76
|
+
style: {
|
|
77
|
+
width: '100%',
|
|
78
|
+
marginBottom: 8
|
|
79
|
+
},
|
|
80
|
+
value: operatorKey,
|
|
81
|
+
onChange: val => {
|
|
82
|
+
setOperatorKey(val);
|
|
83
|
+
}
|
|
84
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
style: {
|
|
86
|
+
marginBottom: 8
|
|
87
|
+
}
|
|
88
|
+
}, renderFilter(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, dataSourceFilter, buddhistLocale, locale, t)), /*#__PURE__*/React.createElement(Space, {
|
|
89
|
+
style: {
|
|
90
|
+
justifyContent: 'end',
|
|
91
|
+
width: '100%'
|
|
92
|
+
}
|
|
93
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
94
|
+
type: "primary",
|
|
95
|
+
onClick: () => {
|
|
96
|
+
confirm({
|
|
97
|
+
closeDropdown: false
|
|
98
|
+
});
|
|
99
|
+
handleSearch(selectedKeys, confirm);
|
|
100
|
+
},
|
|
101
|
+
icon: /*#__PURE__*/React.createElement(SearchOutlined, null),
|
|
102
|
+
size: "small",
|
|
103
|
+
style: {
|
|
104
|
+
width: 90
|
|
105
|
+
}
|
|
106
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(Button, {
|
|
107
|
+
type: "link",
|
|
108
|
+
size: "small",
|
|
109
|
+
onClick: () => {
|
|
110
|
+
// setSearchValue('')
|
|
111
|
+
setSelectedKeys([]);
|
|
112
|
+
confirm();
|
|
113
|
+
// handleSearch()
|
|
114
|
+
// close()
|
|
115
|
+
}
|
|
116
|
+
}, t ? t("Clear") : 'Clear')));
|
|
117
|
+
},
|
|
118
|
+
filterIcon: filtered => /*#__PURE__*/React.createElement(FilterFill, {
|
|
119
|
+
fontSize: 12
|
|
120
|
+
// onClick={() => {
|
|
121
|
+
// onFilterClick?.(column, onFilterCallback)
|
|
122
|
+
// }}
|
|
123
|
+
,
|
|
124
|
+
style: {
|
|
125
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
filterDropdownProps: {
|
|
129
|
+
onOpenChange(open) {
|
|
130
|
+
if (open) {
|
|
131
|
+
// setTimeout(() => searchInput.current?.select(), 100)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}), [buddhistLocale, dataSourceFilter, locale, t]);
|
|
136
|
+
|
|
137
|
+
// ======================= Columns ========================
|
|
138
|
+
const transformColumns = useCallback(columns => {
|
|
139
|
+
// >>>>>>>>>>> Support selection
|
|
140
|
+
const cloneColumns = [...columns];
|
|
141
|
+
const firstNonGroupColumn = flatColumns2(cloneColumns).find(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
142
|
+
const nonGroupColumns = flatColumns2(cloneColumns).filter(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
143
|
+
|
|
144
|
+
// ===================== Render =====================
|
|
145
|
+
|
|
146
|
+
const convertColumns = cols => {
|
|
147
|
+
return cols.map(col => {
|
|
148
|
+
const colIndex = flatColumns2(cols).findIndex(it => it.field === col.field);
|
|
149
|
+
if (col === SELECTION_COLUMN) {
|
|
150
|
+
return SELECTION_COLUMN;
|
|
151
|
+
}
|
|
152
|
+
const transformedColumn = {
|
|
153
|
+
...col,
|
|
154
|
+
dataIndex: col.field ?? col.dataIndex,
|
|
155
|
+
key: col.field ?? col.dataIndex ?? col.key,
|
|
156
|
+
// title: t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title,
|
|
157
|
+
// title: () => (<span>aaa</span>),
|
|
158
|
+
title: () => /*#__PURE__*/React.createElement(HeaderContent, {
|
|
159
|
+
column: {
|
|
160
|
+
...col
|
|
161
|
+
},
|
|
162
|
+
t: t
|
|
163
|
+
}),
|
|
164
|
+
// title: () => (<span>{t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title}</span>),
|
|
165
|
+
ellipsis: col.ellipsis !== false,
|
|
166
|
+
align: col.textAlign ?? col.align,
|
|
167
|
+
fixed: col.frozen ? col.frozen.toLowerCase() : col.fixed
|
|
168
|
+
};
|
|
169
|
+
if (transformedColumn.children && transformedColumn.children?.length) {
|
|
170
|
+
return {
|
|
171
|
+
...transformedColumn,
|
|
172
|
+
children: convertColumns(transformedColumn.children)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (["index", "#"].includes(col.field)) {
|
|
176
|
+
return {
|
|
177
|
+
...transformedColumn,
|
|
178
|
+
onCell: () => ({
|
|
179
|
+
className: 'cell-number'
|
|
180
|
+
}),
|
|
181
|
+
render: (_, __, rowIndex) => rowIndex + 1
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (col.key === 'command') {
|
|
185
|
+
return {
|
|
186
|
+
...transformedColumn,
|
|
187
|
+
onCell: () => ({
|
|
188
|
+
className: 'cell-number',
|
|
189
|
+
style: {
|
|
190
|
+
padding: '2px 8px'
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
...transformedColumn,
|
|
197
|
+
...(transformedColumn.allowFiltering === false ? {} : {
|
|
198
|
+
...getColumnSearchProps(col)
|
|
199
|
+
}),
|
|
200
|
+
sorter: col.sorter === false ? undefined : {
|
|
201
|
+
compare: a => a,
|
|
202
|
+
multiple: sortMultiple ? colIndex : undefined
|
|
203
|
+
},
|
|
204
|
+
sortIcon: args => {
|
|
205
|
+
const {
|
|
206
|
+
sortOrder
|
|
207
|
+
} = args;
|
|
208
|
+
return /*#__PURE__*/React.createElement(Fragment, null, !sortOrder && /*#__PURE__*/React.createElement(ArrowUp, {
|
|
209
|
+
fontSize: 15,
|
|
210
|
+
style: {
|
|
211
|
+
display: 'flex',
|
|
212
|
+
opacity: 0,
|
|
213
|
+
marginLeft: 4
|
|
214
|
+
},
|
|
215
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
216
|
+
active: true
|
|
217
|
+
})
|
|
218
|
+
}), sortOrder === ASCEND && /*#__PURE__*/React.createElement("span", {
|
|
219
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
220
|
+
active: sortOrder === ASCEND
|
|
221
|
+
}),
|
|
222
|
+
style: {
|
|
223
|
+
display: 'flex',
|
|
224
|
+
marginLeft: 4
|
|
225
|
+
}
|
|
226
|
+
}, /*#__PURE__*/React.createElement(ArrowUp, {
|
|
227
|
+
fontSize: 15,
|
|
228
|
+
color: '#000'
|
|
229
|
+
})), sortOrder === DESCEND && /*#__PURE__*/React.createElement("span", {
|
|
230
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
231
|
+
active: sortOrder === DESCEND
|
|
232
|
+
}),
|
|
233
|
+
style: {
|
|
234
|
+
display: 'flex',
|
|
235
|
+
marginLeft: 4
|
|
236
|
+
}
|
|
237
|
+
}, /*#__PURE__*/React.createElement(ArrowDown, {
|
|
238
|
+
fontSize: 15,
|
|
239
|
+
color: '#000'
|
|
240
|
+
})));
|
|
241
|
+
},
|
|
242
|
+
onHeaderCell: () => ({
|
|
243
|
+
width: col.width,
|
|
244
|
+
onResize: handleResize?.(col)
|
|
245
|
+
}),
|
|
246
|
+
onCell: data => {
|
|
247
|
+
return {
|
|
248
|
+
colSpan: data.children && col.field === firstNonGroupColumn?.field ? 2 : data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
|
|
249
|
+
zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
|
|
250
|
+
className: classNames('', {
|
|
251
|
+
'cell-group': data.children,
|
|
252
|
+
'cell-group-fixed': data.children && col.field === firstNonGroupColumn?.field
|
|
253
|
+
})
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
render: (value, record, rowIndex) => {
|
|
257
|
+
if (groupSetting && groupSetting.hiddenColumnGroup === false) {
|
|
258
|
+
if (record.children) {
|
|
259
|
+
return renderContent(col, value, record, rowIndex, format);
|
|
260
|
+
}
|
|
261
|
+
if (groupColumns?.includes(col.field)) {
|
|
262
|
+
return '';
|
|
263
|
+
}
|
|
264
|
+
return renderContent(col, value, record, rowIndex, format);
|
|
265
|
+
}
|
|
266
|
+
if (col.field === firstNonGroupColumn?.field && record.children) {
|
|
267
|
+
const currentGroupColumn = flatColumns2(cols).find(it => it.field === record.field);
|
|
268
|
+
return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", renderContent(currentGroupColumn, record[record.field], record, rowIndex, format));
|
|
269
|
+
}
|
|
270
|
+
return renderContent(col, value, record, rowIndex, format);
|
|
271
|
+
},
|
|
272
|
+
hidden: groupSetting && groupSetting.hiddenColumnGroup === false ? col.hidden : groupAble && groupColumns && groupColumns.includes(col.field) ? true : col.hidden
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
return convertColumns(cloneColumns);
|
|
277
|
+
}, [format, getColumnSearchProps, groupAble, groupColumns, groupSetting, handleResize, sortMultiple, t]);
|
|
278
|
+
return [transformColumns];
|
|
279
|
+
};
|
|
280
|
+
export default useColumns;
|
|
@@ -5,6 +5,7 @@ import type { ColumnEditType, ColumnsType, ColumnTable, GetRowKey } from "../typ
|
|
|
5
5
|
import type { SelectionSettings } from "../type";
|
|
6
6
|
import type { AnyObject } from "../type";
|
|
7
7
|
import type { Key } from "react";
|
|
8
|
+
import type { ColumnsTable } from "./../index";
|
|
8
9
|
export declare const newGuid: () => any;
|
|
9
10
|
export declare const sumDataByField: (data: any[], field: string) => any;
|
|
10
11
|
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
@@ -19,6 +20,7 @@ export declare const getAllVisibleKeys: (columns: any[]) => any[];
|
|
|
19
20
|
export declare const getVisibleColumnKeys: (columns: any[]) => string[];
|
|
20
21
|
export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
|
|
21
22
|
export declare const updateColumns: (columns: any[], includes: string[]) => any[];
|
|
23
|
+
export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
|
|
22
24
|
export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, col: ColumnTable<any>) => string;
|
|
23
25
|
export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
|
|
24
26
|
export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
|
|
@@ -38,6 +40,29 @@ export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'nu
|
|
|
38
40
|
export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
|
|
39
41
|
export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
|
|
40
42
|
export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
|
|
41
|
-
export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName:
|
|
43
|
+
export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: string, data?: RecordType[]) => RecordType[];
|
|
42
44
|
export declare const countItemsBeforeIndex: (array: any[], index: number) => number;
|
|
43
45
|
export declare const getRowNumber: (array: any[], rowKey: any, key: any) => number;
|
|
46
|
+
export declare const getDefaultValue: (defaultValue: any) => AnyObject;
|
|
47
|
+
export declare const addRowIdArray: (inputArray: any[]) => any[];
|
|
48
|
+
export declare const findItemByKey: (array: any, key: string | number, value: any) => any;
|
|
49
|
+
export declare const getLastSelectCell: (selectCells: any) => {
|
|
50
|
+
row: number;
|
|
51
|
+
col: number;
|
|
52
|
+
};
|
|
53
|
+
export declare const getFirstSelectCell: (selectCells: any) => {
|
|
54
|
+
row: number;
|
|
55
|
+
col: number;
|
|
56
|
+
};
|
|
57
|
+
export declare const getRowsPasteIndex: (pasteRows: any) => number[];
|
|
58
|
+
export declare function addRows8(arr: any, n: number): {
|
|
59
|
+
combined: any;
|
|
60
|
+
addedRows: any[];
|
|
61
|
+
} | {
|
|
62
|
+
combined: any[];
|
|
63
|
+
addedRows: any[];
|
|
64
|
+
};
|
|
65
|
+
export declare const transformColumns: <RecordType>(cols: ColumnsTable<RecordType>, convertColumns: any[], t?: any) => ColumnsTable<RecordType>;
|
|
66
|
+
export declare const transformColumns1: <RecordType>(cols: ColumnsTable<RecordType>, sortMultiple?: boolean) => ColumnsTable<RecordType>;
|
|
67
|
+
export declare const removeColumns: <RecordType>(columns: ColumnsTable<RecordType>, groupColumns: string[]) => ColumnsTable<RecordType>;
|
|
68
|
+
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|
|
@@ -2,6 +2,8 @@ import dayjs from "dayjs";
|
|
|
2
2
|
import moment from "moment/moment";
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { presetPalettes } from "@ant-design/colors";
|
|
5
|
+
import { Table } from "rc-master-ui";
|
|
6
|
+
import { flatColumns2 } from "./columns";
|
|
5
7
|
export const newGuid = () => {
|
|
6
8
|
for (let i = 0; i < 20; i++) {
|
|
7
9
|
// @ts-ignore
|
|
@@ -143,6 +145,26 @@ export const updateColumns = (columns, includes) => {
|
|
|
143
145
|
return newColumn;
|
|
144
146
|
});
|
|
145
147
|
};
|
|
148
|
+
export const updateColumnsByGroup = (columns, columnsGroup) => {
|
|
149
|
+
return columns.map(column => {
|
|
150
|
+
const newColumn = {
|
|
151
|
+
...column
|
|
152
|
+
};
|
|
153
|
+
let hasVisibleChild = false;
|
|
154
|
+
if (!column.key && !column.dataIndex) {
|
|
155
|
+
return column;
|
|
156
|
+
}
|
|
157
|
+
if (newColumn.children) {
|
|
158
|
+
newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
|
|
159
|
+
hasVisibleChild = newColumn.children.some(child => !child.hidden);
|
|
160
|
+
}
|
|
161
|
+
newColumn.hidden = newColumn.key && columnsGroup.includes(newColumn.key);
|
|
162
|
+
if (newColumn.children && newColumn.children.length > 0) {
|
|
163
|
+
newColumn.hidden = !hasVisibleChild;
|
|
164
|
+
}
|
|
165
|
+
return newColumn;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
146
168
|
export const getDatepickerFormat = (type, col) => {
|
|
147
169
|
const typeFormat = type ? type.toLowerCase() : '';
|
|
148
170
|
switch (typeFormat) {
|
|
@@ -197,7 +219,10 @@ export const getTypeFilter = col => {
|
|
|
197
219
|
};
|
|
198
220
|
export const updateArrayByKey = (arr, element, key) => {
|
|
199
221
|
if (arr) {
|
|
200
|
-
return arr.map(
|
|
222
|
+
return arr.map(it => {
|
|
223
|
+
const item = {
|
|
224
|
+
...it
|
|
225
|
+
};
|
|
201
226
|
if (item[key] === element[key]) {
|
|
202
227
|
return {
|
|
203
228
|
...item,
|
|
@@ -381,4 +406,309 @@ export const getRowNumber = (array, rowKey, key) => {
|
|
|
381
406
|
// const flattArray = flattenArray(array)
|
|
382
407
|
const flattArray = flattenData('children', array);
|
|
383
408
|
return flattArray.findIndex(it => it[key] === rowKey);
|
|
409
|
+
};
|
|
410
|
+
export const getDefaultValue = defaultValue => {
|
|
411
|
+
if (defaultValue && typeof defaultValue === 'function') {
|
|
412
|
+
return defaultValue();
|
|
413
|
+
}
|
|
414
|
+
return defaultValue;
|
|
415
|
+
};
|
|
416
|
+
export const addRowIdArray = inputArray => {
|
|
417
|
+
if (inputArray) {
|
|
418
|
+
return inputArray.map(item => {
|
|
419
|
+
if (item.children && item.children.length > 0) {
|
|
420
|
+
// item.children = convertArrayWithIndent(item.children)
|
|
421
|
+
item.children = addRowIdArray(item.children);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// return { ...item, rowId: item.rowId ? item.rowId : (item.id ? item.id : newGuid())}
|
|
425
|
+
return {
|
|
426
|
+
...item,
|
|
427
|
+
rowId: item.rowId ?? item.id ?? newGuid()
|
|
428
|
+
};
|
|
429
|
+
});
|
|
430
|
+
} else {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
export const findItemByKey = (array, key, value) => {
|
|
435
|
+
for (let i = 0; i < array.length; i++) {
|
|
436
|
+
const item = array[i];
|
|
437
|
+
if (item[key] === value) {
|
|
438
|
+
return item;
|
|
439
|
+
}
|
|
440
|
+
if (item.children && item.children.length > 0) {
|
|
441
|
+
const foundInChildren = findItemByKey(item.children, key, value);
|
|
442
|
+
if (foundInChildren) {
|
|
443
|
+
return foundInChildren;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
};
|
|
449
|
+
export const getLastSelectCell = selectCells => {
|
|
450
|
+
if (selectCells.size === 0) {
|
|
451
|
+
return {
|
|
452
|
+
row: 0,
|
|
453
|
+
col: 0
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const lastValue = [...selectCells].at(-1);
|
|
457
|
+
const [row, col] = lastValue.split("-").map(Number);
|
|
458
|
+
return {
|
|
459
|
+
row,
|
|
460
|
+
col
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
export const getFirstSelectCell = selectCells => {
|
|
464
|
+
if (selectCells.size === 0) {
|
|
465
|
+
return {
|
|
466
|
+
row: 0,
|
|
467
|
+
col: 0
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const firstValue = selectCells.values().next().value;
|
|
471
|
+
const [row, col] = firstValue.split("-").map(Number);
|
|
472
|
+
return {
|
|
473
|
+
row,
|
|
474
|
+
col
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// export const getLastSelectCell = (selectCells: any): {row: number, col: number} => {
|
|
479
|
+
//
|
|
480
|
+
// if (selectCells.size === 0) {
|
|
481
|
+
// return {row: 0, col: 0}
|
|
482
|
+
// }
|
|
483
|
+
// const lastValue = [...selectCells].pop();
|
|
484
|
+
//
|
|
485
|
+
// const [row, col] = lastValue.split("-").map(Number);
|
|
486
|
+
// return {row, col};
|
|
487
|
+
//
|
|
488
|
+
// }
|
|
489
|
+
|
|
490
|
+
export const getRowsPasteIndex = pasteRows => {
|
|
491
|
+
if (!pasteRows) {
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
|
|
495
|
+
return [...new Set(result)];
|
|
496
|
+
};
|
|
497
|
+
export function addRows8(arr, n) {
|
|
498
|
+
if (!Array.isArray(arr) || arr.length === 0) return {
|
|
499
|
+
combined: arr,
|
|
500
|
+
addedRows: []
|
|
501
|
+
};
|
|
502
|
+
const m = arr.length;
|
|
503
|
+
const numCols = arr[0].length;
|
|
504
|
+
const addedRows = [];
|
|
505
|
+
|
|
506
|
+
// Hàm kiểm tra kiểu date hợp lệ
|
|
507
|
+
const isValidDate = d => {
|
|
508
|
+
return !isNaN(Date.parse(d));
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Lấy giá trị mẫu của cột j từ hàng đầu tiên
|
|
512
|
+
const getSample = j => arr[0][j];
|
|
513
|
+
|
|
514
|
+
// Xác định chế độ xử lý cho mỗi cột:
|
|
515
|
+
// mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
|
|
516
|
+
const modes = [];
|
|
517
|
+
const steps = []; // bước tăng, nếu có (cho number hoặc date)
|
|
518
|
+
|
|
519
|
+
for (let j = 0; j < numCols; j++) {
|
|
520
|
+
const sample = getSample(j);
|
|
521
|
+
if (m === 1) {
|
|
522
|
+
// Nếu mảng chỉ có 1 hàng: nếu là số thì giữ nguyên; nếu là date thì tăng 1 ngày; còn lại giữ nguyên.
|
|
523
|
+
if (typeof sample === "number") {
|
|
524
|
+
modes[j] = "number-constant";
|
|
525
|
+
} else if (isValidDate(sample)) {
|
|
526
|
+
modes[j] = "date-stepping";
|
|
527
|
+
steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
|
|
528
|
+
} else {
|
|
529
|
+
modes[j] = "cycle";
|
|
530
|
+
}
|
|
531
|
+
} else if (m === 2) {
|
|
532
|
+
// Nếu mảng có 2 hàng: nếu là số thì tính bước = row2 - row1, tương tự với date
|
|
533
|
+
const first = arr[0][j],
|
|
534
|
+
second = arr[1][j];
|
|
535
|
+
if (typeof first === "number" && typeof second === "number") {
|
|
536
|
+
modes[j] = "number-stepping";
|
|
537
|
+
steps[j] = second - first;
|
|
538
|
+
} else if (isValidDate(first) && isValidDate(second)) {
|
|
539
|
+
modes[j] = "date-stepping";
|
|
540
|
+
steps[j] = Date.parse(second) - Date.parse(first);
|
|
541
|
+
} else {
|
|
542
|
+
modes[j] = "cycle";
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
// Nếu mảng có >2 hàng
|
|
546
|
+
const first = arr[0][j],
|
|
547
|
+
second = arr[1][j],
|
|
548
|
+
third = arr[2][j];
|
|
549
|
+
if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
|
|
550
|
+
const step1 = second - first;
|
|
551
|
+
const step2 = third - second;
|
|
552
|
+
if (step1 === step2) {
|
|
553
|
+
modes[j] = "number-stepping";
|
|
554
|
+
steps[j] = step1;
|
|
555
|
+
} else {
|
|
556
|
+
modes[j] = "cycle";
|
|
557
|
+
}
|
|
558
|
+
} else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
|
|
559
|
+
const step1 = Date.parse(second) - Date.parse(first);
|
|
560
|
+
const step2 = Date.parse(third) - Date.parse(second);
|
|
561
|
+
if (step1 === step2) {
|
|
562
|
+
modes[j] = "date-stepping";
|
|
563
|
+
steps[j] = step1;
|
|
564
|
+
} else {
|
|
565
|
+
modes[j] = "cycle";
|
|
566
|
+
}
|
|
567
|
+
} else {
|
|
568
|
+
modes[j] = "cycle";
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Tạo các dòng mới (thêm n dòng)
|
|
574
|
+
// Với mỗi cột, nếu chế độ là stepping thì lấy giá trị cuối của mảng ban đầu và cộng thêm (i+1)*step
|
|
575
|
+
// Nếu chế độ là cycle thì dùng arr[i mod m][j]
|
|
576
|
+
for (let i = 0; i < n; i++) {
|
|
577
|
+
const newRow = [];
|
|
578
|
+
for (let j = 0; j < numCols; j++) {
|
|
579
|
+
let newValue;
|
|
580
|
+
switch (modes[j]) {
|
|
581
|
+
case "number-constant":
|
|
582
|
+
// Mảng có 1 hàng, số giữ nguyên
|
|
583
|
+
newValue = arr[0][j];
|
|
584
|
+
break;
|
|
585
|
+
case "number-stepping":
|
|
586
|
+
{
|
|
587
|
+
// Lấy giá trị cuối của cột j trong mảng ban đầu
|
|
588
|
+
const lastValue = arr[m - 1][j];
|
|
589
|
+
newValue = lastValue + (i + 1) * steps[j];
|
|
590
|
+
}
|
|
591
|
+
break;
|
|
592
|
+
case "date-stepping":
|
|
593
|
+
{
|
|
594
|
+
// Lấy giá trị cuối, chuyển về date, cộng thêm (i+1)*step, chuyển lại về định dạng ISO
|
|
595
|
+
const lastDate = new Date(arr[m - 1][j]);
|
|
596
|
+
const newTime = lastDate.getTime() + (i + 1) * steps[j];
|
|
597
|
+
newValue = moment(new Date(newTime)).format();
|
|
598
|
+
}
|
|
599
|
+
break;
|
|
600
|
+
case "cycle":
|
|
601
|
+
default:
|
|
602
|
+
// Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
|
|
603
|
+
newValue = arr[i % m][j];
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
newRow.push(newValue);
|
|
607
|
+
}
|
|
608
|
+
addedRows.push(newRow);
|
|
609
|
+
}
|
|
610
|
+
const combined = arr.concat(addedRows);
|
|
611
|
+
return {
|
|
612
|
+
combined,
|
|
613
|
+
addedRows
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
export const transformColumns = (cols, convertColumns, t) => {
|
|
617
|
+
// @ts-ignore
|
|
618
|
+
return cols.map(column => {
|
|
619
|
+
const find = convertColumns.find(it => it.key === column.field);
|
|
620
|
+
if (!column?.field && !column?.key) {
|
|
621
|
+
return Table.SELECTION_COLUMN;
|
|
622
|
+
}
|
|
623
|
+
if (find) {
|
|
624
|
+
return {
|
|
625
|
+
...find
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Xử lý đệ quy cho children
|
|
630
|
+
if (column.children?.length) {
|
|
631
|
+
return {
|
|
632
|
+
...column,
|
|
633
|
+
key: column.field ?? column.dataIndex ?? column.key,
|
|
634
|
+
title: t ? t(column.headerText) : column.headerText,
|
|
635
|
+
ellipsis: column.ellipsis !== false,
|
|
636
|
+
align: column.textAlign ?? column.align,
|
|
637
|
+
children: transformColumns(column.children, convertColumns)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
};
|
|
642
|
+
export const transformColumns1 = (cols, sortMultiple) => {
|
|
643
|
+
const convertColumns = flatColumns2(cols).map((column, colIndex) => {
|
|
644
|
+
if (!column?.field && !column?.key) {
|
|
645
|
+
return Table.SELECTION_COLUMN;
|
|
646
|
+
}
|
|
647
|
+
if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
|
|
648
|
+
return {
|
|
649
|
+
...column
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
if ((column.key || column.field) === 'command') {
|
|
653
|
+
return {
|
|
654
|
+
...column
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
return {
|
|
658
|
+
...column,
|
|
659
|
+
key: column.field ?? column.dataIndex ?? column.key,
|
|
660
|
+
sorter: column.sorter === false ? undefined : {
|
|
661
|
+
compare: a => a,
|
|
662
|
+
multiple: sortMultiple ? colIndex : undefined
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// @ts-ignore
|
|
668
|
+
return cols.map(column => {
|
|
669
|
+
const find = convertColumns.find(it => it.key === column.field);
|
|
670
|
+
if (!column?.field && !column?.key) {
|
|
671
|
+
return Table.SELECTION_COLUMN;
|
|
672
|
+
}
|
|
673
|
+
if (find) {
|
|
674
|
+
return {
|
|
675
|
+
...find
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Xử lý đệ quy cho children
|
|
680
|
+
if (column.children?.length) {
|
|
681
|
+
return {
|
|
682
|
+
...column,
|
|
683
|
+
key: column.field ?? column.dataIndex ?? column.key,
|
|
684
|
+
ellipsis: column.ellipsis !== false,
|
|
685
|
+
align: column.textAlign ?? column.align,
|
|
686
|
+
children: transformColumns(column.children, convertColumns)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
export const removeColumns = (columns, groupColumns) => {
|
|
692
|
+
const ttt = [...columns];
|
|
693
|
+
return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
|
|
694
|
+
const newCol = {
|
|
695
|
+
...column
|
|
696
|
+
};
|
|
697
|
+
if (newCol.children) {
|
|
698
|
+
newCol.children = removeColumns(newCol.children, groupColumns);
|
|
699
|
+
}
|
|
700
|
+
return newCol;
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
export const convertFlatColumn = array => {
|
|
704
|
+
const tmp = [...array];
|
|
705
|
+
let result = [];
|
|
706
|
+
tmp.forEach(item => {
|
|
707
|
+
if (item.children) {
|
|
708
|
+
result = result.concat(convertFlatColumn(item.children));
|
|
709
|
+
} else {
|
|
710
|
+
result.push(item);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
return result;
|
|
384
714
|
};
|