crud-page-react 0.1.2 → 0.1.4
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 +21 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -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,21 @@ 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 = customActions.map(action => ({
|
|
258
|
+
key: action.key,
|
|
259
|
+
label: action.label,
|
|
260
|
+
onClick: () => onCustomAction === null || onCustomAction === void 0 ? void 0 : onCustomAction(action.key, record),
|
|
261
|
+
danger: action.danger,
|
|
262
|
+
}));
|
|
263
|
+
return (jsxRuntime.jsxs(antd.Space, { size: 4, children: [basicActions.map((action) => {
|
|
253
264
|
var _a, _b, _c;
|
|
254
265
|
if (action.type === 'view') {
|
|
255
266
|
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 +271,20 @@ function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDel
|
|
|
260
271
|
if (action.type === 'delete') {
|
|
261
272
|
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
273
|
}
|
|
263
|
-
return
|
|
264
|
-
}), jsxRuntime.jsx(antd.Tooltip, { title: "\u590D\u5236 JSON", children: jsxRuntime.jsx(antd.Button, { type: "link", size: "small", icon: jsxRuntime.jsx(icons.CopyOutlined, {}), onClick: () => copyJson(record) }) })] }));
|
|
274
|
+
return null;
|
|
275
|
+
}), customActions.length > 0 && (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, {}) }) }) })), jsxRuntime.jsx(antd.Tooltip, { title: "\u590D\u5236 JSON", children: jsxRuntime.jsx(antd.Button, { type: "link", size: "small", icon: jsxRuntime.jsx(icons.CopyOutlined, {}), onClick: () => copyJson(record) }) })] }));
|
|
265
276
|
},
|
|
266
277
|
});
|
|
267
|
-
return (jsxRuntime.jsx(antd.Table, { rowKey: (
|
|
278
|
+
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
279
|
current: pagination.current,
|
|
269
280
|
pageSize: pagination.pageSize,
|
|
270
281
|
total: pagination.total,
|
|
271
282
|
showSizeChanger: true,
|
|
272
|
-
showTotal: ((
|
|
283
|
+
showTotal: ((_b = schema.pagination) === null || _b === void 0 ? void 0 : _b.showTotal)
|
|
273
284
|
? (total) => `共 ${total} 条`
|
|
274
285
|
: undefined,
|
|
275
286
|
onChange: pagination.onChange,
|
|
276
|
-
pageSizeOptions: (
|
|
287
|
+
pageSizeOptions: (_d = (_c = schema.pagination) === null || _c === void 0 ? void 0 : _c.pageSizeOptions) !== null && _d !== void 0 ? _d : [10, 20, 50],
|
|
277
288
|
} }));
|
|
278
289
|
}
|
|
279
290
|
|