xmirror-components 1.0.26 → 1.0.28-alpha.1
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/build/dist/index.cjs +1 -1
- package/build/dist/index.mjs +78 -78
- package/build/es/components/IconButton/index.d.ts +4 -4
- package/build/es/components/IconButton/index.js +3 -3
- package/build/es/components/Table/Footer/index.d.ts +5 -0
- package/build/es/components/Table/Footer/index.js +84 -0
- package/build/es/components/Table/PopoverSetColumns/index.d.ts +14 -0
- package/build/es/components/Table/PopoverSetColumns/index.js +174 -0
- package/build/es/components/Table/index.d.ts +5 -0
- package/build/es/components/Table/index.js +189 -0
- package/build/es/components/Table/types.d.ts +63 -0
- package/build/es/components/Table/types.js +1 -0
- package/build/lib/components/IconButton/index.js +3 -4
- package/build/lib/components/Table/Footer/index.js +119 -0
- package/build/lib/components/Table/PopoverSetColumns/index.js +212 -0
- package/build/lib/components/Table/index.js +227 -0
- package/build/lib/components/Table/types.js +2 -0
- package/build/lib/index.d.ts +2 -2
- package/build/package.json +1 -1
- package/build/types/components/IconButton/index.d.ts +4 -4
- package/build/types/components/Table/Footer/index.d.ts +5 -0
- package/build/types/components/Table/PopoverSetColumns/index.d.ts +14 -0
- package/build/types/components/Table/index.d.ts +5 -0
- package/build/types/components/Table/types.d.ts +63 -0
- package/package.json +1 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React, { useMemo, useRef } from 'react';
|
|
2
|
+
import { FormattedMessage } from 'react-intl';
|
|
3
|
+
import { Checkbox, Row, Col } from 'antd';
|
|
4
|
+
import { CSSTransition } from 'react-transition-group';
|
|
5
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
6
|
+
import './index.less';
|
|
7
|
+
function Index(props) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
var transitionNodeRef = useRef(null);
|
|
10
|
+
var _d = props, pagination = _d.pagination, _e = _d.rowSelection, rowSelection = _e === void 0 ? { selectedRowKeys: [], onChange: function () { } } : _e, _f = _d.dataSource, dataSource = _f === void 0 ? [] : _f, _g = _d.selectionPopover, selectionPopover = _g === void 0 ? false : _g;
|
|
11
|
+
/**
|
|
12
|
+
* 选中所有
|
|
13
|
+
* @param checked 选中状态
|
|
14
|
+
*/
|
|
15
|
+
var changeCheckAll = function (_a) {
|
|
16
|
+
var checked = _a.target.checked;
|
|
17
|
+
var _b = props.rowKey, rowKey = _b === void 0 ? 'id' : _b;
|
|
18
|
+
if (!rowSelection || !rowSelection.onChange)
|
|
19
|
+
return;
|
|
20
|
+
if (checked) {
|
|
21
|
+
var getCheckboxProps_1 = rowSelection.getCheckboxProps;
|
|
22
|
+
var tableData = dataSource;
|
|
23
|
+
if (getCheckboxProps_1) {
|
|
24
|
+
tableData = dataSource.filter(function (item) {
|
|
25
|
+
var data = getCheckboxProps_1(item);
|
|
26
|
+
return !data.disabled;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// rowKey 可能为字符串或函数,这里只处理字符串情况
|
|
30
|
+
var keyGetter = typeof rowKey === 'function' ? rowKey : function (item) { return item[rowKey]; };
|
|
31
|
+
rowSelection.onChange(Array.from(tableData.map(keyGetter)), Array.from(tableData), { type: 'none' });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
rowSelection.onChange([], [], { type: 'none' });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* optionalNum 可选的数量
|
|
39
|
+
* @return {number}
|
|
40
|
+
*/
|
|
41
|
+
var optionalNum = useMemo(function () {
|
|
42
|
+
var getCheckboxProps = rowSelection.getCheckboxProps;
|
|
43
|
+
var tableData = dataSource;
|
|
44
|
+
if (getCheckboxProps) {
|
|
45
|
+
tableData = dataSource.filter(function (item) {
|
|
46
|
+
var data = getCheckboxProps(item);
|
|
47
|
+
return !data.disabled;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return tableData.length;
|
|
51
|
+
}, [dataSource, rowSelection]);
|
|
52
|
+
/**
|
|
53
|
+
* indeterminate 选了,但没全选
|
|
54
|
+
* @return {boolean}
|
|
55
|
+
*/
|
|
56
|
+
var indeterminate = useMemo(function () {
|
|
57
|
+
var _a;
|
|
58
|
+
var selectedRowKeys = (_a = rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
|
|
59
|
+
return !!(selectedRowKeys.length > 0 && selectedRowKeys.length < optionalNum);
|
|
60
|
+
}, [rowSelection.selectedRowKeys, optionalNum]);
|
|
61
|
+
/**
|
|
62
|
+
* checked 选中状态
|
|
63
|
+
* @return {boolean}
|
|
64
|
+
*/
|
|
65
|
+
var checked = useMemo(function () {
|
|
66
|
+
var _a;
|
|
67
|
+
var selectedRowKeys = (_a = rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
|
|
68
|
+
return !!(selectedRowKeys.length > 0 && selectedRowKeys.length === optionalNum);
|
|
69
|
+
}, [rowSelection.selectedRowKeys, optionalNum]);
|
|
70
|
+
return (React.createElement("div", { className: "table-footer" },
|
|
71
|
+
React.createElement(CSSTransition, { in: Boolean(props.rowSelection && props.selectionPopover && (checked || indeterminate)), nodeRef: transitionNodeRef, classNames: "zoom", unmountOnExit: true, timeout: 300 },
|
|
72
|
+
React.createElement(Row, { ref: transitionNodeRef, className: "table-batch-dialog", justify: "space-between" },
|
|
73
|
+
React.createElement(Col, { style: { display: 'flex', alignItems: 'center' } },
|
|
74
|
+
React.createElement(Checkbox, { checked: checked, indeterminate: indeterminate, onChange: changeCheckAll },
|
|
75
|
+
React.createElement(FormattedMessage, { id: "component.table.selected", defaultMessage: '已选{length}条', values: {
|
|
76
|
+
length: (_b = (_a = rowSelection.selectedRowKeys) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0
|
|
77
|
+
} }))),
|
|
78
|
+
React.createElement(Col, { style: { display: 'flex', alignItems: 'center' } },
|
|
79
|
+
selectionPopover,
|
|
80
|
+
React.createElement("span", { className: "btn-close", onClick: function () { changeCheckAll({ target: { checked: false } }); } },
|
|
81
|
+
React.createElement(CloseOutlined, null))))),
|
|
82
|
+
pagination && (React.createElement("span", { className: "table-footer-total" }, pagination.showTotal ? pagination.showTotal((_c = pagination.total) !== null && _c !== void 0 ? _c : 0, [0, 0]) : null))));
|
|
83
|
+
}
|
|
84
|
+
export default Index;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TableComponentProps } from '../types';
|
|
3
|
+
import './index.less';
|
|
4
|
+
interface PopoverSetColumnsProps {
|
|
5
|
+
order: string[];
|
|
6
|
+
visibleItems: string[];
|
|
7
|
+
columns: TableComponentProps['columns'];
|
|
8
|
+
onChangeOrder: (newOrder: string[]) => void;
|
|
9
|
+
columnsVisible: TableComponentProps['columnsVisible'];
|
|
10
|
+
columnsSort: TableComponentProps['columnsSort'];
|
|
11
|
+
onChangeVisible: (newVisibleItems: string[]) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function PopoverSetColumns({ order, visibleItems, columns, onChangeOrder, columnsVisible, columnsSort, onChangeVisible }: PopoverSetColumnsProps): React.JSX.Element;
|
|
14
|
+
export default PopoverSetColumns;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
import React, { useMemo, useRef } from 'react';
|
|
11
|
+
import { Checkbox, Popover } from 'antd';
|
|
12
|
+
import { FormattedMessage } from 'react-intl';
|
|
13
|
+
import { HolderOutlined } from '@ant-design/icons';
|
|
14
|
+
// import { message, IconFont } from 'xmirror-components'
|
|
15
|
+
import { message } from '../../AntdApp';
|
|
16
|
+
import IconFont from '../../IconFont';
|
|
17
|
+
import './index.less';
|
|
18
|
+
function PopoverSetColumns(_a) {
|
|
19
|
+
var order = _a.order, visibleItems = _a.visibleItems, _b = _a.columns, columns = _b === void 0 ? [] : _b, onChangeOrder = _a.onChangeOrder, columnsVisible = _a.columnsVisible, columnsSort = _a.columnsSort, onChangeVisible = _a.onChangeVisible;
|
|
20
|
+
var dragged = useRef(null);
|
|
21
|
+
var over = useRef(null);
|
|
22
|
+
/**
|
|
23
|
+
* 开始拖拽字段
|
|
24
|
+
* @param event{React.DragEvent<HTMLLIElement>}
|
|
25
|
+
* */
|
|
26
|
+
var dragStart = function (event) {
|
|
27
|
+
dragged.current = event.currentTarget;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 拖拽结束
|
|
31
|
+
* @param event{React.DragEvent<HTMLLIElement>}
|
|
32
|
+
* */
|
|
33
|
+
var dragEnd = function (event) {
|
|
34
|
+
if (!over.current || !dragged.current) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
dragged.current.style.display = 'block';
|
|
38
|
+
event.currentTarget.classList.remove('drag-up');
|
|
39
|
+
over.current.classList.remove('drag-up');
|
|
40
|
+
event.currentTarget.classList.remove('drag-down');
|
|
41
|
+
over.current.classList.remove('drag-down');
|
|
42
|
+
var newOrder = __spreadArray([], order, true);
|
|
43
|
+
var from = Number(dragged.current.dataset.index);
|
|
44
|
+
var to = Number(over.current.dataset.index);
|
|
45
|
+
newOrder.splice(to, 0, newOrder.splice(from, 1)[0]);
|
|
46
|
+
onChangeOrder(newOrder);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 拖拽中
|
|
50
|
+
* @param event{React.DragEvent<HTMLUListElement>}
|
|
51
|
+
* */
|
|
52
|
+
var dragOver = function (event) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
if (!dragged.current)
|
|
55
|
+
return;
|
|
56
|
+
dragged.current.style.display = 'none';
|
|
57
|
+
var target = event.target;
|
|
58
|
+
if (target.tagName !== 'LI') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var dgIndex = dragged.current.dataset.index;
|
|
62
|
+
var taIndex = target.dataset.index;
|
|
63
|
+
var id = target.dataset.id;
|
|
64
|
+
if (!id || notDraggableIds.includes(id)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!dgIndex || !taIndex)
|
|
68
|
+
return;
|
|
69
|
+
var animateName = dgIndex > taIndex ? 'drag-up' : 'drag-down';
|
|
70
|
+
if (over.current && target.dataset.index !== over.current.dataset.index) {
|
|
71
|
+
over.current.classList.remove('drag-up', 'drag-down');
|
|
72
|
+
}
|
|
73
|
+
if (!target.classList.contains(animateName)) {
|
|
74
|
+
target.classList.add(animateName);
|
|
75
|
+
over.current = target;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 列显示隐藏
|
|
80
|
+
* @param event{CheckboxChangeEvent}
|
|
81
|
+
* @param dataIndex{array|string} 列表字段(columns)的 dataIndex
|
|
82
|
+
* */
|
|
83
|
+
var changeVisible = function (_a, _b) {
|
|
84
|
+
var checked = _a.target.checked;
|
|
85
|
+
var dataIndex = _b.dataIndex;
|
|
86
|
+
if (visibleItems.length === 1 && !checked) {
|
|
87
|
+
message.error(React.createElement(FormattedMessage, { id: "component.table.visibleError", defaultMessage: '列表最少保留一个字段' }));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var id = Array.isArray(dataIndex) ? dataIndex.join(',') : dataIndex;
|
|
91
|
+
var newVisibleItems = __spreadArray([], visibleItems, true);
|
|
92
|
+
if (checked) {
|
|
93
|
+
newVisibleItems.push(id);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
newVisibleItems.splice(newVisibleItems.indexOf(id), 1);
|
|
97
|
+
}
|
|
98
|
+
onChangeVisible(newVisibleItems);
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* 不可拖拽字段的 dataIndex
|
|
102
|
+
* */
|
|
103
|
+
var notDraggableIds = useMemo(function () {
|
|
104
|
+
var arr = [];
|
|
105
|
+
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
|
|
106
|
+
var item = columns_1[_i];
|
|
107
|
+
if (item.columnSortDisabled && ('dataIndex' in item)) {
|
|
108
|
+
var dataIndex = void 0;
|
|
109
|
+
if (Array.isArray(item.dataIndex)) {
|
|
110
|
+
dataIndex = item.dataIndex.join(',');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
dataIndex = item.dataIndex;
|
|
114
|
+
}
|
|
115
|
+
arr.push(dataIndex);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return arr;
|
|
119
|
+
}, [columns]);
|
|
120
|
+
/**
|
|
121
|
+
* 渲染到页面上的列表
|
|
122
|
+
* */
|
|
123
|
+
var renderList = useMemo(function () {
|
|
124
|
+
return order.map(function (item, index) {
|
|
125
|
+
var column;
|
|
126
|
+
for (var _i = 0, columns_2 = columns; _i < columns_2.length; _i++) {
|
|
127
|
+
var col = columns_2[_i];
|
|
128
|
+
if ('dataIndex' in col) {
|
|
129
|
+
var dataIndex = void 0;
|
|
130
|
+
if (Array.isArray(col.dataIndex)) {
|
|
131
|
+
dataIndex = col.dataIndex.join(',');
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
dataIndex = col.dataIndex;
|
|
135
|
+
}
|
|
136
|
+
if (item === dataIndex) {
|
|
137
|
+
column = col;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!column || !('dataIndex' in column)) {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
var draggable = columnsSort && column && !column.columnSortDisabled;
|
|
146
|
+
var id;
|
|
147
|
+
if (column && Array.isArray(column.dataIndex)) {
|
|
148
|
+
id = column.dataIndex.join(',');
|
|
149
|
+
}
|
|
150
|
+
else if (column) {
|
|
151
|
+
id = column.dataIndex;
|
|
152
|
+
}
|
|
153
|
+
var checked = typeof id === 'string' && visibleItems.includes(id);
|
|
154
|
+
return column
|
|
155
|
+
? (React.createElement("li", { key: Array.isArray(column.dataIndex) ? column.dataIndex.join(',') : String(column.dataIndex), draggable: draggable, onDragEnd: dragEnd, onDragStart: dragStart, "data-index": index, "data-id": Array.isArray(column.dataIndex) ? column.dataIndex.join(',') : String(column.dataIndex) },
|
|
156
|
+
columnsSort && React.createElement(HolderOutlined, { className: "icon-drag" }),
|
|
157
|
+
columnsVisible &&
|
|
158
|
+
React.createElement(Checkbox, { style: { marginRight: '10px' }, checked: Boolean(checked), disabled: column.columnVisibleDisabled, onChange: function (event) { changeVisible(event, column); } }),
|
|
159
|
+
typeof column.title === 'function' ? column.title({}) : column.title))
|
|
160
|
+
: null;
|
|
161
|
+
});
|
|
162
|
+
}, [order, visibleItems, columns, columnsSort, columnsVisible]);
|
|
163
|
+
return (React.createElement(Popover, { overlayClassName: "table-columns-setting-popover", content: React.createElement("ul", { onDragOver: dragOver, className: "table-columns-setting-wrapper" }, renderList), trigger: "click", align: {
|
|
164
|
+
offset: [-60, -14]
|
|
165
|
+
} },
|
|
166
|
+
React.createElement(IconFont, { type: "icon-setting", style: {
|
|
167
|
+
float: 'right',
|
|
168
|
+
fontSize: '17px',
|
|
169
|
+
lineHeight: 1,
|
|
170
|
+
marginTop: '2px',
|
|
171
|
+
fontWeight: 500
|
|
172
|
+
} })));
|
|
173
|
+
}
|
|
174
|
+
export default PopoverSetColumns;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AnyObject, TableComponentProps } from './types';
|
|
3
|
+
import './index.less';
|
|
4
|
+
declare const _default: React.ForwardRefExoticComponent<TableComponentProps<AnyObject> & React.RefAttributes<HTMLDivElement>>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import { Table, Tooltip } from 'antd';
|
|
14
|
+
import { useLocalStorageState } from 'ahooks';
|
|
15
|
+
import { DownOutlined } from '@ant-design/icons';
|
|
16
|
+
import PopoverSetColumns from './PopoverSetColumns';
|
|
17
|
+
import Footer from './Footer';
|
|
18
|
+
import './index.less';
|
|
19
|
+
function Index(props, ref) {
|
|
20
|
+
var _a = props.columns, columns = _a === void 0 ? [] : _a, columnsSort = props.columnsSort, columnsVisible = props.columnsVisible, _b = props.tableId, tableId = _b === void 0 ? '' : _b, pagination = props.pagination, dataSource = props.dataSource;
|
|
21
|
+
var pathname = location.pathname;
|
|
22
|
+
var _tableId = pathname + tableId;
|
|
23
|
+
var _c = useLocalStorageState('TABLE_' + _tableId, {
|
|
24
|
+
defaultValue: null
|
|
25
|
+
}), tableCache = _c[0], setTableCache = _c[1];
|
|
26
|
+
var _d = useState([]), order = _d[0], setOrder = _d[1];
|
|
27
|
+
var _e = useState([]), visibleItems = _e[0], setVisibleItems = _e[1];
|
|
28
|
+
var tableRef = useRef(null);
|
|
29
|
+
/**
|
|
30
|
+
* 修改字段顺序
|
|
31
|
+
* @param newOrder{array} 新顺序
|
|
32
|
+
* */
|
|
33
|
+
var changeOrder = function (newOrder) {
|
|
34
|
+
setOrder(newOrder);
|
|
35
|
+
setCache(newOrder, visibleItems);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 修改显示的字段
|
|
39
|
+
* @param visibleItems{array} 显示的字段列表
|
|
40
|
+
* */
|
|
41
|
+
var changeVisibleItems = function (visibleItems) {
|
|
42
|
+
setVisibleItems(visibleItems);
|
|
43
|
+
setCache(order, visibleItems);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 把排序和显示储存到浏览器
|
|
47
|
+
* @param visibleItems{array} 显示的字段列表
|
|
48
|
+
* @param newOrder{array} 新顺序
|
|
49
|
+
* */
|
|
50
|
+
var setCache = function (newOrder, visibleItems) {
|
|
51
|
+
setTableCache({
|
|
52
|
+
order: newOrder,
|
|
53
|
+
visibleItems: visibleItems
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 初始化字段的排序和显示隐藏
|
|
58
|
+
* */
|
|
59
|
+
var initColumnsSort = function () {
|
|
60
|
+
if (tableCache) {
|
|
61
|
+
setOrder(tableCache.order);
|
|
62
|
+
setVisibleItems(tableCache.visibleItems);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
var orderDataIndex = [];
|
|
66
|
+
var visibleDataIndex = [];
|
|
67
|
+
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
|
|
68
|
+
var item = columns_1[_i];
|
|
69
|
+
var id = void 0;
|
|
70
|
+
if ('dataIndex' in item) {
|
|
71
|
+
if (Array.isArray(item.dataIndex)) {
|
|
72
|
+
id = item.dataIndex.join(',');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
id = item.dataIndex;
|
|
76
|
+
}
|
|
77
|
+
orderDataIndex.push(id);
|
|
78
|
+
if (!('columnVisible' in item && !item.columnVisible)) {
|
|
79
|
+
visibleDataIndex.push(id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
setOrder(orderDataIndex);
|
|
84
|
+
setVisibleItems(visibleDataIndex);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* 初始化设置按钮
|
|
89
|
+
* @param column{object} 列表字段,加入按钮的字段
|
|
90
|
+
* */
|
|
91
|
+
var initSettingButton = function (column) {
|
|
92
|
+
var newColumn = __assign({}, column);
|
|
93
|
+
var columnTitleRender = function (children) {
|
|
94
|
+
return (React.createElement("span", null,
|
|
95
|
+
children,
|
|
96
|
+
React.createElement(PopoverSetColumns, { onChangeOrder: changeOrder, onChangeVisible: changeVisibleItems, order: order, columnsSort: columnsSort, visibleItems: visibleItems, columns: columns, columnsVisible: columnsVisible })));
|
|
97
|
+
};
|
|
98
|
+
if (typeof column.title === 'function') {
|
|
99
|
+
newColumn.title = function (props) {
|
|
100
|
+
return columnTitleRender(column.title(props));
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
newColumn.title = columnTitleRender(column.title);
|
|
105
|
+
}
|
|
106
|
+
return newColumn;
|
|
107
|
+
};
|
|
108
|
+
var renderDefaultColumn = function (value) {
|
|
109
|
+
return value !== null && value !== undefined && value !== ''
|
|
110
|
+
? (React.createElement(Tooltip, { title: value, placement: "topLeft" },
|
|
111
|
+
React.createElement("span", { className: 'column-ellipsis' }, value)))
|
|
112
|
+
: '-';
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* 展示在页面上的列表字段
|
|
116
|
+
* */
|
|
117
|
+
var renderColumns = useMemo(function () {
|
|
118
|
+
var returnColumns = columns;
|
|
119
|
+
if (!columnsSort && !columnsVisible) {
|
|
120
|
+
returnColumns = columns;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
var newColumns_1 = [];
|
|
124
|
+
order.filter(function (item) {
|
|
125
|
+
return visibleItems.includes(item);
|
|
126
|
+
}).forEach(function (item, index, array) {
|
|
127
|
+
for (var _i = 0, columns_2 = columns; _i < columns_2.length; _i++) {
|
|
128
|
+
var column = columns_2[_i];
|
|
129
|
+
if ('dataIndex' in column) {
|
|
130
|
+
var dataIndex = void 0;
|
|
131
|
+
if (Array.isArray(column.dataIndex)) {
|
|
132
|
+
dataIndex = column.dataIndex.join(',');
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
dataIndex = column.dataIndex;
|
|
136
|
+
}
|
|
137
|
+
if (item === dataIndex) {
|
|
138
|
+
if ((columnsSort || columnsVisible) && (index === array.length - 1)) {
|
|
139
|
+
/***
|
|
140
|
+
* 如果是 columnsSort 是 true 就把排序按钮放最后一个字段上
|
|
141
|
+
* */
|
|
142
|
+
newColumns_1.push(initSettingButton(column));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
newColumns_1.push(column);
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
returnColumns = newColumns_1;
|
|
153
|
+
}
|
|
154
|
+
return returnColumns.map(function (item) {
|
|
155
|
+
if (item.filters && !item.filterIcon) {
|
|
156
|
+
item.filterIcon = (React.createElement(DownOutlined, { type: "icon-xiajiantou", style: { fontWeight: 500 } }));
|
|
157
|
+
}
|
|
158
|
+
if (item.ellipsis === false) {
|
|
159
|
+
item.ellipsis = false;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
var ellipsisConfig = item.ellipsis || {};
|
|
163
|
+
item.ellipsis = __assign({ showTitle: false }, ellipsisConfig);
|
|
164
|
+
if (!item.render) {
|
|
165
|
+
item.render = renderDefaultColumn;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return item;
|
|
169
|
+
});
|
|
170
|
+
}, [order, visibleItems, columns]);
|
|
171
|
+
var paginationProps = useMemo(function () {
|
|
172
|
+
if (props.pagination) {
|
|
173
|
+
return __assign(__assign({}, (pagination || {})), { showTotal: function () {
|
|
174
|
+
return dataSource && dataSource.length > 0 && (React.createElement(Footer, __assign({}, props)));
|
|
175
|
+
} });
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}, [pagination]);
|
|
181
|
+
useEffect(function () {
|
|
182
|
+
initColumnsSort();
|
|
183
|
+
}, []);
|
|
184
|
+
return (React.createElement("div", { className: "table-wrapper", style: { position: 'relative' }, ref: ref },
|
|
185
|
+
React.createElement(Table, __assign({ ref: tableRef, scroll: {
|
|
186
|
+
x: 900
|
|
187
|
+
} }, props, { pagination: paginationProps, columns: renderColumns }))));
|
|
188
|
+
}
|
|
189
|
+
export default React.forwardRef(Index);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { type TableProps, type TableColumnType } from 'antd';
|
|
3
|
+
import { type ColumnTitleProps } from 'antd/es/table/interface';
|
|
4
|
+
import type { AnyObject } from 'antd/es/_util/type';
|
|
5
|
+
export type { AnyObject } from 'antd/es/_util/type';
|
|
6
|
+
export type { ColumnTitleProps } from 'antd/es/table/interface';
|
|
7
|
+
export interface TableCache {
|
|
8
|
+
order: string[];
|
|
9
|
+
visibleItems: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface ColumnType<RecordType> extends Omit<TableColumnType<RecordType>, 'title' | 'fixed'> {
|
|
12
|
+
/**
|
|
13
|
+
* 控制该字段是否支持排序,列表 columnsSort 为 true 时有效
|
|
14
|
+
* (columnSortDisabled,尽量只给首尾字段加,中间的字段加了用处不大)
|
|
15
|
+
*/
|
|
16
|
+
columnSortDisabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 控制是否支持字段的显示隐藏功能
|
|
19
|
+
*/
|
|
20
|
+
columnVisibleDisabled?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 字段的显示隐藏属性
|
|
23
|
+
*/
|
|
24
|
+
columnVisible?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 字段id
|
|
27
|
+
*/
|
|
28
|
+
dataIndex: string | string[];
|
|
29
|
+
/**
|
|
30
|
+
* 字段id
|
|
31
|
+
*/
|
|
32
|
+
fixed?: 'left' | 'right' | boolean | string;
|
|
33
|
+
/**
|
|
34
|
+
* 标题
|
|
35
|
+
*/
|
|
36
|
+
title?: React.ReactNode | ((props: ColumnTitleProps<RecordType>) => React.ReactNode);
|
|
37
|
+
}
|
|
38
|
+
export interface ColumnGroupType<RecordType = AnyObject> extends Omit<ColumnType<RecordType>, 'dataIndex'> {
|
|
39
|
+
children: TableComponentProps<RecordType>['columns'];
|
|
40
|
+
}
|
|
41
|
+
export type ColumnTypes<RecordType = AnyObject> = ColumnType<RecordType> | ColumnGroupType<RecordType>;
|
|
42
|
+
export interface TableComponentProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
|
|
43
|
+
/**
|
|
44
|
+
* 列表项
|
|
45
|
+
*/
|
|
46
|
+
columns?: Array<ColumnTypes<RecordType>>;
|
|
47
|
+
/**
|
|
48
|
+
* 是否打开列表字段排序功能
|
|
49
|
+
*/
|
|
50
|
+
columnsSort?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 是否打开列表字段的显示隐藏属性
|
|
53
|
+
*/
|
|
54
|
+
columnsVisible?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 列表唯一值,用来处理一个页面多个列表且同时开启字段排序或字段隐藏功能
|
|
57
|
+
*/
|
|
58
|
+
tableId?: string;
|
|
59
|
+
/**
|
|
60
|
+
* 中间的批量操作弹出层
|
|
61
|
+
*/
|
|
62
|
+
selectionPopover?: React.ReactNode;
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -62,7 +62,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
62
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.IconButton = void 0;
|
|
66
65
|
var react_1 = __importStar(require("react"));
|
|
67
66
|
var antd_1 = require("antd");
|
|
68
67
|
var lodash_es_1 = require("lodash-es");
|
|
@@ -83,7 +82,7 @@ var ButtonTooltip = function (_a) {
|
|
|
83
82
|
return (react_1.default.createElement(antd_1.Tooltip, __assign({ title: disabled ? disabledReason || title : title }, attrs), children));
|
|
84
83
|
}
|
|
85
84
|
};
|
|
86
|
-
|
|
85
|
+
var IconButton = function (props, ref) {
|
|
87
86
|
var iconButton = (0, react_1.useContext)(ConfigProvider_1.ConfigContext).iconButton;
|
|
88
87
|
var Icon = props.icon, _a = props.tooltipDisabled, tooltipDisabled = _a === void 0 ? false : _a, title = props.title, _b = props.hide, hide = _b === void 0 ? false : _b, disabledReason = props.disabledReason, _c = props.onClick, onClick = _c === void 0 ? lodash_es_1.noop : _c, disabled = props.disabled, _d = props.size, size = _d === void 0 ? iconButton.size || 'small' : _d, _e = props.style, style = _e === void 0 ? {} : _e, className = props.className, _f = props.loading, loading = _f === void 0 ? false : _f, attrs = __rest(props, ["icon", "tooltipDisabled", "title", "hide", "disabledReason", "onClick", "disabled", "size", "style", "className", "loading"]);
|
|
89
88
|
var createIcon = function () {
|
|
@@ -101,6 +100,6 @@ exports.IconButton = react_1.default.forwardRef(function (props, ref) {
|
|
|
101
100
|
return (react_1.default.createElement(IconButtonRender, __assign({}, props),
|
|
102
101
|
react_1.default.createElement(ButtonTooltip, __assign({ tooltipDisabled: tooltipDisabled, hide: hide, disabled: disabled, disabledReason: disabledReason, title: title }, attrs),
|
|
103
102
|
react_1.default.createElement(StyledButton, { ref: ref, icon: createIcon(), size: size, className: (0, classnames_1.default)(['icon-button', iconButton.className, className]), disabled: disabled, style: __assign(__assign({}, iconButton.style), style), loading: loading, onClick: onClick }))));
|
|
104
|
-
}
|
|
105
|
-
exports.default =
|
|
103
|
+
};
|
|
104
|
+
exports.default = react_1.default.forwardRef(IconButton);
|
|
106
105
|
var templateObject_1;
|