feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { PageContainer, ProTable, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import { Popconfirm, Space, message } from 'antd';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { roleApi, RoleItem } from '@/services/role';
|
||||
import RoleForm from './components/RoleForm';
|
||||
import AssignAuth from './components/AssignAuth';
|
||||
|
||||
const RolePage: React.FC = () => {
|
||||
const [apps, setApps] = useState<any[]>([]);
|
||||
const [params, setParams] = useState<{ tenantId?: string; searchKey?: string; searchValue?: string }>({});
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [assignOpen, setAssignOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<RoleItem | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const list = await roleApi.apps();
|
||||
setApps(list || []);
|
||||
if (list?.length) {
|
||||
const tenantId = list[0].clientId;
|
||||
setParams((p) => ({ ...p, tenantId }));
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const columns = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: 'ID', dataIndex: 'id' },
|
||||
{ title: '角色名称', dataIndex: 'name' },
|
||||
{ title: '编码', dataIndex: 'code' },
|
||||
{ title: '数据权限', dataIndex: 'dataScope', renderText: (v: any) => (v === 'ALL' ? '全部' : '自定义') },
|
||||
{
|
||||
title: '操作', valueType: 'option', width: 220,
|
||||
render: (_: any, record: RoleItem) => (
|
||||
<Space>
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||
<a onClick={() => { setCurrent(record); setAssignOpen(true); }}>授权</a>
|
||||
<Popconfirm title={`确认删除角色[${record.name}]?`} onConfirm={async () => {
|
||||
const hide = message.loading('删除中...');
|
||||
try {
|
||||
await roleApi.delete(record.id!);
|
||||
message.success('删除成功');
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
} finally { hide(); }
|
||||
}}>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '角色管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={6}
|
||||
onTenantChanged={() => { /* 切换租户后服务端上下文生效 */ }}
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormSelect name="tenantId" label="所属应用" allowClear={false} options={(apps || []).map((i) => ({ label: i.clientId, value: i.clientId }))} />
|
||||
<ProFormSelect name="searchKey" label="搜索" valueEnum={{ name: '角色名称' }} />
|
||||
<ProFormText name="searchValue" placeholder="请输入关键字" />
|
||||
</SearchBarPlus>
|
||||
|
||||
<ActionBar
|
||||
left={
|
||||
<GradientButton size="middle" key="add" type="primary" onClick={() => setCreateOpen(true)}>
|
||||
<PlusOutlined /> 新增
|
||||
</GradientButton>
|
||||
}
|
||||
/>
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<RoleItem>
|
||||
rowKey="id"
|
||||
headerTitle="角色列表"
|
||||
request={async (p) => roleApi.page({ ...p, ...params })}
|
||||
columns={columns as any}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
toolBarRender={false}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<RoleForm
|
||||
title="新增角色"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await roleApi.saveOrUpdate(values);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
|
||||
<RoleForm
|
||||
title="修改角色"
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await roleApi.saveOrUpdate({ ...current, ...values });
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
|
||||
<AssignAuth
|
||||
open={assignOpen}
|
||||
roleId={current?.id}
|
||||
tenantId={params.tenantId}
|
||||
onClose={() => setAssignOpen(false)}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default RolePage;
|
||||
|
||||
Reference in New Issue
Block a user