新增提示Toast组件
This commit is contained in:
@@ -90,6 +90,17 @@ interface StatsData {
|
||||
score: number;
|
||||
}
|
||||
|
||||
// 在文件顶部添加的类型定义,在interface区块前添加
|
||||
interface OcrDataResult {
|
||||
pages?: number[];
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
interface OcrData {
|
||||
[key: string]: OcrDataResult | unknown;
|
||||
ocr_result?: Record<string, OcrDataResult | unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评查文件的所有评查点结果
|
||||
* @param fileId 评查文件ID
|
||||
@@ -204,8 +215,9 @@ export async function getReviewPoints(fileId: string) {
|
||||
}
|
||||
|
||||
// 提取页码数组
|
||||
let contentPage: number[] = [];
|
||||
console.log('datacontent-------', data);
|
||||
let contentPage: Record<string, number[]> = {};
|
||||
// console.log('result-------', result.evaluated_results?.result);
|
||||
// console.log('datacontent-------', data);
|
||||
if (data && typeof data === 'object') {
|
||||
try {
|
||||
const dataObj = data as Record<string, string>;
|
||||
@@ -214,19 +226,19 @@ export async function getReviewPoints(fileId: string) {
|
||||
if (Object.prototype.hasOwnProperty.call(dataObj, key)) {
|
||||
// 使用'-'分割获取前缀(如'立案报告表')
|
||||
const prefix = key.split('-')[0];
|
||||
console.log('prefix-------', prefix);
|
||||
// console.log('prefix-------', prefix);
|
||||
// 检查document.data中的ocrResult是否存在这个key
|
||||
if (documentData.data?.ocrResult &&
|
||||
typeof documentData.data.ocrResult === 'object') {
|
||||
|
||||
// ocrResult可能有嵌套的ocr_result属性
|
||||
let ocrData: Record<string, any> = documentData.data.ocrResult as Record<string, any>;
|
||||
let ocrData: OcrData = documentData.data.ocrResult as OcrData;
|
||||
|
||||
// 检查是否有嵌套的ocr_result对象
|
||||
if ('ocr_result' in ocrData &&
|
||||
ocrData.ocr_result &&
|
||||
typeof ocrData.ocr_result === 'object') {
|
||||
ocrData = ocrData.ocr_result as Record<string, any>;
|
||||
ocrData = ocrData.ocr_result as OcrData;
|
||||
}
|
||||
|
||||
for (const ocrKey in ocrData) {
|
||||
@@ -239,7 +251,8 @@ export async function getReviewPoints(fileId: string) {
|
||||
// 获取pages数组
|
||||
const pages = ocrData[ocrKey].pages;
|
||||
if (Array.isArray(pages)) {
|
||||
contentPage = pages;
|
||||
// 存储每个key对应的页码数组
|
||||
contentPage[key] = pages;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -249,7 +262,7 @@ export async function getReviewPoints(fileId: string) {
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析评查点data失败:', e);
|
||||
contentPage = [];
|
||||
contentPage = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,3 +433,62 @@ export async function updateReviewResult(resultId: string, result: boolean, mess
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认评查结果并更新文档审核状态
|
||||
* @param documentId 文档ID
|
||||
* @returns 更新结果
|
||||
*/
|
||||
export async function confirmReviewResults(documentId: string): Promise<{
|
||||
data?: { auditStatus: number; score: number };
|
||||
error?: string;
|
||||
status?: number;
|
||||
}> {
|
||||
try {
|
||||
if (!documentId) {
|
||||
return { error: '文档ID不能为空', status: 400 };
|
||||
}
|
||||
|
||||
// 获取该文档的所有评查点结果
|
||||
const reviewPointsResponse = await getReviewPoints(documentId);
|
||||
|
||||
if ('error' in reviewPointsResponse && reviewPointsResponse.error) {
|
||||
return { error: reviewPointsResponse.error, status: reviewPointsResponse.status };
|
||||
}
|
||||
|
||||
if (!('data' in reviewPointsResponse) || !reviewPointsResponse.data || !Array.isArray(reviewPointsResponse.data)) {
|
||||
return { error: '获取评查点数据失败', status: 500 };
|
||||
}
|
||||
|
||||
// 计算总分数
|
||||
const totalScore = reviewPointsResponse.stats?.score || 0;
|
||||
|
||||
// 根据总分确定审核状态
|
||||
// <80分:不通过(-1),>=80分:通过(1)
|
||||
const auditStatus = totalScore < 80 ? -1 : 1;
|
||||
|
||||
// 更新文档的审核状态
|
||||
const updateDocumentParams = {
|
||||
audit_status: auditStatus
|
||||
};
|
||||
|
||||
// 调用API更新文档审核状态
|
||||
const response = await postgrestPut<{ id: string }, typeof updateDocumentParams>(
|
||||
'documents',
|
||||
updateDocumentParams,
|
||||
{ id: documentId }
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error, status: response.status };
|
||||
}
|
||||
|
||||
return { data: { auditStatus, score: totalScore } };
|
||||
} catch (error) {
|
||||
console.error('确认评查结果失败:', error);
|
||||
return {
|
||||
error: error instanceof Error ? error.message : '确认评查结果失败',
|
||||
status: 500
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { postgrestGet, postgrestPost, postgrestPut, postgrestDelete, type PostgrestParams } from '../postgrest-client';
|
||||
import dayjs from 'dayjs';
|
||||
import { formatDate } from '../../utils';
|
||||
|
||||
/**
|
||||
* 评查点分组接口
|
||||
@@ -44,20 +44,7 @@ interface ApiResponse<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
* @param dateString 日期字符串
|
||||
* @returns 格式化后的日期字符串
|
||||
*/
|
||||
function formatDate(dateString: string): string {
|
||||
if (!dateString) return '';
|
||||
try {
|
||||
return dayjs(dateString).format('YYYY-MM-DD HH:mm:ss');
|
||||
} catch (error) {
|
||||
console.error('日期格式化失败:', error);
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
|
||||
@@ -4,6 +4,7 @@ import { getDocumentTypes } from '../document-types/document-types';
|
||||
import type { DocumentTypeUI } from '../document-types/document-types';
|
||||
import weekday from 'dayjs/plugin/weekday';
|
||||
import updateLocale from 'dayjs/plugin/updateLocale';
|
||||
import { formatDate } from '../../utils';
|
||||
|
||||
// 配置 dayjs
|
||||
dayjs.extend(weekday);
|
||||
@@ -110,21 +111,6 @@ interface DocumentReviewResult {
|
||||
issueCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
* @param dateString 日期字符串
|
||||
* @returns 格式化后的日期字符串
|
||||
*/
|
||||
function formatDate(dateString: string): string {
|
||||
if (!dateString) return '';
|
||||
try {
|
||||
return dayjs(dateString).format('YYYY-MM-DD');
|
||||
} catch (error) {
|
||||
console.error('日期格式化失败:', error);
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
* @param responseData API 响应数据
|
||||
@@ -409,6 +395,7 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
|
||||
let hasFailResult = false;
|
||||
let totalScore = 0;
|
||||
let totalPoints = 0;
|
||||
let totalPassPoints = 0;
|
||||
|
||||
// 存储该文档的问题消息
|
||||
const issuesList: Array<{severity: 'info' | 'warning' | 'error' | 'critical', message: string}> = [];
|
||||
@@ -425,7 +412,7 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
|
||||
}
|
||||
|
||||
// 检查是否有不通过的结果
|
||||
if (resultValue === false) {
|
||||
if (!resultValue) {
|
||||
hasFailResult = true;
|
||||
|
||||
// 收集问题消息
|
||||
@@ -435,6 +422,8 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
|
||||
message: evaluatedResults.message as string
|
||||
});
|
||||
}
|
||||
}else{
|
||||
totalPassPoints++;
|
||||
}
|
||||
|
||||
// 计算总分
|
||||
@@ -467,7 +456,9 @@ export async function getReviewFiles(searchParams: DocumentSearchParams = {}): P
|
||||
// 如果没有评查点,默认为通过
|
||||
if (totalPoints > 0) {
|
||||
// 通过分数线为80分
|
||||
status = totalScore >= 80 ? 1 : -1; // 通过或不通过
|
||||
// status = totalScore >= 80 ? 1 : -1; // 通过或不通过
|
||||
// 通过率为80%
|
||||
status = parseFloat((totalPassPoints/totalPoints).toFixed(1)) >= 0.8 ? 1 : -1; // 通过或不通过
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { postgrestGet, postgrestPost, postgrestPut, postgrestDelete, type PostgrestParams } from '../postgrest-client';
|
||||
import dayjs from 'dayjs';
|
||||
import { formatDate } from '../../utils';
|
||||
|
||||
/**
|
||||
* 从不同格式的 API 响应中提取数据
|
||||
@@ -146,11 +146,6 @@ function mapApiRuleToFrontendModel(apiRule: ApiRule): Rule {
|
||||
};
|
||||
}
|
||||
|
||||
// 格式化日期的辅助函数
|
||||
function formatDate(dateString: string): string {
|
||||
return dayjs(dateString).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评查点列表
|
||||
* @param params 查询参数
|
||||
|
||||
Reference in New Issue
Block a user