feat: improve Table.Operation

This commit is contained in:
chenos 2021-08-18 11:30:24 +08:00
parent 90f8f721b7
commit 3e5e9c194c
3 changed files with 424 additions and 455 deletions

View File

@ -92,14 +92,13 @@ const useActionPermissionResource = ({ onSuccess }) => {
console.log('actionPermissions', data); console.log('actionPermissions', data);
onSuccess({ onSuccess({
actionPermissions: data.map((permission) => { actionPermissions: data.map((permission) => {
const item: any = {} const item: any = {};
Object.keys(permission).forEach(key => { Object.keys(permission).forEach((key) => {
if (isValid(permission[key])) { if (isValid(permission[key])) {
item[key] = permission[key]; item[key] = permission[key];
} }
}); });
item.fields = item.fields = permission?.fields.map((field) => field.key) || [];
permission?.fields.map((field) => field.key) || [];
return item; return item;
}), }),
}); });
@ -162,63 +161,6 @@ const collectionSchema: ISchema = {
collectionName: 'collections', collectionName: 'collections',
}, },
properties: { properties: {
[uid()]: {
type: 'void',
title: '操作',
'x-component': 'Table.Operation',
'x-component-props': {
className: 'nb-table-operation',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
icon: 'EllipsisOutlined',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action.Dropdown',
'x-component-props': {},
properties: {
[uid()]: {
type: 'void',
title: '配置',
'x-component': 'Menu.Action',
'x-component-props': {
style: {
minWidth: 150,
},
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '数据表操作权限',
'x-component': 'Action.Drawer',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: useActionPermissionResource,
},
'x-component-props': {
useOkAction: useActionPermissionSubmit,
},
properties: {
actionPermissions: {
type: 'array',
'x-component': 'ActionPermissionField',
},
},
},
},
},
},
},
},
},
},
},
column1: { column1: {
type: 'void', type: 'void',
title: '数据表名称', title: '数据表名称',
@ -243,6 +185,54 @@ const collectionSchema: ISchema = {
}, },
}, },
}, },
column3: {
type: 'void',
title: '操作',
'x-component': 'Table.Column',
'x-component-props': {
width: 60,
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action.Group',
'x-component-props': {
type: 'link',
},
properties: {
[uid()]: {
type: 'void',
title: '配置',
'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '数据表操作权限',
'x-component': 'Action.Drawer',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: useActionPermissionResource,
},
'x-component-props': {
useOkAction: useActionPermissionSubmit,
},
properties: {
actionPermissions: {
type: 'array',
'x-component': 'ActionPermissionField',
},
},
},
},
},
},
},
},
},
}, },
}; };
@ -342,121 +332,6 @@ const schema: ISchema = {
}, },
}, },
}, },
[uid()]: {
type: 'void',
title: '操作',
'x-component': 'Table.Operation',
'x-component-props': {
className: 'nb-table-operation',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
icon: 'EllipsisOutlined',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action.Dropdown',
'x-component-props': {},
properties: {
[uid()]: {
type: 'void',
title: '配置',
'x-component': 'Menu.Action',
'x-component-props': {
style: {
minWidth: 150,
},
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '权限配置',
'x-decorator': 'RoleProvider',
'x-component': 'Action.Drawer',
'x-component-props': {
bodyStyle: {
background: '#f0f2f5',
paddingTop: 0,
},
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Tabs',
properties: {
[uid()]: {
type: 'void',
title: '数据表操作权限',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: {
collectionSchema,
},
},
[uid()]: {
type: 'void',
title: '菜单访问权限',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: {
menuSchema,
},
},
},
},
},
},
},
},
[uid()]: {
type: 'void',
title: '编辑',
'x-component': 'Menu.Action',
'x-action-type': 'update',
properties: {
[uid()]: {
type: 'void',
title: '编辑数据',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: useDetailsResource,
},
'x-component': 'Action.Drawer',
'x-component-props': {
useOkAction: '{{ Table.useTableUpdateAction }}',
},
properties: {
title: {
type: 'string',
title: '权限名称',
'x-component': 'Input',
'x-decorator': 'FormilyFormItem',
},
},
},
},
},
[uid()]: {
type: 'void',
title: '删除',
'x-component': 'Menu.Action',
'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'destroy',
'x-component-props': {
useAction: '{{ Table.useTableDestroyAction }}',
},
},
},
},
},
},
},
},
column1: { column1: {
type: 'void', type: 'void',
title: '权限名称', title: '权限名称',
@ -481,6 +356,116 @@ const schema: ISchema = {
}, },
}, },
}, },
[uid()]: {
type: 'void',
title: '操作',
'x-component': 'Table.Column',
'x-component-props': {
width: 160,
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action.Group',
'x-component-props': {
type: 'link',
},
properties: {
[uid()]: {
type: 'void',
title: '配置',
'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '权限配置',
'x-decorator': 'RoleProvider',
'x-component': 'Action.Drawer',
'x-component-props': {
bodyStyle: {
background: '#f0f2f5',
paddingTop: 0,
},
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Tabs',
properties: {
[uid()]: {
type: 'void',
title: '数据表操作权限',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: {
collectionSchema,
},
},
[uid()]: {
type: 'void',
title: '菜单访问权限',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: {
menuSchema,
},
},
},
},
},
},
},
},
[uid()]: {
type: 'void',
title: '编辑',
'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-action-type': 'update',
properties: {
[uid()]: {
type: 'void',
title: '编辑数据',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: useDetailsResource,
},
'x-component': 'Action.Drawer',
'x-component-props': {
useOkAction: '{{ Table.useTableUpdateAction }}',
},
properties: {
title: {
type: 'string',
title: '权限名称',
'x-component': 'Input',
'x-decorator': 'FormilyFormItem',
},
},
},
},
},
[uid()]: {
type: 'void',
title: '删除',
'x-component': 'Action',
'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'destroy',
'x-component-props': {
type: 'link',
useAction: '{{ Table.useTableDestroyAction }}',
},
},
},
},
},
},
}, },
}, },
}, },

