feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Modal, Tree, message } from 'antd';
|
||||
import { roleApi } from '@/services/role';
|
||||
import { buildTree } from '@/utils/tree';
|
||||
|
||||
type Key = string | number;
|
||||
|
||||
export interface AssignAuthProps {
|
||||
roleId?: number;
|
||||
tenantId?: string;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const AssignAuth: React.FC<AssignAuthProps> = ({ roleId, tenantId, open, onClose }) => {
|
||||
const [treeData, setTreeData] = useState<any[]>([]);
|
||||
const [checkedKeys, setCheckedKeys] = useState<Key[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (open && roleId && tenantId) {
|
||||
const menus = await roleApi.menuForAuth(roleId, tenantId);
|
||||
const nodes = menus.map((m: any) => ({ id: m.id, pId: m.pId, title: m.name, name: m.name }));
|
||||
setTreeData(buildTree(nodes));
|
||||
setCheckedKeys(menus.filter((m: any) => m.checked).map((m: any) => m.id));
|
||||
}
|
||||
})();
|
||||
}, [open, roleId, tenantId]);
|
||||
|
||||
const handleOk = async () => {
|
||||
if (!roleId) return;
|
||||
const hide = message.loading('淇濆瓨涓?..');
|
||||
try {
|
||||
await roleApi.assignMenu({ roleId, menuIds: checkedKeys });
|
||||
message.success('鏉冮檺鍒嗛厤鎴愬姛');
|
||||
onClose();
|
||||
} catch (e) {
|
||||
message.error('鏉冮檺鍒嗛厤澶辫触');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal title="鏉冮檺鍒嗛厤" open={open} destroyOnClose onOk={handleOk} onCancel={onClose}>
|
||||
<Tree
|
||||
defaultExpandAll
|
||||
checkable
|
||||
treeData={treeData}
|
||||
checkedKeys={checkedKeys}
|
||||
onCheck={(keys: any) => setCheckedKeys(Array.isArray(keys) ? keys : keys.checked)}
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssignAuth;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import { ModalForm, ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components';
|
||||
import { RoleItem } from '@/services/role';
|
||||
|
||||
export interface RoleFormProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
initialValues?: Partial<RoleItem>;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
onFinish: (values: RoleItem) => Promise<boolean>;
|
||||
}
|
||||
|
||||
const RoleForm: React.FC<RoleFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
|
||||
return (
|
||||
<ModalForm<RoleItem>
|
||||
title={title}
|
||||
visible={open}
|
||||
onVisibleChange={onOpenChange}
|
||||
onFinish={onFinish}
|
||||
initialValues={initialValues ?? { dataScope: 'ALL' }}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
width={500}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText name="name" label="角色名称" rules={[{ required: true, message: '角色名不能为空' }]} width="lg" />
|
||||
<ProFormText name="code" label="编码" rules={[{ required: true, message: '编码不能为空' }]} width="lg" />
|
||||
<ProFormRadio.Group
|
||||
name="dataScope"
|
||||
label="数据权限"
|
||||
width="lg"
|
||||
options={[{ label: '全部', value: 'ALL' }, { label: '本人', value: 'CREATOR' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default RoleForm;
|
||||
Reference in New Issue
Block a user