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

54 lines
1.3 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-02-10 12:06:48 +08:00
import { ActionContext, SchemaComponent, useActionContext } from '../schema-component';
2022-02-17 01:06:42 +08:00
import * as components from './Configuration';
2022-01-19 15:14:00 +08:00
const useCloseAction = () => {
2022-02-10 12:06:48 +08:00
const { setVisible } = useActionContext();
2022-01-19 15:14:00 +08:00
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: '角色配置',
2022-01-19 15:14:00 +08:00
properties: {
hello1: {
type: 'void',
2022-01-30 19:28:42 +08:00
'x-component': 'RoleTable',
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 (
2022-02-10 12:06:48 +08:00
<ActionContext.Provider value={{ visible, setVisible }}>
<PluginManager.Toolbar.Item
icon={<LockOutlined />}
title={'角色和权限'}
2022-01-19 15:14:00 +08:00
onClick={() => {
setVisible(true);
}}
/>
2022-02-17 01:06:42 +08:00
<SchemaComponent components={components} scope={{ useCloseAction }} schema={schema} />
2022-02-10 12:06:48 +08:00
</ActionContext.Provider>
2022-01-19 15:14:00 +08:00
);
};