View File

@ -196,7 +196,7 @@ function generateCardItemSchema(component) {
type: 'void', type: 'void',
title: '新增数据', title: '新增数据',
'x-decorator': 'Form', 'x-decorator': 'Form',
'x-component': 'Action.Modal', 'x-component': 'Action.Drawer',
'x-component-props': { 'x-component-props': {
useOkAction: '{{ Table.useTableCreateAction }}', useOkAction: '{{ Table.useTableCreateAction }}',
}, },
@ -217,79 +217,56 @@ function generateCardItemSchema(component) {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '操作', title: '操作',
'x-component': 'Table.Operation', 'x-component': 'Table.Column',
'x-component-props': { 'x-component-props': {},
className: 'nb-table-operation',
},
'x-designable-bar': 'Table.Operation.DesignableBar', 'x-designable-bar': 'Table.Operation.DesignableBar',
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
'x-component': 'Action', 'x-component': 'Action.Group',
'x-component-props': { 'x-component-props': {
icon: 'EllipsisOutlined', type: 'link',
}, },
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
'x-component': 'Action.Dropdown', name: 'action1',
'x-component-props': {}, title: '查看',
'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'view',
properties: { properties: {
// [uid()]: {
// type: 'void',
// title: '操作 1',
// 'x-component': 'Menu.Action',
// 'x-component-props': {
// style: {
// minWidth: 150,
// },
// disabled: true,
// },
// },
[uid()]: { [uid()]: {
type: 'void', type: 'void',
name: 'action1', title: '查看数据',
title: '查看', 'x-component': 'Action.Drawer',
'x-component': 'Menu.Action',
'x-component-props': { 'x-component-props': {
style: { bodyStyle: {
minWidth: 150, background: '#f0f2f5',
// paddingTop: 0,
}, },
}, },
'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'view',
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '查看', 'x-component': 'Tabs',
'x-component': 'Action.Modal', 'x-designable-bar': 'Tabs.DesignableBar',
'x-component-props': {
bodyStyle: {
background: '#f0f2f5',
// paddingTop: 0,
},
},
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
'x-component': 'Tabs', title: '详情',
'x-designable-bar': 'Tabs.DesignableBar', 'x-designable-bar': 'Tabs.TabPane.DesignableBar',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '详情', 'x-component': 'Grid',
'x-designable-bar': 'x-component-props': {
'Tabs.TabPane.DesignableBar', addNewComponent: 'AddNew.PaneItem',
'x-component': 'Tabs.TabPane',
'x-component-props': {},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Grid',
'x-component-props': {
addNewComponent: 'AddNew.PaneItem',
},
},
}, },
}, },
}, },
@ -298,47 +275,51 @@ function generateCardItemSchema(component) {
}, },
}, },
}, },
},
},
[uid()]: {
type: 'void',
title: '编辑',
'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'update',
properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '编辑', title: '编辑数据',
'x-component': 'Menu.Action', 'x-decorator': 'Form',
'x-designable-bar': 'Table.Action.DesignableBar', 'x-decorator-props': {
'x-action-type': 'update', useResource: '{{ Table.useResource }}',
useValues: '{{ Table.useTableRowRecord }}',
},
'x-component': 'Action.Drawer',
'x-component-props': {
useOkAction: '{{ Table.useTableUpdateAction }}',
},
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '编辑数据', 'x-component': 'Grid',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: '{{ Table.useResource }}',
useValues: '{{ Table.useTableRowRecord }}',
},
'x-component': 'Action.Modal',
'x-component-props': { 'x-component-props': {
useOkAction: '{{ Table.useTableUpdateAction }}', addNewComponent: 'AddNew.FormItem',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Grid',
'x-component-props': {
addNewComponent: 'AddNew.FormItem',
},
},
}, },
}, },
}, },
}, },
[uid()]: { },
type: 'void', },
title: '删除', [uid()]: {
'x-component': 'Menu.Action', type: 'void',
'x-designable-bar': 'Table.Action.DesignableBar', title: '删除',
'x-action-type': 'destroy', 'x-component': 'Action',
'x-component-props': { 'x-designable-bar': 'Table.Action.DesignableBar',
useAction: '{{ Table.useTableDestroyAction }}', 'x-action-type': 'destroy',
}, 'x-component-props': {
}, type: 'link',
useAction: '{{ Table.useTableDestroyAction }}',
}, },
}, },
}, },
@ -471,179 +452,6 @@ function generateCardItemSchema(component) {
}, },
}, },
}, },
[uid()]: {
type: 'void',
title: '操作',
'x-component': 'Table.Operation',
'x-component-props': {
className: 'nb-table-operation',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
icon: 'EllipsisOutlined',
},
properties: {
[uid()]: {
type: 'void',
'x-component': 'Action.Dropdown',
'x-component-props': {},
properties: {
[uid()]: {
type: 'void',
name: 'action1',
title: '查看',
'x-component': 'Menu.Action',
'x-component-props': {
style: {
minWidth: 150,
},
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '查看数据',
'x-read-pretty': true,
'x-decorator': 'Form',
'x-decorator-props': {
useResource:
'{{ Table.useActionLogDetailsResource }}',
},
'x-component': 'Action.Drawer',
'x-component-props': {
// bodyStyle: {
// background: '#f0f2f5',
// // paddingTop: 0,
// },
},
properties: {
created_at: {
type: 'string',
title: '操作时间',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-read-pretty': true,
'x-component-props': {
format: 'YYYY-MM-DD HH:mm:ss',
},
},
'user.nickname': {
type: 'string',
title: '操作用户',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-read-pretty': true,
},
'collection.title': {
type: 'string',
title: '所属数据表',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-read-pretty': true,
},
type: {
type: 'string',
title: '操作类型',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-read-pretty': true,
enum: [
{
label: '新增',
value: 'create',
color: 'green',
},
{
label: '更新',
value: 'update',
color: 'blue',
},
{
label: '删除',
value: 'destroy',
color: 'red',
},
],
},
changes: {
type: 'array',
title: '数据变动',
'x-decorator': 'FormItem',
'x-component': 'ArrayTable',
'x-component-props': {
pagination: false,
// scroll: { x: '100%' },
},
// 'x-reactions': ['{{ filterActionLogs }}'],
items: {
type: 'object',
properties: {
column0: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': {
width: 80,
align: 'center',
},
properties: {
index: {
type: 'void',
'x-component': 'ArrayTable.Index',
},
},
},
column1: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '字段名称' },
properties: {
field: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.Field',
},
},
},
column3: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '操作前' },
properties: {
before: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.FieldValue',
},
},
},
column4: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '操作后' },
properties: {
after: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.FieldValue',
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
column1: { column1: {
type: 'void', type: 'void',
title: '操作时间', title: '操作时间',
@ -700,6 +508,165 @@ function generateCardItemSchema(component) {
}, },
}, },
}, },
[uid()]: {
type: 'void',
title: '操作',
'x-component': 'Table.Column',
'x-component-props': {
width: 60,
align: 'center',
},
properties: {
[uid()]: {
type: 'void',
name: 'action1',
title: '查看',
'x-component': 'Action',
'x-component-props': {
type: 'link',
style: {
padding: '0',
height: 'auto',
},
},
'x-action-type': 'view',
properties: {
[uid()]: {
type: 'void',
title: '查看数据',
'x-read-pretty': true,
'x-decorator': 'Form',
'x-decorator-props': {
useResource: '{{ Table.useActionLogDetailsResource }}',
},
'x-component': 'Action.Drawer',
'x-component-props': {
// bodyStyle: {
// background: '#f0f2f5',
// // paddingTop: 0,
// },
},
properties: {
created_at: {
type: 'string',
title: '操作时间',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-read-pretty': true,
'x-component-props': {
format: 'YYYY-MM-DD HH:mm:ss',
},
},
'user.nickname': {
type: 'string',
title: '操作用户',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-read-pretty': true,
},
'collection.title': {
type: 'string',
title: '所属数据表',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-read-pretty': true,
},
type: {
type: 'string',
title: '操作类型',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-read-pretty': true,
enum: [
{
label: '新增',
value: 'create',
color: 'green',
},
{
label: '更新',
value: 'update',
color: 'blue',
},
{
label: '删除',
value: 'destroy',
color: 'red',
},
],
},
changes: {
type: 'array',
title: '数据变动',
'x-decorator': 'FormItem',
'x-component': 'ArrayTable',
'x-component-props': {
pagination: false,
// scroll: { x: '100%' },
},
// 'x-reactions': ['{{ filterActionLogs }}'],
items: {
type: 'object',
properties: {
column0: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': {
width: 80,
align: 'center',
},
properties: {
index: {
type: 'void',
'x-component': 'ArrayTable.Index',
},
},
},
column1: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '字段名称' },
properties: {
field: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.Field',
},
},
},
column3: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '操作前' },
properties: {
before: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.FieldValue',
},
},
},
column4: {
type: 'void',
'x-component': 'ArrayTable.Column',
'x-component-props': { title: '操作后' },
properties: {
after: {
type: 'string',
'x-decorator': 'FormilyFormItem',
'x-component': 'ActionLogs.FieldValue',
},
},
},
},
},
},
},
},
},
},
},
},
}, },
}, },
}; };
@ -935,7 +902,11 @@ AddNew.CardItem = observer((props: any) => {
{ghost ? ( {ghost ? (
<PlusOutlined /> <PlusOutlined />
) : ( ) : (
<Button type={'dashed'} className={'designable-btn designable-btn-dash'} icon={<PlusOutlined />}> <Button
type={'dashed'}
className={'designable-btn designable-btn-dash'}
icon={<PlusOutlined />}
>
</Button> </Button>
)} )}
@ -1122,7 +1093,11 @@ AddNew.FormItem = observer((props: any) => {
{ghost ? ( {ghost ? (
<PlusOutlined /> <PlusOutlined />
) : ( ) : (
<Button type={'dashed'} className={'designable-btn designable-btn-dash'} icon={<SettingOutlined />}> <Button
type={'dashed'}
className={'designable-btn designable-btn-dash'}
icon={<SettingOutlined />}
>
</Button> </Button>
)} )}
@ -1326,7 +1301,12 @@ AddNew.PaneItem = observer((props: any) => {
{ghost ? ( {ghost ? (
<PlusOutlined /> <PlusOutlined />
) : ( ) : (
<Button block className={'designable-btn designable-btn-dash'} type={'dashed'} icon={<PlusOutlined />}> <Button
block
className={'designable-btn designable-btn-dash'}
type={'dashed'}
icon={<PlusOutlined />}
>
</Button> </Button>
)} )}

View File

@ -370,7 +370,7 @@ const useTableColumns = () => {
const { getField } = useCollectionContext(); const { getField } = useCollectionContext();
const operation = useTableOperation(); // const operation = useTableOperation();
const columnSchemas = schema.reduceProperties((columns, current) => { const columnSchemas = schema.reduceProperties((columns, current) => {
if (isColumn(current)) { if (isColumn(current)) {
@ -379,7 +379,7 @@ const useTableColumns = () => {
return [...columns]; return [...columns];
}, []); }, []);
const columns: any[] = [operation].concat( const columns: any[] = [].concat(
columnSchemas.map((column: Schema) => { columnSchemas.map((column: Schema) => {
const columnProps = column['x-component-props'] || {}; const columnProps = column['x-component-props'] || {};
const collectionField = getField(columnProps.fieldName); const collectionField = getField(columnProps.fieldName);
@ -905,7 +905,7 @@ function generateActionSchema(type) {
type: 'void', type: 'void',
title: '新增数据', title: '新增数据',
'x-decorator': 'Form', 'x-decorator': 'Form',
'x-component': 'Action.Modal', 'x-component': 'Action.Drawer',
'x-component-props': { 'x-component-props': {
useOkAction: '{{ Table.useTableCreateAction }}', useOkAction: '{{ Table.useTableCreateAction }}',
}, },
@ -951,14 +951,17 @@ function generateMenuActionSchema(type) {
name: uid(), name: uid(),
type: 'void', type: 'void',
title: '查看', title: '查看',
'x-component': 'Menu.Action', 'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-designable-bar': 'Table.Action.DesignableBar', 'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'view', 'x-action-type': 'view',
properties: { properties: {
[uid()]: { [uid()]: {
type: 'void', type: 'void',
title: '查看数据', title: '查看数据',
'x-component': 'Action.Modal', 'x-component': 'Action.Drawer',
'x-component-props': { 'x-component-props': {
bodyStyle: { bodyStyle: {
background: '#f0f2f5', background: '#f0f2f5',
@ -998,7 +1001,10 @@ function generateMenuActionSchema(type) {
name: uid(), name: uid(),
type: 'void', type: 'void',
title: '编辑', title: '编辑',
'x-component': 'Menu.Action', 'x-component': 'Action',
'x-component-props': {
type: 'link',
},
'x-designable-bar': 'Table.Action.DesignableBar', 'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'update', 'x-action-type': 'update',
properties: { properties: {
@ -1010,7 +1016,7 @@ function generateMenuActionSchema(type) {
useResource: '{{ Table.useResource }}', useResource: '{{ Table.useResource }}',
useValues: '{{ Table.useTableRowRecord }}', useValues: '{{ Table.useTableRowRecord }}',
}, },
'x-component': 'Action.Modal', 'x-component': 'Action.Drawer',
'x-component-props': { 'x-component-props': {
useOkAction: '{{ Table.useTableUpdateAction }}', useOkAction: '{{ Table.useTableUpdateAction }}',
}, },
@ -1031,11 +1037,12 @@ function generateMenuActionSchema(type) {
name: uid(), name: uid(),
type: 'void', type: 'void',
title: '删除', title: '删除',
'x-component': 'Menu.Action', 'x-component': 'Action',
'x-designable-bar': 'Table.Action.DesignableBar', 'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'destroy', 'x-action-type': 'destroy',
'x-component-props': { 'x-component-props': {
useAction: '{{ Table.useTableDestroyAction }}', useAction: '{{ Table.useTableDestroyAction }}',
type: 'link',
}, },
}, },
}; };
@ -1611,15 +1618,12 @@ Table.Operation.Cell = observer((props: any) => {
); );
}); });
Table.Operation.DesignableBar = (props) => { Table.Operation.DesignableBar = () => {
const { designable, schema, remove, refresh, appendChild } = useDesignable( const { schema: columnSchema } = useDesignable();
props.path, const groupSchema = Object.values(columnSchema.properties || {}).shift();
); const groupPath = getSchemaPath(groupSchema);
const { schema, remove, refresh, appendChild } = useDesignable(groupPath);
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
if (!designable || !schema?.parent?.parent['x-designable-bar']) {
return null;
}
console.log('Table.Operation.DesignableBar', schema?.parent?.parent);
const map = new Map(); const map = new Map();
schema.mapProperties((s) => { schema.mapProperties((s) => {
if (!s['x-action-type']) { if (!s['x-action-type']) {
@ -1627,6 +1631,7 @@ Table.Operation.DesignableBar = (props) => {
} }
map.set(s['x-action-type'], s.name); map.set(s['x-action-type'], s.name);
}); });
const path = getSchemaPath(schema);
return ( return (
<div className={cls('designable-bar', { active: visible })}> <div className={cls('designable-bar', { active: visible })}>
<span <span
@ -1661,10 +1666,7 @@ Table.Operation.DesignableBar = (props) => {
const data = appendChild(s); const data = appendChild(s);
await createSchema(data); await createSchema(data);
} else if (map.get(item.name)) { } else if (map.get(item.name)) {
const removed = remove([ const removed = remove([...path, map.get(item.name)]);
...props.path,
map.get(item.name),
]);
await removeSchema(removed); await removeSchema(removed);
} }
}} }}
@ -1672,7 +1674,7 @@ Table.Operation.DesignableBar = (props) => {
))} ))}
</Menu.ItemGroup> </Menu.ItemGroup>
<Menu.Divider /> <Menu.Divider />
<Menu.SubMenu title={'自定义'}> <Menu.SubMenu disabled title={'自定义'}>
<Menu.Item style={{ minWidth: 120 }}></Menu.Item> <Menu.Item style={{ minWidth: 120 }}></Menu.Item>
<Menu.Item></Menu.Item> <Menu.Item></Menu.Item>
<Menu.Item></Menu.Item> <Menu.Item></Menu.Item>
@ -1694,9 +1696,11 @@ Table.Action.DesignableBar = () => {
const { schema, remove, refresh, insertAfter } = useDesignable(); const { schema, remove, refresh, insertAfter } = useDesignable();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const isPopup = Object.keys(schema.properties || {}).length > 0; const isPopup = Object.keys(schema.properties || {}).length > 0;
const popupSchema = Object.values(schema.properties || {}).shift();
const inActionBar = schema.parent['x-component'] === 'Table.ActionBar'; const inActionBar = schema.parent['x-component'] === 'Table.ActionBar';
const displayed = useDisplayedMapContext(); const displayed = useDisplayedMapContext();
const field = useField(); const field = useField();
const popupComponent = popupSchema?.['x-component'] || 'Action.Drawer';
return ( return (
<div className={cls('designable-bar', { active: visible })}> <div className={cls('designable-bar', { active: visible })}>
<span <span
@ -1764,7 +1768,7 @@ Table.Action.DesignableBar = () => {
<Select <Select
bordered={false} bordered={false}
size={'small'} size={'small'}
defaultValue={'Action.Modal'} defaultValue={popupComponent}
onChange={(value) => { onChange={(value) => {
const s = Object.values(schema.properties).shift(); const s = Object.values(schema.properties).shift();
s['x-component'] = value; s['x-component'] = value;