xmirror-components 1.0.27 → 1.0.28-alpha.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/build/dist/index.cjs +14 -14
- package/build/dist/index.mjs +150 -149
- package/build/es/components/IconButton/index.d.ts +2 -2
- package/build/es/components/IconButton/index.js +3 -7
- 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 -7
- 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 +1 -1
- package/build/package.json +1 -1
- package/build/types/components/IconButton/index.d.ts +2 -2
- 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,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var react_1 = __importStar(require("react"));
|
|
37
|
+
var react_intl_1 = require("react-intl");
|
|
38
|
+
var antd_1 = require("antd");
|
|
39
|
+
var react_transition_group_1 = require("react-transition-group");
|
|
40
|
+
var icons_1 = require("@ant-design/icons");
|
|
41
|
+
require("./index.less");
|
|
42
|
+
function Index(props) {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
var transitionNodeRef = (0, react_1.useRef)(null);
|
|
45
|
+
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;
|
|
46
|
+
/**
|
|
47
|
+
* 选中所有
|
|
48
|
+
* @param checked 选中状态
|
|
49
|
+
*/
|
|
50
|
+
var changeCheckAll = function (_a) {
|
|
51
|
+
var checked = _a.target.checked;
|
|
52
|
+
var _b = props.rowKey, rowKey = _b === void 0 ? 'id' : _b;
|
|
53
|
+
if (!rowSelection || !rowSelection.onChange)
|
|
54
|
+
return;
|
|
55
|
+
if (checked) {
|
|
56
|
+
var getCheckboxProps_1 = rowSelection.getCheckboxProps;
|
|
57
|
+
var tableData = dataSource;
|
|
58
|
+
if (getCheckboxProps_1) {
|
|
59
|
+
tableData = dataSource.filter(function (item) {
|
|
60
|
+
var data = getCheckboxProps_1(item);
|
|
61
|
+
return !data.disabled;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// rowKey 可能为字符串或函数,这里只处理字符串情况
|
|
65
|
+
var keyGetter = typeof rowKey === 'function' ? rowKey : function (item) { return item[rowKey]; };
|
|
66
|
+
rowSelection.onChange(Array.from(tableData.map(keyGetter)), Array.from(tableData), { type: 'none' });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
rowSelection.onChange([], [], { type: 'none' });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* optionalNum 可选的数量
|
|
74
|
+
* @return {number}
|
|
75
|
+
*/
|
|
76
|
+
var optionalNum = (0, react_1.useMemo)(function () {
|
|
77
|
+
var getCheckboxProps = rowSelection.getCheckboxProps;
|
|
78
|
+
var tableData = dataSource;
|
|
79
|
+
if (getCheckboxProps) {
|
|
80
|
+
tableData = dataSource.filter(function (item) {
|
|
81
|
+
var data = getCheckboxProps(item);
|
|
82
|
+
return !data.disabled;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return tableData.length;
|
|
86
|
+
}, [dataSource, rowSelection]);
|
|
87
|
+
/**
|
|
88
|
+
* indeterminate 选了,但没全选
|
|
89
|
+
* @return {boolean}
|
|
90
|
+
*/
|
|
91
|
+
var indeterminate = (0, react_1.useMemo)(function () {
|
|
92
|
+
var _a;
|
|
93
|
+
var selectedRowKeys = (_a = rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
|
|
94
|
+
return !!(selectedRowKeys.length > 0 && selectedRowKeys.length < optionalNum);
|
|
95
|
+
}, [rowSelection.selectedRowKeys, optionalNum]);
|
|
96
|
+
/**
|
|
97
|
+
* checked 选中状态
|
|
98
|
+
* @return {boolean}
|
|
99
|
+
*/
|
|
100
|
+
var checked = (0, react_1.useMemo)(function () {
|
|
101
|
+
var _a;
|
|
102
|
+
var selectedRowKeys = (_a = rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
|
|
103
|
+
return !!(selectedRowKeys.length > 0 && selectedRowKeys.length === optionalNum);
|
|
104
|
+
}, [rowSelection.selectedRowKeys, optionalNum]);
|
|
105
|
+
return (react_1.default.createElement("div", { className: "table-footer" },
|
|
106
|
+
react_1.default.createElement(react_transition_group_1.CSSTransition, { in: Boolean(props.rowSelection && props.selectionPopover && (checked || indeterminate)), nodeRef: transitionNodeRef, classNames: "zoom", unmountOnExit: true, timeout: 300 },
|
|
107
|
+
react_1.default.createElement(antd_1.Row, { ref: transitionNodeRef, className: "table-batch-dialog", justify: "space-between" },
|
|
108
|
+
react_1.default.createElement(antd_1.Col, { style: { display: 'flex', alignItems: 'center' } },
|
|
109
|
+
react_1.default.createElement(antd_1.Checkbox, { checked: checked, indeterminate: indeterminate, onChange: changeCheckAll },
|
|
110
|
+
react_1.default.createElement(react_intl_1.FormattedMessage, { id: "component.table.selected", defaultMessage: '已选{length}条', values: {
|
|
111
|
+
length: (_b = (_a = rowSelection.selectedRowKeys) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0
|
|
112
|
+
} }))),
|
|
113
|
+
react_1.default.createElement(antd_1.Col, { style: { display: 'flex', alignItems: 'center' } },
|
|
114
|
+
selectionPopover,
|
|
115
|
+
react_1.default.createElement("span", { className: "btn-close", onClick: function () { changeCheckAll({ target: { checked: false } }); } },
|
|
116
|
+
react_1.default.createElement(icons_1.CloseOutlined, null))))),
|
|
117
|
+
pagination && (react_1.default.createElement("span", { className: "table-footer-total" }, pagination.showTotal ? pagination.showTotal((_c = pagination.total) !== null && _c !== void 0 ? _c : 0, [0, 0]) : null))));
|
|
118
|
+
}
|
|
119
|
+
exports.default = Index;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
36
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
37
|
+
if (ar || !(i in from)) {
|
|
38
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
39
|
+
ar[i] = from[i];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
var react_1 = __importStar(require("react"));
|
|
49
|
+
var antd_1 = require("antd");
|
|
50
|
+
var react_intl_1 = require("react-intl");
|
|
51
|
+
var icons_1 = require("@ant-design/icons");
|
|
52
|
+
// import { message, IconFont } from 'xmirror-components'
|
|
53
|
+
var AntdApp_1 = require("../../AntdApp");
|
|
54
|
+
var IconFont_1 = __importDefault(require("../../IconFont"));
|
|
55
|
+
require("./index.less");
|
|
56
|
+
function PopoverSetColumns(_a) {
|
|
57
|
+
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;
|
|
58
|
+
var dragged = (0, react_1.useRef)(null);
|
|
59
|
+
var over = (0, react_1.useRef)(null);
|
|
60
|
+
/**
|
|
61
|
+
* 开始拖拽字段
|
|
62
|
+
* @param event{React.DragEvent<HTMLLIElement>}
|
|
63
|
+
* */
|
|
64
|
+
var dragStart = function (event) {
|
|
65
|
+
dragged.current = event.currentTarget;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 拖拽结束
|
|
69
|
+
* @param event{React.DragEvent<HTMLLIElement>}
|
|
70
|
+
* */
|
|
71
|
+
var dragEnd = function (event) {
|
|
72
|
+
if (!over.current || !dragged.current) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
dragged.current.style.display = 'block';
|
|
76
|
+
event.currentTarget.classList.remove('drag-up');
|
|
77
|
+
over.current.classList.remove('drag-up');
|
|
78
|
+
event.currentTarget.classList.remove('drag-down');
|
|
79
|
+
over.current.classList.remove('drag-down');
|
|
80
|
+
var newOrder = __spreadArray([], order, true);
|
|
81
|
+
var from = Number(dragged.current.dataset.index);
|
|
82
|
+
var to = Number(over.current.dataset.index);
|
|
83
|
+
newOrder.splice(to, 0, newOrder.splice(from, 1)[0]);
|
|
84
|
+
onChangeOrder(newOrder);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* 拖拽中
|
|
88
|
+
* @param event{React.DragEvent<HTMLUListElement>}
|
|
89
|
+
* */
|
|
90
|
+
var dragOver = function (event) {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
if (!dragged.current)
|
|
93
|
+
return;
|
|
94
|
+
dragged.current.style.display = 'none';
|
|
95
|
+
var target = event.target;
|
|
96
|
+
if (target.tagName !== 'LI') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var dgIndex = dragged.current.dataset.index;
|
|
100
|
+
var taIndex = target.dataset.index;
|
|
101
|
+
var id = target.dataset.id;
|
|
102
|
+
if (!id || notDraggableIds.includes(id)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (!dgIndex || !taIndex)
|
|
106
|
+
return;
|
|
107
|
+
var animateName = dgIndex > taIndex ? 'drag-up' : 'drag-down';
|
|
108
|
+
if (over.current && target.dataset.index !== over.current.dataset.index) {
|
|
109
|
+
over.current.classList.remove('drag-up', 'drag-down');
|
|
110
|
+
}
|
|
111
|
+
if (!target.classList.contains(animateName)) {
|
|
112
|
+
target.classList.add(animateName);
|
|
113
|
+
over.current = target;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 列显示隐藏
|
|
118
|
+
* @param event{CheckboxChangeEvent}
|
|
119
|
+
* @param dataIndex{array|string} 列表字段(columns)的 dataIndex
|
|
120
|
+
* */
|
|
121
|
+
var changeVisible = function (_a, _b) {
|
|
122
|
+
var checked = _a.target.checked;
|
|
123
|
+
var dataIndex = _b.dataIndex;
|
|
124
|
+
if (visibleItems.length === 1 && !checked) {
|
|
125
|
+
AntdApp_1.message.error(react_1.default.createElement(react_intl_1.FormattedMessage, { id: "component.table.visibleError", defaultMessage: '列表最少保留一个字段' }));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
var id = Array.isArray(dataIndex) ? dataIndex.join(',') : dataIndex;
|
|
129
|
+
var newVisibleItems = __spreadArray([], visibleItems, true);
|
|
130
|
+
if (checked) {
|
|
131
|
+
newVisibleItems.push(id);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
newVisibleItems.splice(newVisibleItems.indexOf(id), 1);
|
|
135
|
+
}
|
|
136
|
+
onChangeVisible(newVisibleItems);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* 不可拖拽字段的 dataIndex
|
|
140
|
+
* */
|
|
141
|
+
var notDraggableIds = (0, react_1.useMemo)(function () {
|
|
142
|
+
var arr = [];
|
|
143
|
+
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
|
|
144
|
+
var item = columns_1[_i];
|
|
145
|
+
if (item.columnSortDisabled && ('dataIndex' in item)) {
|
|
146
|
+
var dataIndex = void 0;
|
|
147
|
+
if (Array.isArray(item.dataIndex)) {
|
|
148
|
+
dataIndex = item.dataIndex.join(',');
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
dataIndex = item.dataIndex;
|
|
152
|
+
}
|
|
153
|
+
arr.push(dataIndex);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return arr;
|
|
157
|
+
}, [columns]);
|
|
158
|
+
/**
|
|
159
|
+
* 渲染到页面上的列表
|
|
160
|
+
* */
|
|
161
|
+
var renderList = (0, react_1.useMemo)(function () {
|
|
162
|
+
return order.map(function (item, index) {
|
|
163
|
+
var column;
|
|
164
|
+
for (var _i = 0, columns_2 = columns; _i < columns_2.length; _i++) {
|
|
165
|
+
var col = columns_2[_i];
|
|
166
|
+
if ('dataIndex' in col) {
|
|
167
|
+
var dataIndex = void 0;
|
|
168
|
+
if (Array.isArray(col.dataIndex)) {
|
|
169
|
+
dataIndex = col.dataIndex.join(',');
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
dataIndex = col.dataIndex;
|
|
173
|
+
}
|
|
174
|
+
if (item === dataIndex) {
|
|
175
|
+
column = col;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (!column || !('dataIndex' in column)) {
|
|
181
|
+
return '';
|
|
182
|
+
}
|
|
183
|
+
var draggable = columnsSort && column && !column.columnSortDisabled;
|
|
184
|
+
var id;
|
|
185
|
+
if (column && Array.isArray(column.dataIndex)) {
|
|
186
|
+
id = column.dataIndex.join(',');
|
|
187
|
+
}
|
|
188
|
+
else if (column) {
|
|
189
|
+
id = column.dataIndex;
|
|
190
|
+
}
|
|
191
|
+
var checked = typeof id === 'string' && visibleItems.includes(id);
|
|
192
|
+
return column
|
|
193
|
+
? (react_1.default.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) },
|
|
194
|
+
columnsSort && react_1.default.createElement(icons_1.HolderOutlined, { className: "icon-drag" }),
|
|
195
|
+
columnsVisible &&
|
|
196
|
+
react_1.default.createElement(antd_1.Checkbox, { style: { marginRight: '10px' }, checked: Boolean(checked), disabled: column.columnVisibleDisabled, onChange: function (event) { changeVisible(event, column); } }),
|
|
197
|
+
typeof column.title === 'function' ? column.title({}) : column.title))
|
|
198
|
+
: null;
|
|
199
|
+
});
|
|
200
|
+
}, [order, visibleItems, columns, columnsSort, columnsVisible]);
|
|
201
|
+
return (react_1.default.createElement(antd_1.Popover, { overlayClassName: "table-columns-setting-popover", content: react_1.default.createElement("ul", { onDragOver: dragOver, className: "table-columns-setting-wrapper" }, renderList), trigger: "click", align: {
|
|
202
|
+
offset: [-60, -14]
|
|
203
|
+
} },
|
|
204
|
+
react_1.default.createElement(IconFont_1.default, { type: "icon-setting", style: {
|
|
205
|
+
float: 'right',
|
|
206
|
+
fontSize: '17px',
|
|
207
|
+
lineHeight: 1,
|
|
208
|
+
marginTop: '2px',
|
|
209
|
+
fontWeight: 500
|
|
210
|
+
} })));
|
|
211
|
+
}
|
|
212
|
+
exports.default = PopoverSetColumns;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var react_1 = __importStar(require("react"));
|
|
51
|
+
var antd_1 = require("antd");
|
|
52
|
+
var ahooks_1 = require("ahooks");
|
|
53
|
+
var icons_1 = require("@ant-design/icons");
|
|
54
|
+
var PopoverSetColumns_1 = __importDefault(require("./PopoverSetColumns"));
|
|
55
|
+
var Footer_1 = __importDefault(require("./Footer"));
|
|
56
|
+
require("./index.less");
|
|
57
|
+
function Index(props, ref) {
|
|
58
|
+
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;
|
|
59
|
+
var pathname = location.pathname;
|
|
60
|
+
var _tableId = pathname + tableId;
|
|
61
|
+
var _c = (0, ahooks_1.useLocalStorageState)('TABLE_' + _tableId, {
|
|
62
|
+
defaultValue: null
|
|
63
|
+
}), tableCache = _c[0], setTableCache = _c[1];
|
|
64
|
+
var _d = (0, react_1.useState)([]), order = _d[0], setOrder = _d[1];
|
|
65
|
+
var _e = (0, react_1.useState)([]), visibleItems = _e[0], setVisibleItems = _e[1];
|
|
66
|
+
var tableRef = (0, react_1.useRef)(null);
|
|
67
|
+
/**
|
|
68
|
+
* 修改字段顺序
|
|
69
|
+
* @param newOrder{array} 新顺序
|
|
70
|
+
* */
|
|
71
|
+
var changeOrder = function (newOrder) {
|
|
72
|
+
setOrder(newOrder);
|
|
73
|
+
setCache(newOrder, visibleItems);
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* 修改显示的字段
|
|
77
|
+
* @param visibleItems{array} 显示的字段列表
|
|
78
|
+
* */
|
|
79
|
+
var changeVisibleItems = function (visibleItems) {
|
|
80
|
+
setVisibleItems(visibleItems);
|
|
81
|
+
setCache(order, visibleItems);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* 把排序和显示储存到浏览器
|
|
85
|
+
* @param visibleItems{array} 显示的字段列表
|
|
86
|
+
* @param newOrder{array} 新顺序
|
|
87
|
+
* */
|
|
88
|
+
var setCache = function (newOrder, visibleItems) {
|
|
89
|
+
setTableCache({
|
|
90
|
+
order: newOrder,
|
|
91
|
+
visibleItems: visibleItems
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 初始化字段的排序和显示隐藏
|
|
96
|
+
* */
|
|
97
|
+
var initColumnsSort = function () {
|
|
98
|
+
if (tableCache) {
|
|
99
|
+
setOrder(tableCache.order);
|
|
100
|
+
setVisibleItems(tableCache.visibleItems);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
var orderDataIndex = [];
|
|
104
|
+
var visibleDataIndex = [];
|
|
105
|
+
for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) {
|
|
106
|
+
var item = columns_1[_i];
|
|
107
|
+
var id = void 0;
|
|
108
|
+
if ('dataIndex' in item) {
|
|
109
|
+
if (Array.isArray(item.dataIndex)) {
|
|
110
|
+
id = item.dataIndex.join(',');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
id = item.dataIndex;
|
|
114
|
+
}
|
|
115
|
+
orderDataIndex.push(id);
|
|
116
|
+
if (!('columnVisible' in item && !item.columnVisible)) {
|
|
117
|
+
visibleDataIndex.push(id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
setOrder(orderDataIndex);
|
|
122
|
+
setVisibleItems(visibleDataIndex);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 初始化设置按钮
|
|
127
|
+
* @param column{object} 列表字段,加入按钮的字段
|
|
128
|
+
* */
|
|
129
|
+
var initSettingButton = function (column) {
|
|
130
|
+
var newColumn = __assign({}, column);
|
|
131
|
+
var columnTitleRender = function (children) {
|
|
132
|
+
return (react_1.default.createElement("span", null,
|
|
133
|
+
children,
|
|
134
|
+
react_1.default.createElement(PopoverSetColumns_1.default, { onChangeOrder: changeOrder, onChangeVisible: changeVisibleItems, order: order, columnsSort: columnsSort, visibleItems: visibleItems, columns: columns, columnsVisible: columnsVisible })));
|
|
135
|
+
};
|
|
136
|
+
if (typeof column.title === 'function') {
|
|
137
|
+
newColumn.title = function (props) {
|
|
138
|
+
return columnTitleRender(column.title(props));
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
newColumn.title = columnTitleRender(column.title);
|
|
143
|
+
}
|
|
144
|
+
return newColumn;
|
|
145
|
+
};
|
|
146
|
+
var renderDefaultColumn = function (value) {
|
|
147
|
+
return value !== null && value !== undefined && value !== ''
|
|
148
|
+
? (react_1.default.createElement(antd_1.Tooltip, { title: value, placement: "topLeft" },
|
|
149
|
+
react_1.default.createElement("span", { className: 'column-ellipsis' }, value)))
|
|
150
|
+
: '-';
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* 展示在页面上的列表字段
|
|
154
|
+
* */
|
|
155
|
+
var renderColumns = (0, react_1.useMemo)(function () {
|
|
156
|
+
var returnColumns = columns;
|
|
157
|
+
if (!columnsSort && !columnsVisible) {
|
|
158
|
+
returnColumns = columns;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
var newColumns_1 = [];
|
|
162
|
+
order.filter(function (item) {
|
|
163
|
+
return visibleItems.includes(item);
|
|
164
|
+
}).forEach(function (item, index, array) {
|
|
165
|
+
for (var _i = 0, columns_2 = columns; _i < columns_2.length; _i++) {
|
|
166
|
+
var column = columns_2[_i];
|
|
167
|
+
if ('dataIndex' in column) {
|
|
168
|
+
var dataIndex = void 0;
|
|
169
|
+
if (Array.isArray(column.dataIndex)) {
|
|
170
|
+
dataIndex = column.dataIndex.join(',');
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
dataIndex = column.dataIndex;
|
|
174
|
+
}
|
|
175
|
+
if (item === dataIndex) {
|
|
176
|
+
if ((columnsSort || columnsVisible) && (index === array.length - 1)) {
|
|
177
|
+
/***
|
|
178
|
+
* 如果是 columnsSort 是 true 就把排序按钮放最后一个字段上
|
|
179
|
+
* */
|
|
180
|
+
newColumns_1.push(initSettingButton(column));
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
newColumns_1.push(column);
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
returnColumns = newColumns_1;
|
|
191
|
+
}
|
|
192
|
+
return returnColumns.map(function (item) {
|
|
193
|
+
if (item.filters && !item.filterIcon) {
|
|
194
|
+
item.filterIcon = (react_1.default.createElement(icons_1.DownOutlined, { type: "icon-xiajiantou", style: { fontWeight: 500 } }));
|
|
195
|
+
}
|
|
196
|
+
if (item.ellipsis === false) {
|
|
197
|
+
item.ellipsis = false;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
var ellipsisConfig = item.ellipsis || {};
|
|
201
|
+
item.ellipsis = __assign({ showTitle: false }, ellipsisConfig);
|
|
202
|
+
if (!item.render) {
|
|
203
|
+
item.render = renderDefaultColumn;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return item;
|
|
207
|
+
});
|
|
208
|
+
}, [order, visibleItems, columns]);
|
|
209
|
+
var paginationProps = (0, react_1.useMemo)(function () {
|
|
210
|
+
if (props.pagination) {
|
|
211
|
+
return __assign(__assign({}, (pagination || {})), { showTotal: function () {
|
|
212
|
+
return dataSource && dataSource.length > 0 && (react_1.default.createElement(Footer_1.default, __assign({}, props)));
|
|
213
|
+
} });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}, [pagination]);
|
|
219
|
+
(0, react_1.useEffect)(function () {
|
|
220
|
+
initColumnsSort();
|
|
221
|
+
}, []);
|
|
222
|
+
return (react_1.default.createElement("div", { className: "table-wrapper", style: { position: 'relative' }, ref: ref },
|
|
223
|
+
react_1.default.createElement(antd_1.Table, __assign({ ref: tableRef, scroll: {
|
|
224
|
+
x: 900
|
|
225
|
+
} }, props, { pagination: paginationProps, columns: renderColumns }))));
|
|
226
|
+
}
|
|
227
|
+
exports.default = react_1.default.forwardRef(Index);
|
package/build/lib/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ declare interface ConfigProviderProps {
|
|
|
95
95
|
|
|
96
96
|
export declare function GlobalLoading(): default_2.JSX.Element;
|
|
97
97
|
|
|
98
|
-
export declare const IconButton:
|
|
98
|
+
export declare const IconButton: default_2.ForwardRefExoticComponent<IconButtonProps & default_2.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
|
99
99
|
|
|
100
100
|
declare type IconButtonConfig = Pick<IconButtonProps, 'size' | 'className' | 'style'> & {
|
|
101
101
|
render: (props: IconButtonProps & {
|
package/build/package.json
CHANGED
|
@@ -52,5 +52,5 @@ export interface IconButtonProps extends Omit<ButtonTooltipProps, 'children'> {
|
|
|
52
52
|
*/
|
|
53
53
|
flag?: string | number;
|
|
54
54
|
}
|
|
55
|
-
declare const
|
|
56
|
-
export default
|
|
55
|
+
declare const _default: React.ForwardRefExoticComponent<IconButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
|
56
|
+
export default _default;
|
|
@@ -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,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;
|