crud-page-react 0.1.2 → 0.1.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 +31 -280
- package/dist/index.esm.js +32 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -215,7 +215,7 @@ function renderCell(field, value) {
|
|
|
215
215
|
return jsxRuntime.jsx("span", { children: String(value) });
|
|
216
216
|
}
|
|
217
217
|
function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDelete, onCustomAction, }) {
|
|
218
|
-
var _a, _b, _c, _d
|
|
218
|
+
var _a, _b, _c, _d;
|
|
219
219
|
const tableFields = schema.fields.filter((f) => f.table !== false && f.table !== undefined);
|
|
220
220
|
const columns = tableFields.map((field) => {
|
|
221
221
|
const cfg = getTableConfig(field);
|
|
@@ -246,10 +246,32 @@ function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDel
|
|
|
246
246
|
title: '操作',
|
|
247
247
|
key: '__actions',
|
|
248
248
|
fixed: 'right',
|
|
249
|
-
width:
|
|
249
|
+
width: 200, // 固定宽度,因为现在有下拉菜单
|
|
250
250
|
render: (_, record) => {
|
|
251
251
|
var _a;
|
|
252
|
-
|
|
252
|
+
const actions = (_a = schema.actions) !== null && _a !== void 0 ? _a : [];
|
|
253
|
+
// 分离基础操作和自定义操作
|
|
254
|
+
const basicActions = actions.filter(action => action.type === 'view' || action.type === 'edit' || action.type === 'delete');
|
|
255
|
+
const customActions = actions.filter(action => action.type === 'custom');
|
|
256
|
+
// 构建下拉菜单项
|
|
257
|
+
const dropdownItems = [
|
|
258
|
+
...customActions.map(action => ({
|
|
259
|
+
key: action.key,
|
|
260
|
+
label: action.label,
|
|
261
|
+
onClick: () => onCustomAction === null || onCustomAction === void 0 ? void 0 : onCustomAction(action.key, record),
|
|
262
|
+
danger: action.danger,
|
|
263
|
+
})),
|
|
264
|
+
...(customActions.length > 0 ? [{
|
|
265
|
+
type: 'divider',
|
|
266
|
+
}] : []),
|
|
267
|
+
{
|
|
268
|
+
key: 'copy-json',
|
|
269
|
+
label: '复制 JSON',
|
|
270
|
+
icon: jsxRuntime.jsx(icons.CopyOutlined, {}),
|
|
271
|
+
onClick: () => copyJson(record),
|
|
272
|
+
}
|
|
273
|
+
];
|
|
274
|
+
return (jsxRuntime.jsxs(antd.Space, { size: 4, children: [basicActions.map((action) => {
|
|
253
275
|
var _a, _b, _c;
|
|
254
276
|
if (action.type === 'view') {
|
|
255
277
|
return (jsxRuntime.jsx(antd.Tooltip, { title: action.label, children: jsxRuntime.jsx(antd.Button, { type: "link", size: "small", icon: jsxRuntime.jsx(icons.EyeOutlined, {}), onClick: () => onView(record) }) }, action.key));
|
|
@@ -260,20 +282,20 @@ function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDel
|
|
|
260
282
|
if (action.type === 'delete') {
|
|
261
283
|
return (jsxRuntime.jsx(antd.Popconfirm, { title: (_b = (_a = action.confirm) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : '确定删除?', description: (_c = action.confirm) === null || _c === void 0 ? void 0 : _c.content, onConfirm: () => onDelete(record), okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88", okButtonProps: { danger: true }, children: jsxRuntime.jsx(antd.Tooltip, { title: action.label, children: jsxRuntime.jsx(antd.Button, { type: "link", size: "small", danger: true, icon: jsxRuntime.jsx(icons.DeleteOutlined, {}) }) }) }, action.key));
|
|
262
284
|
}
|
|
263
|
-
return
|
|
264
|
-
}), jsxRuntime.jsx(antd.Tooltip, { title: "\
|
|
285
|
+
return null;
|
|
286
|
+
}), jsxRuntime.jsx(antd.Dropdown, { menu: { items: dropdownItems }, trigger: ['click'], placement: "bottomRight", children: jsxRuntime.jsx(antd.Tooltip, { title: "\u5176\u5B83\u64CD\u4F5C", children: jsxRuntime.jsx(antd.Button, { type: "link", size: "small", icon: jsxRuntime.jsx(icons.MoreOutlined, {}) }) }) })] }));
|
|
265
287
|
},
|
|
266
288
|
});
|
|
267
|
-
return (jsxRuntime.jsx(antd.Table, { rowKey: (
|
|
289
|
+
return (jsxRuntime.jsx(antd.Table, { rowKey: (_a = schema.rowKey) !== null && _a !== void 0 ? _a : 'id', columns: columns, dataSource: data, loading: loading, scroll: { x: 'max-content' }, pagination: {
|
|
268
290
|
current: pagination.current,
|
|
269
291
|
pageSize: pagination.pageSize,
|
|
270
292
|
total: pagination.total,
|
|
271
293
|
showSizeChanger: true,
|
|
272
|
-
showTotal: ((
|
|
294
|
+
showTotal: ((_b = schema.pagination) === null || _b === void 0 ? void 0 : _b.showTotal)
|
|
273
295
|
? (total) => `共 ${total} 条`
|
|
274
296
|
: undefined,
|
|
275
297
|
onChange: pagination.onChange,
|
|
276
|
-
pageSizeOptions: (
|
|
298
|
+
pageSizeOptions: (_d = (_c = schema.pagination) === null || _c === void 0 ? void 0 : _c.pageSizeOptions) !== null && _d !== void 0 ? _d : [10, 20, 50],
|
|
277
299
|
} }));
|
|
278
300
|
}
|
|
279
301
|
|