feat: 1. 完善全局路由的访问权限的验证。 2. 完善接口返回的树形路由结构 3.优化评查点列表的查询,改用表连接的方式,废弃使用数据库的rpc函数,同时进行地区隔离和权限隔离。
4. 删除冗余的评查文件列表。 5.完善上传文档 页面初始化查询数据的时候 查询文件类型(改成动态指定) 6. 添加获取入口模块的查询接口。 7.完善服务端中判断token的有效性,失效则跳转到登录页。 8. 重构layout和sidebar的页面,改成由动态权限路由来渲染对应的菜单栏。 9.重构入口页面,通过动态查询根据不同地区的人返回不同的入口。
This commit is contained in:
+70
-154
@@ -12,9 +12,9 @@ function extractApiData<T>(responseData: unknown): T | null {
|
||||
if (!responseData) return null;
|
||||
|
||||
// 格式1: { code: number, msg: string, data: T }
|
||||
if (typeof responseData === 'object' && responseData !== null &&
|
||||
'code' in responseData &&
|
||||
'data' in responseData &&
|
||||
if (typeof responseData === 'object' && responseData !== null &&
|
||||
'code' in responseData &&
|
||||
'data' in responseData &&
|
||||
(responseData as { data: unknown }).data) {
|
||||
return (responseData as { data: T }).data;
|
||||
}
|
||||
@@ -23,6 +23,34 @@ function extractApiData<T>(responseData: unknown): T | null {
|
||||
return responseData as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 sessionStorage 获取文档类型 ID 列表(客户端专用)
|
||||
* @returns 文档类型 ID 数组,如果不存在则返回 null
|
||||
*/
|
||||
function getDocumentTypeIdsFromSession(): number[] | null {
|
||||
if (typeof window === 'undefined') {
|
||||
return null; // 服务端环境返回 null
|
||||
}
|
||||
|
||||
try {
|
||||
const typeIdsStr = sessionStorage.getItem('documentTypeIds');
|
||||
if (!typeIdsStr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const typeIds = JSON.parse(typeIdsStr);
|
||||
if (Array.isArray(typeIds) && typeIds.every(id => typeof id === 'number')) {
|
||||
return typeIds;
|
||||
}
|
||||
|
||||
console.warn('⚠️ [getDocumentTypeIds] documentTypeIds 格式不正确:', typeIds);
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('❌ [getDocumentTypeIds] 解析 documentTypeIds 失败:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 文档状态枚举
|
||||
export enum DocumentStatus {
|
||||
waiting = 'waiting',
|
||||
@@ -226,6 +254,7 @@ export async function uploadContractTemplate(
|
||||
* @param mergeMode 合并模式:'overwrite'(覆盖原文档)或 'new'(新建文档记录)
|
||||
* @param isReprocess 是否触发重新处理
|
||||
* @param remark 备注
|
||||
* @param token JWT token(可选)
|
||||
* @returns 上传结果
|
||||
*/
|
||||
export async function appendContractAttachments(
|
||||
@@ -233,7 +262,8 @@ export async function appendContractAttachments(
|
||||
files: File[],
|
||||
mergeMode: 'overwrite' | 'new' = 'overwrite',
|
||||
isReprocess: boolean = true,
|
||||
remark?: string
|
||||
remark?: string,
|
||||
token?: string
|
||||
): Promise<{data: FileUploadResponse; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
console.log('【合同附件追加】开始追加附件:', { documentId, fileCount: files.length, mergeMode });
|
||||
@@ -256,20 +286,18 @@ export async function appendContractAttachments(
|
||||
// 构建请求URL
|
||||
const uploadUrl = `${UPLOAD_URL}/contracts/${documentId}/append_attachments`;
|
||||
console.log('【合同附件追加】准备发送请求到服务器:', uploadUrl);
|
||||
|
||||
|
||||
// 设置请求头
|
||||
const headers: HeadersInit = {
|
||||
'Accept': 'application/json'
|
||||
};
|
||||
|
||||
// 从 localStorage 获取 token
|
||||
if (typeof window !== 'undefined') {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
// 使用传入的 token 或从 localStorage 获取
|
||||
const authToken = token || (typeof window !== 'undefined' ? localStorage.getItem('access_token') : null);
|
||||
if (authToken) {
|
||||
headers['Authorization'] = `Bearer ${authToken}`;
|
||||
}
|
||||
|
||||
|
||||
// 发送请求
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
@@ -440,10 +468,15 @@ export async function uploadDocumentToServer(
|
||||
/**
|
||||
* 获取当天的文档列表
|
||||
* @param userInfo 用户信息(必需)
|
||||
* @param reviewType 审核类型(可选)
|
||||
* @param token JWT token
|
||||
* @param documentTypeIds 文档类型 ID 列表(可选)
|
||||
* @returns 文档列表
|
||||
*/
|
||||
export async function getTodayDocuments(userInfo?: { user_id?: number; [key: string]: unknown }, reviewType?: string, token?: string): Promise<{data: Document[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getTodayDocuments(
|
||||
userInfo?: { user_id?: number; [key: string]: unknown },
|
||||
token?: string,
|
||||
documentTypeIds?: number[]
|
||||
): Promise<{data: Document[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
// 检查用户信息是否存在
|
||||
if (!userInfo?.user_id) {
|
||||
@@ -455,129 +488,11 @@ export async function getTodayDocuments(userInfo?: { user_id?: number; [key: str
|
||||
|
||||
const today = dayjs().startOf('day').format('YYYY-MM-DD');
|
||||
// console.log('查询当天文档,日期范围:', today);
|
||||
|
||||
// 如果是合同类型,需要合并查询documents表和contract_structure_comparison表
|
||||
if (reviewType === 'contract') {
|
||||
try {
|
||||
// 查询documents表中的合同数据
|
||||
const documentsParams: PostgrestParams = {
|
||||
select: `
|
||||
id,
|
||||
name,
|
||||
type_id,
|
||||
file_size,
|
||||
status,
|
||||
created_at,
|
||||
document_number,
|
||||
path,
|
||||
storage_type,
|
||||
is_test_document,
|
||||
evaluation_level,
|
||||
ocr_result,
|
||||
extracted_results,
|
||||
sumary,
|
||||
remark,
|
||||
audit_status
|
||||
`,
|
||||
order: 'created_at.desc',
|
||||
filter: {
|
||||
'created_at': `gte.${today}`,
|
||||
'type_id': 'eq.1',
|
||||
'user_id': `eq.${userInfo.user_id}`
|
||||
}
|
||||
};
|
||||
|
||||
// 🔑 优先使用传入的 documentTypeIds,否则从 sessionStorage 读取(客户端)
|
||||
const typeIds = documentTypeIds || getDocumentTypeIdsFromSession();
|
||||
// console.log('📋 [getTodayDocuments] 文档类型 IDs:', typeIds, '来源:', documentTypeIds ? 'URL参数' : 'sessionStorage');
|
||||
|
||||
// 查询contract_structure_comparison表中的数据
|
||||
// const comparisonParams: PostgrestParams = {
|
||||
// select: `
|
||||
// id,
|
||||
// template_contract_name,
|
||||
// file_size,
|
||||
// status,
|
||||
// created_at,
|
||||
// document_id,
|
||||
// template_contract_path,
|
||||
// ocr_results,
|
||||
// comparison_results
|
||||
// `,
|
||||
// order: 'created_at.desc',
|
||||
// filter: {
|
||||
// 'created_at': `gte.${today}`
|
||||
// }
|
||||
// };
|
||||
|
||||
// 并行查询两个表
|
||||
// const [documentsResponse, comparisonResponse] = await Promise.all([
|
||||
// postgrestGet<Document[]>('documents', documentsParams),
|
||||
// postgrestGet<ContractStructureComparison[]>('contract_structure_comparison', comparisonParams)
|
||||
// ]);
|
||||
|
||||
const documentsResponse = await postgrestGet<Document[]>('documents', { ...documentsParams, token });
|
||||
|
||||
// console.log('documents表响应:', documentsResponse);
|
||||
// console.log('contract_structure_comparison表响应:', comparisonResponse);
|
||||
|
||||
// if (documentsResponse.error && comparisonResponse.error) {
|
||||
// console.error('两个表查询都失败:', documentsResponse.error, comparisonResponse.error);
|
||||
// return { error: documentsResponse.error || comparisonResponse.error, status: documentsResponse.status || comparisonResponse.status };
|
||||
// }
|
||||
if (documentsResponse.error) {
|
||||
console.error('documents表查询失败:', documentsResponse.error);
|
||||
return { error: documentsResponse.error, status: documentsResponse.status };
|
||||
}
|
||||
|
||||
// 提取documents表数据
|
||||
let documentsData: Document[] = [];
|
||||
if (!documentsResponse.error && documentsResponse.data) {
|
||||
const extractedDocuments = extractApiData<Document[]>(documentsResponse.data);
|
||||
if (extractedDocuments) {
|
||||
documentsData = extractedDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
// 提取contract_structure_comparison表数据并转换为Document格式
|
||||
// let comparisonData: Document[] = [];
|
||||
// if (!comparisonResponse.error && comparisonResponse.data) {
|
||||
// const extractedComparison = extractApiData<ContractStructureComparison[]>(comparisonResponse.data);
|
||||
// if (extractedComparison) {
|
||||
// // 将ContractStructureComparison转换为Document格式
|
||||
// console.log('extractedComparison:', extractedComparison);
|
||||
// comparisonData = extractedComparison.map(item => ({
|
||||
// id: item.id,
|
||||
// name: item.template_contract_name || `合同结构比较记录_${item.id}`,
|
||||
// type_id: 1, // 合同结构比较默认为合同类型
|
||||
// file_size: item.file_size || 0,
|
||||
// status: item.status,
|
||||
// created_at: item.created_at,
|
||||
// document_id: item.document_id,
|
||||
// template_contract_path: item.template_contract_path,
|
||||
// ocr_results: item.ocr_results,
|
||||
// comparison_results: item.comparison_results
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
|
||||
// 合并两个数据源
|
||||
// const allData = [...documentsData, ...comparisonData];
|
||||
const allData = [...documentsData];
|
||||
|
||||
// 按created_at降序排序
|
||||
allData.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
|
||||
// console.log('合并后的数据:', allData);
|
||||
return { data: allData };
|
||||
|
||||
} catch (contractError) {
|
||||
console.error('合同类型查询失败:', contractError);
|
||||
return {
|
||||
error: contractError instanceof Error ? contractError.message : '合同类型查询失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 非合同类型的原有逻辑
|
||||
const params: PostgrestParams = {
|
||||
select: `
|
||||
id,
|
||||
@@ -604,14 +519,16 @@ export async function getTodayDocuments(userInfo?: { user_id?: number; [key: str
|
||||
}
|
||||
};
|
||||
|
||||
// 根据reviewType添加过滤条件
|
||||
if (reviewType === 'record') {
|
||||
// 如果是卷宗类型,只显示type_id=2或type_id=3的文档
|
||||
// 🔑 根据 documentTypeIds 添加过滤条件
|
||||
if (typeIds && typeIds.length > 0) {
|
||||
// 使用动态的文档类型 ID 列表
|
||||
const typeIdsStr = typeIds.join(',');
|
||||
if (params.filter) {
|
||||
params.filter['type_id'] = 'in.(2,3,155)';
|
||||
params.filter['type_id'] = `in.(${typeIdsStr})`;
|
||||
} else {
|
||||
params.filter = { 'type_id': 'in.(2,3,155)' };
|
||||
params.filter = { 'type_id': `in.(${typeIdsStr})` };
|
||||
}
|
||||
console.log('📋 [getTodayDocuments] 使用文档类型 IDs 查询:', typeIdsStr);
|
||||
}
|
||||
|
||||
// console.log('发送请求参数:', params);
|
||||
@@ -643,33 +560,32 @@ export async function getTodayDocuments(userInfo?: { user_id?: number; [key: str
|
||||
|
||||
/**
|
||||
* 获取文档类型列表
|
||||
* @param reviewType 审核类型(可选)
|
||||
* @param token JWT token (可选)
|
||||
* @returns 文档类型列表
|
||||
*/
|
||||
export async function getDocumentTypes(reviewType?: string, token?: string): Promise<{data: DocumentType[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
export async function getDocumentTypes(token?: string): Promise<{data: DocumentType[]; error?: never} | {data?: never; error: string; status?: number}> {
|
||||
try {
|
||||
const params: PostgrestParams = {
|
||||
select: 'id, name',
|
||||
filter: {} // 初始化为空对象
|
||||
};
|
||||
|
||||
// 根据reviewType添加过滤条件
|
||||
if (reviewType === 'contract') {
|
||||
// 如果是合同类型,只显示id=1的文档类型
|
||||
// 🔑 从 sessionStorage 获取文档类型 ID 列表(动态方式)
|
||||
const documentTypeIds = getDocumentTypeIdsFromSession();
|
||||
// console.log('📋 [getDocumentTypes] 文档类型 IDs:', documentTypeIds);
|
||||
|
||||
// 根据 documentTypeIds 添加过滤条件
|
||||
if (documentTypeIds && documentTypeIds.length > 0) {
|
||||
// 使用动态的文档类型 ID 列表
|
||||
const typeIdsStr = documentTypeIds.join(',');
|
||||
if (params.filter) {
|
||||
params.filter['id'] = 'eq.1';
|
||||
params.filter['id'] = `in.(${typeIdsStr})`;
|
||||
} else {
|
||||
params.filter = { 'id': 'eq.1' };
|
||||
}
|
||||
} else if (reviewType === 'record') {
|
||||
// 如果是卷宗类型,只显示id=2或id=3的文档类型
|
||||
if (params.filter) {
|
||||
params.filter['id'] = 'in.(2,3,155)';
|
||||
} else {
|
||||
params.filter = { 'id': 'in.(2,3,155)' };
|
||||
params.filter = { 'id': `in.(${typeIdsStr})` };
|
||||
}
|
||||
console.log('📋 [getDocumentTypes] 使用动态类型 IDs 查询:', typeIdsStr);
|
||||
}
|
||||
// 如果没有 documentTypeIds,返回所有文档类型(不添加过滤条件)
|
||||
|
||||
const response = await postgrestGet<DocumentType[]>('document_types', { ...params, token });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user