crud-page-react 0.2.0 → 0.2.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/dist/index.d.ts +15 -1
- package/dist/index.esm.js +44 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/dist/types/schema.d.ts +31 -1
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -67,6 +67,35 @@ function getFieldGroupPrefix(key) {
|
|
|
67
67
|
const idx = key.indexOf('.');
|
|
68
68
|
return idx >= 0 ? key.slice(0, idx) : null;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 检查操作按钮是否应该显示
|
|
72
|
+
*
|
|
73
|
+
* @param condition - 条件配置
|
|
74
|
+
* @param record - 当前行数据
|
|
75
|
+
* @returns 是否应该显示该操作
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // 字段值匹配
|
|
79
|
+
* shouldShowAction({ status: ['active', 'pending'] }, { status: 'active' }) → true
|
|
80
|
+
* shouldShowAction({ status: ['active', 'pending'] }, { status: 'deleted' }) → false
|
|
81
|
+
*
|
|
82
|
+
* // 支持嵌套字段(点分路径)
|
|
83
|
+
* shouldShowAction({ 'user.role': ['admin'] }, { user: { role: 'admin' } }) → true
|
|
84
|
+
*/
|
|
85
|
+
function shouldShowAction(condition, record) {
|
|
86
|
+
if (!condition || Object.keys(condition).length === 0) {
|
|
87
|
+
return true; // 没有条件时默认显示
|
|
88
|
+
}
|
|
89
|
+
for (const [fieldPath, allowedValues] of Object.entries(condition)) {
|
|
90
|
+
// 支持点分路径获取嵌套值
|
|
91
|
+
const actualValue = getNestedValue(record, fieldPath);
|
|
92
|
+
// 检查值是否在允许的值列表中
|
|
93
|
+
if (!allowedValues.includes(actualValue)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
70
99
|
|
|
71
100
|
const { RangePicker } = antd.DatePicker;
|
|
72
101
|
/** 解析 FilterConfig */
|
|
@@ -254,9 +283,21 @@ function DynamicTable({ schema, data, loading, pagination, onView, onEdit, onDel
|
|
|
254
283
|
render: (_, record) => {
|
|
255
284
|
var _a;
|
|
256
285
|
const actions = (_a = schema.actions) !== null && _a !== void 0 ? _a : [];
|
|
257
|
-
//
|
|
258
|
-
const basicActions = actions.filter(action =>
|
|
259
|
-
|
|
286
|
+
// 分离基础操作和自定义操作,并根据 condition 过滤
|
|
287
|
+
const basicActions = actions.filter(action => {
|
|
288
|
+
// 检查是否是基础操作类型
|
|
289
|
+
const isBasicAction = action.type === 'view' || action.type === 'edit' || action.type === 'delete';
|
|
290
|
+
if (!isBasicAction)
|
|
291
|
+
return false;
|
|
292
|
+
// 检查 condition 条件
|
|
293
|
+
return shouldShowAction(action.condition, record);
|
|
294
|
+
});
|
|
295
|
+
const customActions = actions.filter(action => {
|
|
296
|
+
if (action.type !== 'custom')
|
|
297
|
+
return false;
|
|
298
|
+
// 检查 condition 条件
|
|
299
|
+
return shouldShowAction(action.condition, record);
|
|
300
|
+
});
|
|
260
301
|
// 构建下拉菜单项(仅包含自定义操作)
|
|
261
302
|
const dropdownItems = customActions.map(action => ({
|
|
262
303
|
key: action.key,
|