fix: tighten entry module rbac flows
This commit is contained in:
@@ -46,6 +46,7 @@ interface LoaderData {
|
||||
pageSize: number;
|
||||
currentPage: number;
|
||||
error?: string;
|
||||
accessDenied?: boolean;
|
||||
}
|
||||
|
||||
function resolveModuleLogoUrl(path?: string | null): string | null {
|
||||
@@ -92,16 +93,19 @@ export async function clientLoader({ request }: ClientLoaderFunctionArgs) {
|
||||
modules: modulesResult,
|
||||
total: totalCount,
|
||||
pageSize,
|
||||
currentPage: page
|
||||
currentPage: page,
|
||||
accessDenied: false,
|
||||
};
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "加载入口模块列表失败";
|
||||
console.error("加载入口模块列表失败:", error);
|
||||
return {
|
||||
modules: [],
|
||||
total: 0,
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
error: error instanceof Error ? error.message : "加载入口模块列表失败"
|
||||
error: errorMessage,
|
||||
accessDenied: errorMessage.includes('无权限') || errorMessage.includes('权限') || errorMessage.includes('403'),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -127,7 +131,7 @@ export default function EntryModulesList() {
|
||||
|
||||
// 获取加载器数据
|
||||
const loaderData = useLoaderData<LoaderData>();
|
||||
const { modules, total, error } = loaderData;
|
||||
const { modules, total, error, accessDenied } = loaderData;
|
||||
|
||||
// ✅ 使用权限 Hook
|
||||
const { canCreate, canUpdate, canDelete, canView } = usePermission();
|
||||
@@ -145,9 +149,13 @@ export default function EntryModulesList() {
|
||||
// 处理loader加载数据的时候的错误
|
||||
useEffect(() => {
|
||||
if (error) {
|
||||
if (accessDenied) {
|
||||
toastService.warning('您当前只有入口模块页面可见权限,没有列表读取权限');
|
||||
return;
|
||||
}
|
||||
toastService.error(error);
|
||||
}
|
||||
}, [error]);
|
||||
}, [error, accessDenied]);
|
||||
|
||||
// 处理名称搜索
|
||||
const handleNameSearch = (value: string) => {
|
||||
@@ -413,17 +421,30 @@ export default function EntryModulesList() {
|
||||
/>
|
||||
</FilterPanel>
|
||||
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={modules || []}
|
||||
rowKey="id"
|
||||
loading={false}
|
||||
emptyText="暂无入口模块数据"
|
||||
/>
|
||||
{accessDenied ? (
|
||||
<div className="empty-state" style={{ padding: '64px 24px', textAlign: 'center' }}>
|
||||
<div style={{ fontSize: 40, color: '#faad14', marginBottom: 12 }}>
|
||||
<i className="ri-lock-line"></i>
|
||||
</div>
|
||||
<div style={{ fontSize: 18, fontWeight: 600, color: '#1f2937', marginBottom: 8 }}>
|
||||
当前账号没有入口模块列表权限
|
||||
</div>
|
||||
<div style={{ fontSize: 14, color: '#6b7280' }}>
|
||||
请在“角色权限管理”中为当前角色授予 `entry_module:list:read` 及相关权限后再访问。
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={modules || []}
|
||||
rowKey="id"
|
||||
loading={false}
|
||||
emptyText="暂无入口模块数据"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 分页 */}
|
||||
{total > 0 && (
|
||||
{!accessDenied && total > 0 && (
|
||||
<Pagination
|
||||
// pageSizeOptions={[10,20]}
|
||||
currentPage={currentPage}
|
||||
|
||||
Reference in New Issue
Block a user