From 1ab7d544b3dc44f2984ca61763f6bae057ec2edb Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 7 Aug 2021 23:22:30 +0800 Subject: [PATCH] feat: add ActionLogs block --- packages/api/src/app.ts | 3 +- packages/client/src/schemas/add-new/index.tsx | 176 +++++++++++++++++- packages/client/src/schemas/table/index.tsx | 18 +- packages/client/src/schemas/tabs/index.tsx | 2 +- 4 files changed, 187 insertions(+), 12 deletions(-) diff --git a/packages/api/src/app.ts b/packages/api/src/app.ts index 4f5681381..f73ae28dd 100644 --- a/packages/api/src/app.ts +++ b/packages/api/src/app.ts @@ -41,9 +41,8 @@ const plugins = [ '@nocobase/plugin-collections', '@nocobase/plugin-ui-router', '@nocobase/plugin-ui-schema', - // '@nocobase/plugin-action-logs', - // '@nocobase/plugin-pages', '@nocobase/plugin-users', + '@nocobase/plugin-action-logs', // '@nocobase/plugin-file-manager', // '@nocobase/plugin-permissions', // '@nocobase/plugin-automations', diff --git a/packages/client/src/schemas/add-new/index.tsx b/packages/client/src/schemas/add-new/index.tsx index b9bfd8a5d..5d5dda74d 100644 --- a/packages/client/src/schemas/add-new/index.tsx +++ b/packages/client/src/schemas/add-new/index.tsx @@ -384,6 +384,150 @@ function generateCardItemSchema(component) { config: cloneDeep(barChartConfig), }, }, + 'Ref.ActionLogs': { + type: 'array', + name: 'table', + 'x-decorator': 'CardItem', + 'x-component': 'Table', + default: [], + 'x-component-props': { + useResource: '{{ Table.useActionLogsResource }}', + collectionName: 'action_logs', + rowKey: 'id', + // dragSort: true, + showIndex: true, + refreshRequestOnChange: true, + pagination: { + pageSize: 10, + }, + }, + properties: { + [uid()]: { + type: 'void', + 'x-component': 'Table.ActionBar', + properties: { + [uid()]: { + type: 'void', + title: '筛选', + 'x-align': 'left', + 'x-component': 'Table.Filter', + 'x-component-props': { + fieldNames: [], + }, + }, + }, + }, + [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-component': 'Action.Drawer', + 'x-component-props': { + bodyStyle: { + background: '#f0f2f5', + // paddingTop: 0, + }, + }, + properties: { + [uid()]: { + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': { + singleton: true, + }, + properties: { + [uid()]: { + type: 'void', + title: '详情', + 'x-component': 'Tabs.TabPane', + 'x-component-props': {}, + properties: { + [uid()]: { + type: 'void', + 'x-component': 'Grid', + 'x-component-props': { + // addNewComponent: 'AddNew.PaneItem', + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + column1: { + type: 'void', + title: '创建时间', + 'x-component': 'Table.Column', + properties: { + created_at: { + type: 'string', + 'x-component': 'DatePicker', + 'x-read-pretty': true, + 'x-component-props': { + format: 'YYYY-MM-DD HH:mm:ss', + }, + }, + }, + }, + column2: { + type: 'void', + title: '操作类型', + 'x-component': 'Table.Column', + properties: { + type: { + type: 'string', + 'x-component': 'Select', + 'x-read-pretty': true, + enum: [ + { label: '新增数据', value: 'create' }, + { label: '更新数据', value: 'update' }, + { label: '删除数据', value: 'destroy' }, + ], + }, + }, + }, + }, + }, }; return defaults[component]; } @@ -602,12 +746,12 @@ AddNew.CardItem = observer((props: any) => { - + - 模板1 + 操作日志 - 新建模板 + 新建模板 } @@ -934,12 +1078,34 @@ AddNew.PaneItem = observer((props: any) => { } + onClick={async () => { + let data: ISchema = generateCardItemSchema('Ref.ActionLogs'); + if (isGridBlock(schema)) { + path.pop(); + path.pop(); + data = generateGridBlock(data); + } else if (isGrid(schema)) { + data = generateGridBlock(data); + } + if (data) { + let s; + if (isGrid(schema)) { + s = appendChild(data, [...path]); + } else if (defaultAction === 'insertAfter') { + s = insertAfter(data, [...path]); + } else { + s = insertBefore(data, [...path]); + } + await createSchema(s); + } + setVisible(false); + }} > 日志 - }> + {/* }> 评论 - + */} { }), ); - if (designable) { + if (designable && schema['x-designable-bar']) { columns.push({ title: , dataIndex: 'addnew', @@ -972,7 +972,7 @@ function AddActionButton() { const displayed = useDisplayedMapContext(); const { appendChild, remove } = useDesignable(); const { schema, designable } = useDesignable(); - if (!designable) { + if (!designable || !schema['x-designable-bar']) { return null; } return ( @@ -1385,12 +1385,14 @@ Table.Filter.DesignableBar = () => { }; Table.Operation = observer((props: any) => { - const { designable } = useDesignable(); + const { designable, schema } = useDesignable(); const [visible, setVisible] = useState(false); return (
操作 - {designable && } + {designable && schema['x-designable-bar'] && ( + + )}
); }); @@ -2035,6 +2037,14 @@ Table.useResource = ({ onSuccess }) => { return { resource, service, initialValues: service.data, ...service }; }; +const useActionLogsResource = (options: any = {}) => { + const resource = Resource.make('action_logs'); + return { + resource, + }; +}; + +Table.useActionLogsResource = useActionLogsResource; Table.useTableFilterAction = useTableFilterAction; Table.useTableCreateAction = useTableCreateAction; Table.useTableUpdateAction = useTableUpdateAction; diff --git a/packages/client/src/schemas/tabs/index.tsx b/packages/client/src/schemas/tabs/index.tsx index f9db03326..8e10b65e9 100644 --- a/packages/client/src/schemas/tabs/index.tsx +++ b/packages/client/src/schemas/tabs/index.tsx @@ -104,7 +104,7 @@ export const Tabs: any = observer((props: any) => { {...others} className={cls({ singleton })} tabBarExtraContent={ - designable && ( + designable && schema['x-designable-bar'] && (