多租户与景区关系
This commit is contained in:
@@ -4,30 +4,22 @@ 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 { tenantApi } from '@/services/tenant';
|
||||
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 [params, setParams] = useState<{ tenantId?: string; includeChildren?: boolean; 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 }));
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
// 以租户为主:通过 SearchBarPlus 内置租户选择器
|
||||
|
||||
const columns = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '租户', dataIndex: 'tenantId', width: 160, search: false, render: (_: any, r: RoleItem) => (r as any)?.tenantName || (r as any)?.tenantId || '-' },
|
||||
{ title: 'ID', dataIndex: 'id' },
|
||||
{ title: '角色名称', dataIndex: 'name' },
|
||||
{ title: '编码', dataIndex: 'code' },
|
||||
@@ -54,16 +46,37 @@ const RolePage: React.FC = () => {
|
||||
}
|
||||
];
|
||||
|
||||
// 页面初次进入时,自动获取当前租户并触发表格请求
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
let tenantId: string | undefined;
|
||||
const cur: any = await tenantApi.getCurrentTenant();
|
||||
tenantId = cur?.data?.tenantId ?? cur?.tenantId;
|
||||
if (!tenantId) {
|
||||
const stats: any = await tenantApi.getScopeStats();
|
||||
tenantId = stats?.data?.currentTenantId ?? stats?.currentTenantId;
|
||||
}
|
||||
if (tenantId) {
|
||||
setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren: true }));
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误,保持手动查询可用
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '角色管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={6}
|
||||
onTenantChanged={() => { /* 切换租户后服务端上下文生效 */ }}
|
||||
onTenantChanged={(tenantId, includeChildren) => {
|
||||
setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren }));
|
||||
}}
|
||||
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>
|
||||
@@ -80,6 +93,7 @@ const RolePage: React.FC = () => {
|
||||
<ProTable<RoleItem>
|
||||
rowKey="id"
|
||||
headerTitle="角色列表"
|
||||
params={params}
|
||||
request={async (p) => roleApi.page({ ...p, ...params })}
|
||||
columns={columns as any}
|
||||
search={false}
|
||||
@@ -134,4 +148,3 @@ const RolePage: React.FC = () => {
|
||||
};
|
||||
|
||||
export default RolePage;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user