feat: 1. 完善全局路由的访问权限的验证。 2. 完善接口返回的树形路由结构 3.优化评查点列表的查询,改用表连接的方式,废弃使用数据库的rpc函数,同时进行地区隔离和权限隔离。

4. 删除冗余的评查文件列表。      5.完善上传文档 页面初始化查询数据的时候 查询文件类型(改成动态指定)  6. 添加获取入口模块的查询接口。    7.完善服务端中判断token的有效性,失效则跳转到登录页。
8. 重构layout和sidebar的页面,改成由动态权限路由来渲染对应的菜单栏。       9.重构入口页面,通过动态查询根据不同地区的人返回不同的入口。
This commit is contained in:
2025-11-20 01:35:30 +08:00
parent adfb84a31d
commit 2edde8a8ab
23 changed files with 1201 additions and 2154 deletions
+122
View File
@@ -485,3 +485,125 @@ export async function getHomeData(reviewType?: string | null,userId?: string | n
}
}
/**
* 入口模块类型定义
*/
export interface EntryModule {
id: number;
name: string;
description: string | null;
path: string | null;
areas: string[];
created_at: string;
updated_at: string;
document_types?: Array<{
id: number;
name: string;
code: string | null;
}>;
}
/**
* 获取用户可访问的入口模块
* @param userArea 用户所属地区
* @param token JWT token
* @returns 入口模块列表
*/
export async function getEntryModules(userRole: string | null | undefined, userArea: string | null | undefined, token?: string): Promise<EntryModule[]> {
try {
if (!userRole || !userArea) {
console.warn('⚠️ [getEntryModules] 用户角色或地区为空,返回空模块列表');
return [];
}
// console.log('🔍 [getEntryModules] 查询地区:', userArea);
// 查询 entry_modules 表,筛选 areas 数组中包含用户地区的模块
// 使用 PostgreSQL JSONB 操作符 @> 检查数组是否包含值
const params: PostgrestParams = {
select: 'id,name,description,path,areas,created_at,updated_at',
filter: {
// areas 数组中包含用户的 area
// areas: `cs.["${userArea}"]` // cs = contains (PostgreSQL @> 操作符)
}
};
if (userRole != 'provincial_admin'){
params.filter = {
areas: `cs.["${userArea}"]`
}
}
const modulesResponse = await postgrestGet('entry_modules', { ...params, token });
if (modulesResponse.error) {
console.error('❌ [getEntryModules] 查询入口模块失败:', modulesResponse.error);
return [];
}
const modules = extractApiData<EntryModule[]>(modulesResponse.data);
if (!modules || modules.length === 0) {
console.warn('⚠️ [getEntryModules] 未找到匹配的入口模块');
return [];
}
console.log(`✅ [getEntryModules] 找到 ${modules.length} 个入口模块`);
// 为每个模块查询关联的 document_types
const modulesWithTypes = await Promise.all(
modules.map(async (module) => {
try {
const typesParams: PostgrestParams = {
select: 'id,name,code',
filter: {
entry_module_id: `eq.${module.id}`
}
};
const typesResponse = await postgrestGet('document_types', { ...typesParams, token });
if (typesResponse.error) {
console.error(`❌ [getEntryModules] 查询模块 ${module.id} 的文档类型失败:`, typesResponse.error);
return { ...module, document_types: [] };
}
const documentTypes = extractApiData<Array<{ id: number; name: string; code: string | null }>>(typesResponse.data);
return {
...module,
document_types: documentTypes || []
};
} catch (error) {
console.error(`❌ [getEntryModules] 处理模块 ${module.id} 时出错:`, error);
return { ...module, document_types: [] };
}
})
);
console.log('✅ [getEntryModules] 入口模块数据(含文档类型):', JSON.stringify(modulesWithTypes));
// 默认会多加一个 智慧法务大模型 入口 默认所有人都可以用,看到
modulesWithTypes.push({
"id": 0,
"name": "智慧法务大模型",
"description": "智慧法务大模型",
"path": "entryModule/assistant",
"areas": [],
"created_at": "2025-11-18T21:33:33.857417+08:00",
"updated_at": "2025-11-18T22:28:51.819722+08:00",
"document_types": [
{
"id": 0,
"name": "空",
"code": "空"
}
]
})
return modulesWithTypes;
} catch (error) {
console.error('❌ [getEntryModules] 获取入口模块失败:', error instanceof Error ? error.message : String(error));
return [];
}
}