@publishfx/publish-components 2.0.3
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/README.md +191 -0
- package/dist/ActionButton/index.d.ts +10 -0
- package/dist/ActionButton/index.js +40 -0
- package/dist/ActionButton/index.module.js +9 -0
- package/dist/ActionButton/index_module.css +23 -0
- package/dist/ActionButton/interface.d.ts +12 -0
- package/dist/ActionButton/interface.js +9 -0
- package/dist/CommonModal/config.d.ts +8 -0
- package/dist/CommonModal/config.js +13 -0
- package/dist/CommonModal/confirm.d.ts +7 -0
- package/dist/CommonModal/confirm.js +132 -0
- package/dist/CommonModal/index.d.ts +2 -0
- package/dist/CommonModal/index.js +3 -0
- package/dist/CommonModal/interface.d.ts +17 -0
- package/dist/CommonModal/interface.js +0 -0
- package/dist/CommonModal/modal.d.ts +11 -0
- package/dist/CommonModal/modal.js +161 -0
- package/dist/CompareChange/index.d.ts +20 -0
- package/dist/CompareChange/index.js +66 -0
- package/dist/CustomTransfer/BaseTransfer.d.ts +35 -0
- package/dist/CustomTransfer/BaseTransfer.js +155 -0
- package/dist/CustomTransfer/SelectItemList.d.ts +9 -0
- package/dist/CustomTransfer/SelectItemList.js +54 -0
- package/dist/CustomTransfer/SelectTreeList.d.ts +43 -0
- package/dist/CustomTransfer/SelectTreeList.js +248 -0
- package/dist/CustomTransfer/SelectedItemList.d.ts +21 -0
- package/dist/CustomTransfer/SelectedItemList.js +132 -0
- package/dist/CustomTransfer/SimpleLink.d.ts +4 -0
- package/dist/CustomTransfer/SimpleLink.js +20 -0
- package/dist/CustomTransfer/index.d.ts +22 -0
- package/dist/CustomTransfer/index.js +92 -0
- package/dist/CustomTransfer/styled.d.ts +27 -0
- package/dist/CustomTransfer/styled.js +181 -0
- package/dist/PerformanceTable/ResizableTitle.d.ts +12 -0
- package/dist/PerformanceTable/ResizableTitle.js +85 -0
- package/dist/PerformanceTable/index.d.ts +4 -0
- package/dist/PerformanceTable/index.js +417 -0
- package/dist/PerformanceTable/interface.d.ts +47 -0
- package/dist/PerformanceTable/interface.js +0 -0
- package/dist/PerformanceTable/style.d.ts +19 -0
- package/dist/PerformanceTable/style.js +402 -0
- package/dist/PerformanceTable/useResizable.d.ts +29 -0
- package/dist/PerformanceTable/useResizable.js +108 -0
- package/dist/ReactSticky/Container.d.ts +19 -0
- package/dist/ReactSticky/Container.js +93 -0
- package/dist/ReactSticky/Sticky.d.ts +27 -0
- package/dist/ReactSticky/Sticky.js +123 -0
- package/dist/ReactSticky/index.d.ts +5 -0
- package/dist/ReactSticky/index.js +4 -0
- package/dist/assets/icons/403.js +15 -0
- package/dist/assets/icons/Icon403.d.ts +3 -0
- package/dist/assets/icons/Icon403.js +14 -0
- package/dist/assets/icons/IconAdd.d.ts +3 -0
- package/dist/assets/icons/IconAdd.js +24 -0
- package/dist/assets/icons/IconAim.d.ts +3 -0
- package/dist/assets/icons/IconAim.js +36 -0
- package/dist/assets/icons/IconBatchupload.d.ts +3 -0
- package/dist/assets/icons/IconBatchupload.js +23 -0
- package/dist/assets/icons/IconClose.d.ts +3 -0
- package/dist/assets/icons/IconClose.js +15 -0
- package/dist/assets/icons/IconDrag_sort.d.ts +3 -0
- package/dist/assets/icons/IconDrag_sort.js +28 -0
- package/dist/assets/icons/IconError.d.ts +3 -0
- package/dist/assets/icons/IconError.js +42 -0
- package/dist/assets/icons/IconExport.d.ts +3 -0
- package/dist/assets/icons/IconExport.js +15 -0
- package/dist/assets/icons/IconFolder.d.ts +3 -0
- package/dist/assets/icons/IconFolder.js +126 -0
- package/dist/assets/icons/IconOpen_down.d.ts +3 -0
- package/dist/assets/icons/IconOpen_down.js +13 -0
- package/dist/assets/icons/IconOpen_right.d.ts +3 -0
- package/dist/assets/icons/IconOpen_right.js +13 -0
- package/dist/assets/icons/IconPlus.d.ts +3 -0
- package/dist/assets/icons/IconPlus.js +17 -0
- package/dist/assets/icons/IconSearch.d.ts +3 -0
- package/dist/assets/icons/IconSearch.js +15 -0
- package/dist/assets/icons/IconSelected_transfer.d.ts +3 -0
- package/dist/assets/icons/IconSelected_transfer.js +15 -0
- package/dist/assets/icons/IconSettings.d.ts +3 -0
- package/dist/assets/icons/IconSettings.js +15 -0
- package/dist/assets/icons/IconUp_down.d.ts +3 -0
- package/dist/assets/icons/IconUp_down.js +15 -0
- package/dist/assets/icons/IconUpload.d.ts +3 -0
- package/dist/assets/icons/IconUpload.js +20 -0
- package/dist/assets/icons/Up_down.js +17 -0
- package/dist/assets/icons/add.js +28 -0
- package/dist/assets/icons/batchupload.js +24 -0
- package/dist/assets/icons/close.js +17 -0
- package/dist/assets/icons/data_increase.js +31 -0
- package/dist/assets/icons/data_no_change.js +19 -0
- package/dist/assets/icons/data_reduction.js +31 -0
- package/dist/assets/icons/drag_sort.js +30 -0
- package/dist/assets/icons/error.js +44 -0
- package/dist/assets/icons/export.js +16 -0
- package/dist/assets/icons/folder.js +128 -0
- package/dist/assets/icons/open_down.js +15 -0
- package/dist/assets/icons/open_right.js +15 -0
- package/dist/assets/icons/plus.js +19 -0
- package/dist/assets/icons/search.js +17 -0
- package/dist/assets/icons/selected.js +17 -0
- package/dist/assets/icons/selected_transfer.js +17 -0
- package/dist/assets/icons/settings.js +17 -0
- package/dist/assets/icons/upload.js +23 -0
- package/dist/assets/images/book.js +2 -0
- package/dist/assets/images/emptyVideo.js +2 -0
- package/dist/assets/images/excel.js +2 -0
- package/dist/assets/images/fail.js +2 -0
- package/dist/assets/images/file.js +2 -0
- package/dist/assets/images/noResult.js +2 -0
- package/dist/assets/images/platform/Apple.js +23 -0
- package/dist/assets/images/platform/Facebook.js +42 -0
- package/dist/assets/images/platform/Google.js +54 -0
- package/dist/assets/images/platform/Instagram.js +2 -0
- package/dist/assets/images/platform/TikTok.js +42 -0
- package/dist/assets/images/platform/Twitch.js +2 -0
- package/dist/assets/images/platform/Twitter.js +2 -0
- package/dist/assets/images/platform/Youtube.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/static/image/Instagram.png +0 -0
- package/dist/static/image/Twitch.png +0 -0
- package/dist/static/image/Twitter.png +0 -0
- package/dist/static/image/Youtube.png +0 -0
- package/dist/static/image/book.png +0 -0
- package/dist/static/image/emptyVideo.png +0 -0
- package/dist/static/image/excel.png +0 -0
- package/dist/static/image/fail.png +0 -0
- package/dist/static/image/file.png +0 -0
- package/dist/static/image/noResult.png +0 -0
- package/dist/static/svg/403.svg +22 -0
- package/dist/static/svg/Apple.svg +4 -0
- package/dist/static/svg/Facebook.svg +9 -0
- package/dist/static/svg/Google.svg +14 -0
- package/dist/static/svg/TikTok.svg +9 -0
- package/dist/static/svg/Up_down.svg +1 -0
- package/dist/static/svg/add.svg +1 -0
- package/dist/static/svg/batchupload.svg +1 -0
- package/dist/static/svg/close.svg +1 -0
- package/dist/static/svg/data_increase.svg +15 -0
- package/dist/static/svg/data_no_change.svg +1 -0
- package/dist/static/svg/data_reduction.svg +15 -0
- package/dist/static/svg/drag_sort.svg +1 -0
- package/dist/static/svg/error.svg +8 -0
- package/dist/static/svg/export.svg +1 -0
- package/dist/static/svg/folder.svg +36 -0
- package/dist/static/svg/open_down.svg +1 -0
- package/dist/static/svg/open_right.svg +8 -0
- package/dist/static/svg/plus.svg +3 -0
- package/dist/static/svg/search.svg +1 -0
- package/dist/static/svg/selected.svg +3 -0
- package/dist/static/svg/selected_transfer.svg +3 -0
- package/dist/static/svg/settings.svg +1 -0
- package/dist/static/svg/upload.svg +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from "react";
|
|
3
|
+
import { merge } from "lodash";
|
|
4
|
+
import IconOpen_down from "../assets/icons/IconOpen_down.js";
|
|
5
|
+
import IconOpen_right from "../assets/icons/IconOpen_right.js";
|
|
6
|
+
import useResizable, { ResizeTable, components } from "./useResizable.js";
|
|
7
|
+
import { BoldTitle } from "./style.js";
|
|
8
|
+
const { Summary } = ResizeTable;
|
|
9
|
+
const PerformanceTable = ({ columns, dataSource = [], showPagination = true, pagination, loading = false, emptyDescription = '暂无数据', size = 'default', border = false, stripe = true, rowSelection, onSort, rowKey = 'id', isFullScreen = false, onExpandClick, customExpandIcon, colorThemes = [
|
|
10
|
+
'#d0324b',
|
|
11
|
+
'#db6679',
|
|
12
|
+
'#e694a2',
|
|
13
|
+
'#eebbc1',
|
|
14
|
+
'#f7e0e3',
|
|
15
|
+
'#c9ece0',
|
|
16
|
+
'#a4dfca',
|
|
17
|
+
'#75ceaf',
|
|
18
|
+
'#4bbf97',
|
|
19
|
+
'#05a76f'
|
|
20
|
+
], colorScaledColumns = [], summaryData, summaryTitle = '统计', highlightSetting, ...restProps }, ref)=>{
|
|
21
|
+
const [expandedRowKeys, setExpandedRowKeys] = useState([]);
|
|
22
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
23
|
+
const [pageSize, setPageSize] = useState(pagination && 'boolean' != typeof pagination ? pagination.pageSize || 10 : 10);
|
|
24
|
+
const [sorter, setSorter] = useState(null);
|
|
25
|
+
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
|
26
|
+
const isWeekend = useCallback((dateValue, dateField, weekends)=>{
|
|
27
|
+
if (!dateValue || !dateField || !weekends) return false;
|
|
28
|
+
let date;
|
|
29
|
+
if ('string' == typeof dateValue) {
|
|
30
|
+
const dateStr = dateValue.split(' - ')[0];
|
|
31
|
+
date = new Date(dateStr);
|
|
32
|
+
} else {
|
|
33
|
+
if (!(dateValue instanceof Date)) return false;
|
|
34
|
+
date = dateValue;
|
|
35
|
+
}
|
|
36
|
+
if (isNaN(date.getTime())) return false;
|
|
37
|
+
const dayOfWeek = date.getDay();
|
|
38
|
+
return weekends.includes(dayOfWeek);
|
|
39
|
+
}, []);
|
|
40
|
+
const formattedColumns = useMemo(()=>columns.map((col, index)=>{
|
|
41
|
+
const { showPercent, showCurrency, showNumber, formatter, render, enableColorScale, dataIndex, ...restCol } = col;
|
|
42
|
+
const colDataIndex = 'string' == typeof dataIndex ? dataIndex : Array.isArray(dataIndex) ? dataIndex[0] : '';
|
|
43
|
+
const shouldShowColorScale = enableColorScale && colDataIndex && colorScaledColumns.includes(colDataIndex);
|
|
44
|
+
let finalRender = render;
|
|
45
|
+
const wrapWithColorScale = (renderFn)=>(value, record, index)=>{
|
|
46
|
+
const content = renderFn ? renderFn(value, record, index) : value;
|
|
47
|
+
if (shouldShowColorScale && record?.level && colDataIndex) {
|
|
48
|
+
const colorLevel = record.level[colDataIndex];
|
|
49
|
+
if ('number' == typeof colorLevel && colorLevel >= 0 && colorLevel < colorThemes.length) {
|
|
50
|
+
const backgroundColor = colorThemes[colorLevel];
|
|
51
|
+
const textColor = 0 === colorLevel || 9 === colorLevel ? '#fff' : '';
|
|
52
|
+
return /*#__PURE__*/ jsx("div", {
|
|
53
|
+
style: {
|
|
54
|
+
backgroundColor,
|
|
55
|
+
color: textColor,
|
|
56
|
+
padding: '9px 16px',
|
|
57
|
+
overflow: 'hidden',
|
|
58
|
+
whiteSpace: 'nowrap',
|
|
59
|
+
wordBreak: 'break-all',
|
|
60
|
+
textOverflow: 'ellipsis',
|
|
61
|
+
cursor: 'pointer'
|
|
62
|
+
},
|
|
63
|
+
title: String(content),
|
|
64
|
+
children: content
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (null != content && '' !== content) return /*#__PURE__*/ jsx("div", {
|
|
69
|
+
style: {
|
|
70
|
+
overflow: 'hidden',
|
|
71
|
+
whiteSpace: 'nowrap',
|
|
72
|
+
wordBreak: 'break-all',
|
|
73
|
+
textOverflow: 'ellipsis'
|
|
74
|
+
},
|
|
75
|
+
title: String(content),
|
|
76
|
+
children: content
|
|
77
|
+
});
|
|
78
|
+
return content;
|
|
79
|
+
};
|
|
80
|
+
if (formatter) finalRender = wrapWithColorScale((value, record, index)=>formatter(value, record, index));
|
|
81
|
+
else if (showPercent || showCurrency || showNumber) finalRender = wrapWithColorScale((value)=>{
|
|
82
|
+
if (null == value || '' === value) return '-';
|
|
83
|
+
let formattedValue = value;
|
|
84
|
+
if (showPercent) formattedValue = `${(100 * Number(value)).toFixed(2)}%`;
|
|
85
|
+
else if (showCurrency) formattedValue = `¥${Number(value).toLocaleString('zh-CN', {
|
|
86
|
+
minimumFractionDigits: 2,
|
|
87
|
+
maximumFractionDigits: 2
|
|
88
|
+
})}`;
|
|
89
|
+
else if (showNumber) formattedValue = Number(value).toLocaleString('zh-CN');
|
|
90
|
+
return formattedValue;
|
|
91
|
+
});
|
|
92
|
+
else if (shouldShowColorScale) finalRender = wrapWithColorScale((value)=>value);
|
|
93
|
+
else if (finalRender) {
|
|
94
|
+
const originalRender = finalRender;
|
|
95
|
+
finalRender = (value, record, index)=>{
|
|
96
|
+
const content = originalRender(value, record, index);
|
|
97
|
+
if (null != content && '' !== content) return /*#__PURE__*/ jsx("div", {
|
|
98
|
+
style: {
|
|
99
|
+
overflow: 'hidden',
|
|
100
|
+
whiteSpace: 'nowrap',
|
|
101
|
+
wordBreak: 'break-all',
|
|
102
|
+
textOverflow: 'ellipsis'
|
|
103
|
+
},
|
|
104
|
+
title: String(content),
|
|
105
|
+
children: content
|
|
106
|
+
});
|
|
107
|
+
return content;
|
|
108
|
+
};
|
|
109
|
+
} else finalRender = wrapWithColorScale((value)=>value);
|
|
110
|
+
return {
|
|
111
|
+
...restCol,
|
|
112
|
+
dataIndex,
|
|
113
|
+
render: finalRender,
|
|
114
|
+
sorter: false !== restCol.sorter ? void 0 !== restCol.sorter ? restCol.sorter : true : false,
|
|
115
|
+
fixed: 0 === index && void 0 === restCol.fixed ? 'left' : restCol.fixed,
|
|
116
|
+
bodyCellStyle: {
|
|
117
|
+
padding: 0
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}), [
|
|
121
|
+
columns,
|
|
122
|
+
colorScaledColumns,
|
|
123
|
+
colorThemes,
|
|
124
|
+
highlightSetting,
|
|
125
|
+
isWeekend
|
|
126
|
+
]);
|
|
127
|
+
const resizeCallback = useCallback(()=>{}, []);
|
|
128
|
+
const { columns: resizableColumns, resizingIndex } = useResizable({
|
|
129
|
+
columns: formattedColumns,
|
|
130
|
+
resizeCallback
|
|
131
|
+
});
|
|
132
|
+
const mergedComponents = useMemo(()=>merge({}, components, {
|
|
133
|
+
header: {}
|
|
134
|
+
}), []);
|
|
135
|
+
const handleSort = useCallback((_pagination, sorterResult)=>{
|
|
136
|
+
const sortResult = Array.isArray(sorterResult) ? sorterResult[0] : sorterResult;
|
|
137
|
+
if (sortResult) {
|
|
138
|
+
setSorter(sortResult);
|
|
139
|
+
if (onSort && sortResult.field) onSort(String(sortResult.field), sortResult.direction || null);
|
|
140
|
+
}
|
|
141
|
+
}, [
|
|
142
|
+
onSort
|
|
143
|
+
]);
|
|
144
|
+
const handlePaginationChange = useCallback((page, size)=>{
|
|
145
|
+
setCurrentPage(page);
|
|
146
|
+
setPageSize(size);
|
|
147
|
+
if (pagination && 'object' == typeof pagination && pagination.onChange) pagination.onChange(page, size);
|
|
148
|
+
}, [
|
|
149
|
+
pagination
|
|
150
|
+
]);
|
|
151
|
+
const handleExpand = useCallback((record, expanded)=>{
|
|
152
|
+
const keyValue = 'function' == typeof rowKey ? rowKey(record) : record[rowKey];
|
|
153
|
+
const key = String(keyValue);
|
|
154
|
+
expanded ? setExpandedRowKeys((prev)=>[
|
|
155
|
+
...prev,
|
|
156
|
+
key
|
|
157
|
+
]) : setExpandedRowKeys((prev)=>prev.filter((k)=>k !== key));
|
|
158
|
+
if (onExpandClick) onExpandClick(expanded, record);
|
|
159
|
+
}, [
|
|
160
|
+
rowKey,
|
|
161
|
+
onExpandClick
|
|
162
|
+
]);
|
|
163
|
+
const expandProps = useMemo(()=>{
|
|
164
|
+
if (customExpandIcon) return {
|
|
165
|
+
icon: ({ expanded, record })=>customExpandIcon(expanded, record)
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
icon: ({ expanded, record })=>{
|
|
169
|
+
const Icon = expanded ? IconOpen_down : IconOpen_right;
|
|
170
|
+
return /*#__PURE__*/ jsx(Icon, {
|
|
171
|
+
style: {
|
|
172
|
+
marginRight: '12px',
|
|
173
|
+
cursor: 'pointer',
|
|
174
|
+
marginTop: '3px'
|
|
175
|
+
},
|
|
176
|
+
onClick: (e)=>{
|
|
177
|
+
e.stopPropagation();
|
|
178
|
+
handleExpand(!expanded, record);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}, [
|
|
184
|
+
customExpandIcon,
|
|
185
|
+
handleExpand
|
|
186
|
+
]);
|
|
187
|
+
const handleRowSelection = useMemo(()=>{
|
|
188
|
+
if (!rowSelection) return;
|
|
189
|
+
return {
|
|
190
|
+
...rowSelection,
|
|
191
|
+
selectedRowKeys,
|
|
192
|
+
onChange: (selectedKeys, selectedRows)=>{
|
|
193
|
+
setSelectedRowKeys(selectedKeys);
|
|
194
|
+
if (rowSelection.onChange) rowSelection.onChange(selectedKeys, selectedRows || []);
|
|
195
|
+
},
|
|
196
|
+
onSelect: (selected, record, selectedRows)=>{
|
|
197
|
+
if (rowSelection.onSelect) rowSelection.onSelect(selected, record, selectedRows);
|
|
198
|
+
},
|
|
199
|
+
onSelectAll: (selected, selectedRows)=>{
|
|
200
|
+
if (rowSelection.onSelectAll) rowSelection.onSelectAll(selected, selectedRows);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}, [
|
|
204
|
+
rowSelection,
|
|
205
|
+
selectedRowKeys
|
|
206
|
+
]);
|
|
207
|
+
const getTableData = useCallback(()=>{
|
|
208
|
+
const headers = columns.map((col)=>{
|
|
209
|
+
const title = 'string' == typeof col.title ? col.title : col.title?.toString() || '';
|
|
210
|
+
return `"${title}"`;
|
|
211
|
+
}).join(',') + '\n';
|
|
212
|
+
const getValue = (record, dataIndex)=>{
|
|
213
|
+
if ('string' == typeof dataIndex) return record[dataIndex];
|
|
214
|
+
if (Array.isArray(dataIndex)) return dataIndex.reduce((obj, key)=>obj?.[key], record);
|
|
215
|
+
return '';
|
|
216
|
+
};
|
|
217
|
+
const rows = dataSource.map((record)=>columns.map((col)=>{
|
|
218
|
+
const dataIndex = col.dataIndex;
|
|
219
|
+
if (!dataIndex) return '';
|
|
220
|
+
const value = getValue(record, dataIndex);
|
|
221
|
+
return `"${value || ''}"`;
|
|
222
|
+
}).join(',')).join('\n');
|
|
223
|
+
return headers + rows;
|
|
224
|
+
}, [
|
|
225
|
+
columns,
|
|
226
|
+
dataSource
|
|
227
|
+
]);
|
|
228
|
+
const getSelectedRows = useCallback(()=>dataSource.filter((record)=>{
|
|
229
|
+
const keyValue = 'function' == typeof rowKey ? rowKey(record) : record[rowKey];
|
|
230
|
+
const key = String(keyValue);
|
|
231
|
+
return selectedRowKeys.some((selectedKey)=>String(selectedKey) === key);
|
|
232
|
+
}), [
|
|
233
|
+
dataSource,
|
|
234
|
+
rowKey,
|
|
235
|
+
selectedRowKeys
|
|
236
|
+
]);
|
|
237
|
+
useImperativeHandle(ref, ()=>({
|
|
238
|
+
getTableData,
|
|
239
|
+
getSelectedRows
|
|
240
|
+
}), [
|
|
241
|
+
getTableData,
|
|
242
|
+
getSelectedRows
|
|
243
|
+
]);
|
|
244
|
+
const paginationConfig = useMemo(()=>{
|
|
245
|
+
if (!showPagination || false === pagination) return false;
|
|
246
|
+
const defaultPagination = {
|
|
247
|
+
current: currentPage,
|
|
248
|
+
pageSize,
|
|
249
|
+
total: dataSource.length,
|
|
250
|
+
showTotal: true,
|
|
251
|
+
sizeCanChange: true,
|
|
252
|
+
sizeOptions: [
|
|
253
|
+
10,
|
|
254
|
+
20,
|
|
255
|
+
50,
|
|
256
|
+
100
|
|
257
|
+
],
|
|
258
|
+
onChange: handlePaginationChange,
|
|
259
|
+
onPageSizeChange: handlePaginationChange
|
|
260
|
+
};
|
|
261
|
+
if ('object' == typeof pagination) return {
|
|
262
|
+
...defaultPagination,
|
|
263
|
+
...pagination,
|
|
264
|
+
current: pagination.current ?? currentPage,
|
|
265
|
+
pageSize: pagination.pageSize ?? pageSize
|
|
266
|
+
};
|
|
267
|
+
return defaultPagination;
|
|
268
|
+
}, [
|
|
269
|
+
showPagination,
|
|
270
|
+
pagination,
|
|
271
|
+
currentPage,
|
|
272
|
+
pageSize,
|
|
273
|
+
dataSource.length,
|
|
274
|
+
handlePaginationChange
|
|
275
|
+
]);
|
|
276
|
+
const paginatedData = useMemo(()=>{
|
|
277
|
+
if (!showPagination || false === pagination) return dataSource;
|
|
278
|
+
const start = (currentPage - 1) * pageSize;
|
|
279
|
+
const end = start + pageSize;
|
|
280
|
+
return dataSource.slice(start, end);
|
|
281
|
+
}, [
|
|
282
|
+
dataSource,
|
|
283
|
+
currentPage,
|
|
284
|
+
pageSize,
|
|
285
|
+
showPagination,
|
|
286
|
+
pagination
|
|
287
|
+
]);
|
|
288
|
+
const summaryConfig = useMemo(()=>{
|
|
289
|
+
if (!summaryData) return;
|
|
290
|
+
return ()=>/*#__PURE__*/ jsx(Summary, {
|
|
291
|
+
fixed: "bottom",
|
|
292
|
+
children: /*#__PURE__*/ jsx(Summary.Row, {
|
|
293
|
+
children: columns.map((col, index)=>{
|
|
294
|
+
const colDataIndex = 'string' == typeof col.dataIndex ? col.dataIndex : Array.isArray(col.dataIndex) ? col.dataIndex[0] : '';
|
|
295
|
+
if (0 === index) return /*#__PURE__*/ jsx(Summary.Cell, {
|
|
296
|
+
children: /*#__PURE__*/ jsx(BoldTitle, {
|
|
297
|
+
children: summaryTitle
|
|
298
|
+
})
|
|
299
|
+
}, index);
|
|
300
|
+
const summaryValue = colDataIndex ? summaryData[colDataIndex] : void 0;
|
|
301
|
+
let displayValue = null != summaryValue ? summaryValue : '-';
|
|
302
|
+
if (col.showPercent && 'number' == typeof displayValue) displayValue = `${(100 * displayValue).toFixed(2)}%`;
|
|
303
|
+
else if (col.showCurrency && 'number' == typeof displayValue) displayValue = `¥${displayValue.toLocaleString('zh-CN', {
|
|
304
|
+
minimumFractionDigits: 2,
|
|
305
|
+
maximumFractionDigits: 2
|
|
306
|
+
})}`;
|
|
307
|
+
else if (col.showNumber && 'number' == typeof displayValue) displayValue = displayValue.toLocaleString('zh-CN');
|
|
308
|
+
let renderedValue = displayValue;
|
|
309
|
+
if (col.render && void 0 !== summaryValue) renderedValue = col.render(summaryValue, {}, index);
|
|
310
|
+
return /*#__PURE__*/ jsx(Summary.Cell, {
|
|
311
|
+
style: {
|
|
312
|
+
textAlign: col.align || 'left',
|
|
313
|
+
padding: '9px 0',
|
|
314
|
+
fontWeight: 'bold'
|
|
315
|
+
},
|
|
316
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
317
|
+
style: {
|
|
318
|
+
overflow: 'hidden',
|
|
319
|
+
whiteSpace: 'nowrap',
|
|
320
|
+
textOverflow: 'ellipsis',
|
|
321
|
+
width: '100%',
|
|
322
|
+
display: 'inline-block',
|
|
323
|
+
fontWeight: 'bold',
|
|
324
|
+
fontSize: '14px'
|
|
325
|
+
},
|
|
326
|
+
title: String(displayValue),
|
|
327
|
+
children: renderedValue
|
|
328
|
+
})
|
|
329
|
+
}, index);
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
});
|
|
333
|
+
}, [
|
|
334
|
+
summaryData,
|
|
335
|
+
columns,
|
|
336
|
+
summaryTitle
|
|
337
|
+
]);
|
|
338
|
+
const getRowClassName = useCallback((record, index)=>{
|
|
339
|
+
if (!highlightSetting?.weekends || !highlightSetting?.dateField) return '';
|
|
340
|
+
const dateValue = record[highlightSetting.dateField];
|
|
341
|
+
if (!dateValue) return '';
|
|
342
|
+
let date;
|
|
343
|
+
if ('string' == typeof dateValue) {
|
|
344
|
+
const dateStr = dateValue.split(' - ')[0];
|
|
345
|
+
date = new Date(dateStr);
|
|
346
|
+
} else {
|
|
347
|
+
if (!(dateValue instanceof Date)) return '';
|
|
348
|
+
date = dateValue;
|
|
349
|
+
}
|
|
350
|
+
if (isNaN(date.getTime())) return '';
|
|
351
|
+
const dayOfWeek = date.getDay();
|
|
352
|
+
if (highlightSetting.weekends.includes(dayOfWeek)) {
|
|
353
|
+
const classNames = [];
|
|
354
|
+
if (highlightSetting.showBold) classNames.push('performance-table-weekend-row');
|
|
355
|
+
if (highlightSetting.showBackgroundPattern) classNames.push('performance-table-weekend-row-pattern');
|
|
356
|
+
if (highlightSetting.showIcon) classNames.push('performance-table-weekend-row-icon');
|
|
357
|
+
if (highlightSetting.highlightTextColor) classNames.push('performance-table-weekend-text-color');
|
|
358
|
+
return classNames.join(' ');
|
|
359
|
+
}
|
|
360
|
+
return '';
|
|
361
|
+
}, [
|
|
362
|
+
highlightSetting
|
|
363
|
+
]);
|
|
364
|
+
const tableStyle = useMemo(()=>{
|
|
365
|
+
const style = {};
|
|
366
|
+
if (highlightSetting?.showIcon && highlightSetting?.iconPath) style['--weekend-icon-url'] = `url(${highlightSetting.iconPath})`;
|
|
367
|
+
if (highlightSetting?.highlightTextColor) style['--weekend-text-color'] = highlightSetting.highlightTextColor;
|
|
368
|
+
return Object.keys(style).length > 0 ? style : void 0;
|
|
369
|
+
}, [
|
|
370
|
+
highlightSetting?.showIcon,
|
|
371
|
+
highlightSetting?.iconPath,
|
|
372
|
+
highlightSetting?.highlightTextColor
|
|
373
|
+
]);
|
|
374
|
+
return /*#__PURE__*/ jsx(ResizeTable, {
|
|
375
|
+
...restProps,
|
|
376
|
+
columns: resizableColumns,
|
|
377
|
+
data: paginatedData,
|
|
378
|
+
loading: loading,
|
|
379
|
+
size: size,
|
|
380
|
+
border: border,
|
|
381
|
+
stripe: stripe,
|
|
382
|
+
rowKey: rowKey,
|
|
383
|
+
rowSelection: handleRowSelection,
|
|
384
|
+
pagination: paginationConfig,
|
|
385
|
+
expandedRowKeys: expandedRowKeys,
|
|
386
|
+
onExpand: handleExpand,
|
|
387
|
+
expandProps: expandProps,
|
|
388
|
+
onChange: handleSort,
|
|
389
|
+
showSorterTooltip: false,
|
|
390
|
+
summary: summaryConfig,
|
|
391
|
+
components: mergedComponents,
|
|
392
|
+
scroll: {
|
|
393
|
+
x: true,
|
|
394
|
+
y: true
|
|
395
|
+
},
|
|
396
|
+
resizingIndex: resizingIndex,
|
|
397
|
+
isFullScreen: isFullScreen,
|
|
398
|
+
rowClassName: getRowClassName,
|
|
399
|
+
style: tableStyle,
|
|
400
|
+
noDataElement: /*#__PURE__*/ jsx("div", {
|
|
401
|
+
style: {
|
|
402
|
+
width: '100%',
|
|
403
|
+
padding: '40px 0',
|
|
404
|
+
textAlign: 'center'
|
|
405
|
+
},
|
|
406
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
407
|
+
style: {
|
|
408
|
+
color: 'var(--color-text-3)',
|
|
409
|
+
fontSize: '14px'
|
|
410
|
+
},
|
|
411
|
+
children: emptyDescription
|
|
412
|
+
})
|
|
413
|
+
})
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
const src_PerformanceTable = /*#__PURE__*/ forwardRef(PerformanceTable);
|
|
417
|
+
export { src_PerformanceTable as default };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TableProps, TableColumnProps } from "@arco-design/web-react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export interface PerformanceTableColumn<T = any> extends TableColumnProps<T> {
|
|
4
|
+
showPercent?: boolean;
|
|
5
|
+
showCurrency?: boolean;
|
|
6
|
+
showNumber?: boolean;
|
|
7
|
+
formatter?: (value: any, record: T, index: number) => React.ReactNode;
|
|
8
|
+
enableColorScale?: boolean;
|
|
9
|
+
minWidth?: number;
|
|
10
|
+
maxWidth?: number;
|
|
11
|
+
disableResize?: boolean;
|
|
12
|
+
rawTitle?: string;
|
|
13
|
+
adjusted?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface PerformanceTableProps<T = any> extends Omit<TableProps<T>, 'columns' | 'size' | 'expandProps'> {
|
|
16
|
+
columns: PerformanceTableColumn<T>[];
|
|
17
|
+
dataSource?: T[];
|
|
18
|
+
showPagination?: boolean;
|
|
19
|
+
pagination?: TableProps<T>['pagination'] | false;
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
emptyDescription?: string;
|
|
22
|
+
size?: 'mini' | 'small' | 'default' | 'middle';
|
|
23
|
+
border?: boolean;
|
|
24
|
+
stripe?: boolean;
|
|
25
|
+
rowSelection?: TableProps<T>['rowSelection'];
|
|
26
|
+
onSort?: (dataIndex: string, direction: 'ascend' | 'descend' | null) => void;
|
|
27
|
+
isFullScreen?: boolean;
|
|
28
|
+
onExpandClick?: (expanded: boolean, record: T) => void;
|
|
29
|
+
customExpandIcon?: (expanded: boolean, record: T) => React.ReactNode;
|
|
30
|
+
colorThemes?: string[];
|
|
31
|
+
colorScaledColumns?: string[];
|
|
32
|
+
summaryData?: Record<string, any>;
|
|
33
|
+
summaryTitle?: string;
|
|
34
|
+
highlightSetting?: {
|
|
35
|
+
weekends?: number[];
|
|
36
|
+
dateField?: string;
|
|
37
|
+
showBold?: boolean;
|
|
38
|
+
showBackgroundPattern?: boolean;
|
|
39
|
+
showIcon?: boolean;
|
|
40
|
+
iconPath?: string;
|
|
41
|
+
highlightTextColor?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export type PerformanceTableRef = {
|
|
45
|
+
getTableData: () => string;
|
|
46
|
+
getSelectedRows: () => any[];
|
|
47
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const StyledIcon: import("styled-components").StyledComponent<"img", any, {}, never>;
|
|
3
|
+
export declare const BoldTitle: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
4
|
+
export declare const ResizeTable: import("styled-components").StyledComponent<(<T>(props: import("@arco-design/web-react").TableProps<T> & {
|
|
5
|
+
ref?: import("react").Ref<import("@arco-design/web-react").TableInstance>;
|
|
6
|
+
}) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
|
|
7
|
+
Summary: typeof import("@arco-design/web-react/es/Table/summary").default;
|
|
8
|
+
}, any, {
|
|
9
|
+
resizingIndex?: number;
|
|
10
|
+
isFullScreen?: boolean;
|
|
11
|
+
}, never>;
|
|
12
|
+
export declare const StyledTd: import("styled-components").StyledComponent<"td", any, {
|
|
13
|
+
colSpan: number;
|
|
14
|
+
}, never>;
|
|
15
|
+
export declare const StyledTdComp: React.FunctionComponent<{
|
|
16
|
+
colSpan: number;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}>;
|