fix: 1. 继续对齐交叉评查的接口,完善创建交叉评查的逻辑 和 相关组件的渲染布局。
2. 文档的基本信息修改改用接口。 3. 重新完善角色权限管理的页面逻辑。 4.将评查点列表中的返回逻辑改用浏览器的记忆返回。
This commit is contained in:
+46
-28
@@ -431,9 +431,17 @@ export async function getDocumentTypesByIds(ids: number[], frontendJWT?: string)
|
||||
|
||||
/**
|
||||
* 更新文档信息
|
||||
*
|
||||
* 使用 PATCH 方法调用 /api/postgrest/proxy/documents 接口
|
||||
* 后端会自动注入 user_id 过滤条件,确保用户只能更新自己的文档
|
||||
*
|
||||
* @param id 文档ID
|
||||
* @param document 部分文档数据
|
||||
* @param document 部分文档数据(可更新字段:document_number, audit_status, is_test_document, remark)
|
||||
* @param userId 用户ID(用于权限验证)
|
||||
* @param frontendJWT JWT Token(可选,如不传则使用 localStorage 中的 access_token)
|
||||
* @returns 更新结果
|
||||
*
|
||||
* @see auth_doc/document_update_api.md 接口文档
|
||||
*/
|
||||
export async function updateDocument(id: string, document: Partial<DocumentUI> & { remark?: string }, userId: string, frontendJWT?: string): Promise<{
|
||||
data?: DocumentUI;
|
||||
@@ -444,57 +452,67 @@ export async function updateDocument(id: string, document: Partial<DocumentUI> &
|
||||
if (!id) {
|
||||
return { error: '文档ID不能为空', status: 400 };
|
||||
}
|
||||
|
||||
|
||||
if (!userId) {
|
||||
return { error: '用户身份验证失败', status: 401 };
|
||||
}
|
||||
|
||||
|
||||
// 准备API数据 - 将UI数据转换为API格式
|
||||
// 根据文档,可更新字段:document_number, audit_status, is_test_document, remark
|
||||
const apiDocument: Partial<Document> = {};
|
||||
|
||||
|
||||
if (document.documentNumber !== undefined) {
|
||||
apiDocument.document_number = document.documentNumber;
|
||||
}
|
||||
|
||||
// if (document.type !== undefined) {
|
||||
// apiDocument.type_id = parseInt(document.type);
|
||||
// }
|
||||
|
||||
|
||||
if (document.auditStatus !== undefined) {
|
||||
apiDocument.audit_status = document.auditStatus;
|
||||
}
|
||||
|
||||
|
||||
if (document.isTest !== undefined) {
|
||||
apiDocument.is_test_document = document.isTest;
|
||||
}
|
||||
|
||||
|
||||
if (document.remark !== undefined) {
|
||||
apiDocument.remark = document.remark;
|
||||
}
|
||||
|
||||
// console.log('更新文档API数据:', apiDocument);
|
||||
|
||||
const response = await postgrestPut<Document, Partial<Document>>(
|
||||
'/api/postgrest/proxy/documents',
|
||||
apiDocument,
|
||||
{
|
||||
id: parseInt(id),
|
||||
user_id: parseInt(userId) // 确保只能更新自己的文档
|
||||
},
|
||||
frontendJWT
|
||||
|
||||
// console.log('📤 [updateDocument] 更新文档API数据:', apiDocument);
|
||||
|
||||
// 使用 axios-client 的 apiRequest 方法(支持自定义 headers)
|
||||
// 接口路径: /api/postgrest/proxy/documents?id=eq.{id}
|
||||
// 后端会自动注入 user_id 过滤条件(根据JWT中的用户信息)
|
||||
const { apiRequest } = await import('../axios-client');
|
||||
const response = await apiRequest<Document[]>(
|
||||
`/api/postgrest/proxy/documents?id=eq.${id}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
data: apiDocument,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(frontendJWT ? { 'Authorization': `Bearer ${frontendJWT}` } : {})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if (response.error) {
|
||||
console.error('更新文档API错误:', response.error);
|
||||
console.error('❌ [updateDocument] 更新文档API错误:', response.error);
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
// 获取更新后的完整文档数据
|
||||
|
||||
// 检查返回数据
|
||||
// 成功时返回更新后的文档数组,空数组表示文档不存在或无权访问
|
||||
const responseData = response.data;
|
||||
if (!responseData || (Array.isArray(responseData) && responseData.length === 0)) {
|
||||
return { error: '文档不存在或无权访问', status: 404 };
|
||||
}
|
||||
|
||||
// 获取更新后的完整文档数据(包含关联的文档类型信息)
|
||||
const updatedResponse = await getDocument(id, userId, frontendJWT);
|
||||
|
||||
|
||||
return updatedResponse;
|
||||
} catch (error) {
|
||||
console.error('更新文档信息失败:', error);
|
||||
console.error('❌ [updateDocument] 更新文档信息失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '更新文档信息失败',
|
||||
status: 500
|
||||
|
||||
Reference in New Issue
Block a user