tachybase_todo/packages/client/src/acl/ACLShortcut.tsx

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-19 15:14:00 +08:00
import { LockOutlined } from '@ant-design/icons';
import { ISchema, useForm } from '@formily/react';
2022-01-30 19:28:42 +08:00
import { uid } from '@formily/shared';
import React, { useState } from 'react';
import { PluginManager } from '../plugin-manager';
2022-01-30 19:28:42 +08:00
import { SchemaComponent, useActionVisible, VisibleContext } from '../schema-component';
import { RoleTable } from './RolePermissionManager';
2022-01-19 15:14:00 +08:00
const useCloseAction = () => {
const { setVisible } = useActionVisible();
const form = useForm();
return {
async run() {
setVisible(false);
form.submit((values) => {
console.log(values);
});
},
};
};
const schema: ISchema = {
type: 'object',
properties: {
2022-01-30 19:28:42 +08:00
[uid()]: {
2022-01-19 15:14:00 +08:00
'x-component': 'Action.Drawer',
type: 'void',
title: 'Drawer Title',
properties: {
hello1: {
type: 'void',
2022-01-30 19:28:42 +08:00
'x-component': 'RoleTable',
2022-01-19 15:14:00 +08:00
},
2022-01-30 19:28:42 +08:00
// footer1: {
// 'x-component': 'Action.Drawer.Footer',
// type: 'void',
// properties: {
// close1: {
// title: 'Close',
// 'x-component': 'Action',
// 'x-component-props': {
// useAction: '{{ useCloseAction }}',
// },
// },
// },
// },
2022-01-19 15:14:00 +08:00
},
},
},
};
export const ACLShortcut = () => {
2022-01-19 15:14:00 +08:00
const [visible, setVisible] = useState(false);
return (
<VisibleContext.Provider value={[visible, setVisible]}>
<PluginManager.Toolbar.Item
icon={<LockOutlined />}
title={'角色和权限'}
2022-01-19 15:14:00 +08:00
onClick={() => {
setVisible(true);
}}
/>
2022-01-30 19:28:42 +08:00
<SchemaComponent components={{ RoleTable }} scope={{ useCloseAction }} schema={schema} />
2022-01-19 15:14:00 +08:00
</VisibleContext.Provider>
);
};