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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user