vap1 0.7.8 → 0.7.9
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/components/Tables/VTable.d.ts +10 -0
- package/components/Tables/VTable.js +122 -8
- package/package.json +1 -1
- package/utils/Global.d.ts +5 -0
- package/utils/Global.js +1 -0
|
@@ -26,6 +26,11 @@ export type VTableProps = BaseTableProps & {
|
|
|
26
26
|
* 选中后变化
|
|
27
27
|
*/
|
|
28
28
|
onSelectedChange?: (selectedRowKeys: Key[], selectedRows?: any[]) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 是否启用列宽拖拽调整功能,默认 false
|
|
31
|
+
* 谨慎使用
|
|
32
|
+
*/
|
|
33
|
+
resizable?: boolean;
|
|
29
34
|
};
|
|
30
35
|
export declare const VTable: React.ForwardRefExoticComponent<import("./index").TableDefine & Pick<BoxProps, "default" | "mode" | "selectBar" | "defaultParam"> & {
|
|
31
36
|
searchBar?: Omit<import("../SearchTool").SearchBarProps, "onChange" | "onSearch">;
|
|
@@ -50,4 +55,9 @@ export declare const VTable: React.ForwardRefExoticComponent<import("./index").T
|
|
|
50
55
|
* 选中后变化
|
|
51
56
|
*/
|
|
52
57
|
onSelectedChange?: (selectedRowKeys: Key[], selectedRows?: any[]) => void;
|
|
58
|
+
/**
|
|
59
|
+
* 是否启用列宽拖拽调整功能,默认 false
|
|
60
|
+
* 谨慎使用
|
|
61
|
+
*/
|
|
62
|
+
resizable?: boolean;
|
|
53
63
|
} & React.RefAttributes<VTableRef>>;
|
|
@@ -43,6 +43,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
43
43
|
return result;
|
|
44
44
|
};
|
|
45
45
|
})();
|
|
46
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
47
|
+
var t = {};
|
|
48
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
49
|
+
t[p] = s[p];
|
|
50
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
51
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
52
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
53
|
+
t[p[i]] = s[p[i]];
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
};
|
|
46
57
|
var __read = (this && this.__read) || function (o, n) {
|
|
47
58
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
48
59
|
if (!m) return o;
|
|
@@ -92,13 +103,62 @@ var getHeightByTagName = function (root, tagName) {
|
|
|
92
103
|
return 0;
|
|
93
104
|
};
|
|
94
105
|
exports.getHeightByTagName = getHeightByTagName;
|
|
106
|
+
// 可拖拽的表头单元格组件
|
|
107
|
+
var ResizableHeaderCell = function (props) {
|
|
108
|
+
var onResize = props.onResize, width = props.width, restProps = __rest(props, ["onResize", "width"]);
|
|
109
|
+
var _a = __read((0, react_1.useState)(false), 2), resizing = _a[0], setResizing = _a[1];
|
|
110
|
+
var startXRef = (0, react_1.useRef)(0);
|
|
111
|
+
var startWidthRef = (0, react_1.useRef)(0);
|
|
112
|
+
var handleMouseDown = (0, react_1.useCallback)(function (e) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
e.stopPropagation();
|
|
115
|
+
setResizing(true);
|
|
116
|
+
startXRef.current = e.clientX;
|
|
117
|
+
startWidthRef.current = width || 128;
|
|
118
|
+
var handleMouseMove = function (moveEvent) {
|
|
119
|
+
var deltaX = moveEvent.clientX - startXRef.current;
|
|
120
|
+
var newWidth = Math.max(50, startWidthRef.current + deltaX);
|
|
121
|
+
if (onResize) {
|
|
122
|
+
onResize(newWidth);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var handleMouseUp = function () {
|
|
126
|
+
setResizing(false);
|
|
127
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
128
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
129
|
+
};
|
|
130
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
131
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
132
|
+
}, [width, onResize]);
|
|
133
|
+
return (react_1.default.createElement("th", __assign({}, restProps, { style: __assign(__assign({}, restProps.style), { position: 'relative', width: width }) }),
|
|
134
|
+
restProps.children,
|
|
135
|
+
onResize && (react_1.default.createElement("div", { className: "resize-handle", onMouseDown: handleMouseDown, style: {
|
|
136
|
+
position: 'absolute',
|
|
137
|
+
right: 0,
|
|
138
|
+
top: 0,
|
|
139
|
+
bottom: 0,
|
|
140
|
+
width: '4px',
|
|
141
|
+
cursor: 'col-resize',
|
|
142
|
+
backgroundColor: resizing ? '#1890ff' : 'transparent',
|
|
143
|
+
zIndex: 1,
|
|
144
|
+
userSelect: 'none',
|
|
145
|
+
}, onMouseEnter: function (e) {
|
|
146
|
+
e.target.style.backgroundColor = '#1890ff';
|
|
147
|
+
}, onMouseLeave: function (e) {
|
|
148
|
+
if (!resizing) {
|
|
149
|
+
e.target.style.backgroundColor = 'transparent';
|
|
150
|
+
}
|
|
151
|
+
} }))));
|
|
152
|
+
};
|
|
95
153
|
var _VTable = (0, react_1.forwardRef)(function (props) {
|
|
96
|
-
var _a
|
|
97
|
-
var _b = (0,
|
|
154
|
+
var _a;
|
|
155
|
+
var _b = (0, useTableContext_1.useTableContext)(), selectedRowKeys = _b.selectedRowKeys, initObjects = _b.initObjects, reflushPage = _b.reflushPage, setSelection = _b.setSelection;
|
|
156
|
+
var _c = (0, Box_1.useBox)(), state = _c.state, root = _c.root, resize = _c.resize;
|
|
98
157
|
var update = (0, hooks_1.useUpdate)();
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
var
|
|
158
|
+
var _d = __read((0, react_1.useState)(undefined), 2), scroll = _d[0], setScroll = _d[1];
|
|
159
|
+
var _e = __read((0, react_1.useState)({}), 2), columnWidths = _e[0], setColumnWidths = _e[1];
|
|
160
|
+
var _f = props.model, rowKey = _f.rowKey, list = _f.list, isQuerying = _f.isQuerying, pageNo = _f.pageNo, pageSize = _f.pageSize, orderBy = _f.orderBy, query = _f.query, total = _f.total, cost = _f.cost;
|
|
161
|
+
var _g = __read((0, react_1.useState)([false, false]), 2), _h = __read(_g[0], 2), pageEnterd = _h[0], pageLoaded = _h[1], setSatus = _g[1];
|
|
102
162
|
(0, react_1.useEffect)(function () {
|
|
103
163
|
if (isQuerying)
|
|
104
164
|
return;
|
|
@@ -143,10 +203,39 @@ var _VTable = (0, react_1.forwardRef)(function (props) {
|
|
|
143
203
|
reflushPage(list);
|
|
144
204
|
}, [pageLoaded, list]);
|
|
145
205
|
// 计算 clolum 及 高亮keyword
|
|
146
|
-
var columns = (0, react_1.useMemo)(function () {
|
|
206
|
+
var columns = (0, react_1.useMemo)(function () {
|
|
207
|
+
var _a;
|
|
208
|
+
var cols = (0, Util_1.convertColumns)(props, { ref: start, isRank: false });
|
|
209
|
+
// 如果启用 resizable,初始化列宽
|
|
210
|
+
var enableResize = (_a = props.resizable) !== null && _a !== void 0 ? _a : utils_1.GLOBAL.CONFIG.TABLE.RESIZABLE;
|
|
211
|
+
if (enableResize) {
|
|
212
|
+
var widths_1 = {};
|
|
213
|
+
cols.forEach(function (col, index) {
|
|
214
|
+
var key = col.dataIndex || col.key || "col_".concat(index);
|
|
215
|
+
if (key && !columnWidths[key]) {
|
|
216
|
+
widths_1[key] = col.width || 128;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (Object.keys(widths_1).length > 0) {
|
|
220
|
+
setColumnWidths(function (prev) { return (__assign(__assign({}, prev), widths_1)); });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return cols;
|
|
224
|
+
}, [props.columns, props.resizable]);
|
|
225
|
+
// 应用列宽(仅在 resizable 模式下)
|
|
226
|
+
var finalColumns = (0, react_1.useMemo)(function () {
|
|
227
|
+
var _a;
|
|
228
|
+
var enableResize = (_a = props.resizable) !== null && _a !== void 0 ? _a : utils_1.GLOBAL.CONFIG.TABLE.RESIZABLE;
|
|
229
|
+
if (!enableResize)
|
|
230
|
+
return columns;
|
|
231
|
+
return columns.map(function (col, index) {
|
|
232
|
+
var key = col.dataIndex || col.key || "col_".concat(index);
|
|
233
|
+
return __assign(__assign({}, col), { width: columnWidths[key] || col.width || 128, onHeaderCell: function (column) { return (__assign({ 'data-column-key': key }, (col.onHeaderCell ? col.onHeaderCell(column) : {}))); } });
|
|
234
|
+
});
|
|
235
|
+
}, [columns, columnWidths, props.resizable]);
|
|
147
236
|
(0, react_1.useLayoutEffect)(function () {
|
|
148
237
|
resize();
|
|
149
|
-
}, [
|
|
238
|
+
}, [finalColumns]);
|
|
150
239
|
(0, react_1.useEffect)(function () {
|
|
151
240
|
if (props.autoLoad === false)
|
|
152
241
|
return;
|
|
@@ -219,9 +308,34 @@ var _VTable = (0, react_1.forwardRef)(function (props) {
|
|
|
219
308
|
// if (list.length) {
|
|
220
309
|
// tableProps.tableLayout = "fixed";
|
|
221
310
|
// }
|
|
311
|
+
// 自定义表头组件(仅在 resizable 模式下)
|
|
312
|
+
var components = (0, react_1.useMemo)(function () {
|
|
313
|
+
var _a;
|
|
314
|
+
var enableResize = (_a = props.resizable) !== null && _a !== void 0 ? _a : utils_1.GLOBAL.CONFIG.TABLE.RESIZABLE;
|
|
315
|
+
if (!enableResize)
|
|
316
|
+
return undefined;
|
|
317
|
+
return {
|
|
318
|
+
header: {
|
|
319
|
+
cell: function (cellProps) {
|
|
320
|
+
var children = cellProps.children, restCellProps = __rest(cellProps, ["children"]);
|
|
321
|
+
var columnKey = restCellProps['data-column-key'];
|
|
322
|
+
if (!columnKey) {
|
|
323
|
+
return react_1.default.createElement("th", __assign({}, restCellProps), children);
|
|
324
|
+
}
|
|
325
|
+
return (react_1.default.createElement(ResizableHeaderCell, __assign({}, restCellProps, { width: columnWidths[columnKey], onResize: function (newWidth) {
|
|
326
|
+
setColumnWidths(function (prev) {
|
|
327
|
+
var _a;
|
|
328
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[columnKey] = newWidth, _a)));
|
|
329
|
+
});
|
|
330
|
+
} }), children));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}, [props.resizable, columnWidths]);
|
|
335
|
+
var enableResize = (_a = props.resizable) !== null && _a !== void 0 ? _a : utils_1.GLOBAL.CONFIG.TABLE.RESIZABLE;
|
|
222
336
|
return react_1.default.createElement(antd_1.Table, __assign({ rowKey: props.rowKey || rowKey, scroll: scroll,
|
|
223
337
|
// showSorterTooltip={false}
|
|
224
|
-
size: utils_1.GLOBAL.CONFIG.TABLE.SIZE, locale: { emptyText: react_1.default.createElement(antd_1.Empty, { style: { marginTop: 24 } }) } }, lodash_1.default.omit(props, ['children']), tableProps, { className: utils_1.StringUtil.className(['c-table'], props.className), pagination: false, columns:
|
|
338
|
+
size: utils_1.GLOBAL.CONFIG.TABLE.SIZE, locale: { emptyText: react_1.default.createElement(antd_1.Empty, { style: { marginTop: 24 } }) } }, lodash_1.default.omit(props, ['children', 'resizable']), tableProps, { className: utils_1.StringUtil.className(['c-table', enableResize && 'c-resizable-table'], props.className), pagination: false, columns: finalColumns, dataSource: list, loading: isQuerying, components: components, tableLayout: enableResize ? 'fixed' : undefined, onChange: function (x, y, field) {
|
|
225
339
|
if (field.column) {
|
|
226
340
|
orderBy(field.field, field.order == 'ascend' ? 'asc' : 'desc');
|
|
227
341
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"vap1","version":"0.7.
|
|
1
|
+
{"name":"vap1","version":"0.7.9","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
|
package/utils/Global.d.ts
CHANGED