4d5ec6cdb7
- 更新 API 配置,使用新的后端服务地址- 移除前端模拟数据,改为从后端获取真实数据- 优化意见列表接口,支持分页和用户身份验证 - 调整前端界面,适应新的数据结构和功能需求
281 lines
7.5 KiB
TypeScript
281 lines
7.5 KiB
TypeScript
// import { postgrestPost } from "../postgrest-client";
|
|
|
|
/**
|
|
* 提出意见的请求参数接口
|
|
*/
|
|
export interface SubmitOpinionRequest {
|
|
reviewPointResultId: string | number;
|
|
documentId: string | number;
|
|
auditPoint: string;
|
|
foundIssue: string;
|
|
auditOpinion: string;
|
|
deductionScore: number;
|
|
}
|
|
|
|
/**
|
|
* 提出意见的响应接口
|
|
*/
|
|
export interface SubmitOpinionResponse {
|
|
success: boolean;
|
|
message: string;
|
|
data?: {
|
|
id: string | number;
|
|
created_at: string;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 交叉评查意见数据接口
|
|
*/
|
|
export interface CrossCheckingOpinion {
|
|
proposal_id: string | number;
|
|
evaluation_point_name: string;
|
|
proposed_score: number;
|
|
reason: string;
|
|
proposer: string;
|
|
votes: Array<{ voter: string; vote_type: string }>;
|
|
agree_voters: string[];
|
|
disagree_voters: string[];
|
|
pending_voters: string[];
|
|
can_vote: boolean;
|
|
problem_message: string;
|
|
// 兼容旧字段
|
|
id?: string | number;
|
|
evaluation_point_id?: string | number;
|
|
document_id?: string | number;
|
|
audit_point?: string;
|
|
found_issue?: string;
|
|
audit_opinion?: string;
|
|
deduction_score?: number;
|
|
status?: string;
|
|
created_at?: string;
|
|
updated_at?: string;
|
|
is_vote?: boolean;
|
|
voter_count?: number;
|
|
proposer_name?: string;
|
|
current_user_is_proposer?: boolean;
|
|
}
|
|
|
|
/**
|
|
* API响应格式
|
|
*/
|
|
export interface ApiResponse<T> {
|
|
data?: T;
|
|
error?: string;
|
|
status?: number;
|
|
}
|
|
|
|
/**
|
|
* 提交交叉评查意见
|
|
* @param opinionData 意见数据
|
|
* @returns 提交结果
|
|
*/
|
|
export async function submitCrossCheckingOpinion(
|
|
opinionData: SubmitOpinionRequest
|
|
): Promise<ApiResponse<SubmitOpinionResponse>> {
|
|
try {
|
|
const requestData = {
|
|
proposer_user_id: 1,
|
|
evaluation_result_id: opinionData.reviewPointResultId,
|
|
// document_id: opinionData.documentId,
|
|
// audit_point: opinionData.auditPoint,
|
|
// found_issue: opinionData.foundIssue,
|
|
proposed_score: opinionData.deductionScore,
|
|
reason: opinionData.auditOpinion
|
|
};
|
|
|
|
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(requestData)
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.message || '提交失败');
|
|
}
|
|
|
|
return {
|
|
data: {
|
|
success: true,
|
|
message: '意见提交成功',
|
|
data: data
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('提交交叉评查意见失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '提交意见失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取交叉评查意见列表(支持分页)
|
|
* @param documentId 文档ID
|
|
* @param page 页码
|
|
* @param pageSize 每页大小
|
|
* @returns 意见列表和总数
|
|
*/
|
|
import { API_BASE_URL } from '../../config/api-config';
|
|
|
|
export async function getCrossCheckingOpinions(
|
|
documentId: string | number,
|
|
page: number = 1,
|
|
pageSize: number = 10,
|
|
userId?: number // 可选,便于后端接口对接
|
|
): Promise<ApiResponse<{ opinions: CrossCheckingOpinion[], total: number }>> {
|
|
try {
|
|
// 如果没传userId,默认用1
|
|
const realUserId = userId ?? 1;
|
|
// 实际后端API调用,拼接API_BASE_URL
|
|
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/details`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
user_id: realUserId,
|
|
document_id: documentId, // 如果后端需要document_id可以加上
|
|
page,
|
|
page_size: pageSize
|
|
})
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error('获取意见列表失败');
|
|
}
|
|
const data = await response.json();
|
|
|
|
// 处理新的数据结构,支持分页
|
|
const responseData = data.data || data;
|
|
const pagination = data.pagination;
|
|
|
|
// 定义后端返回的数据项类型
|
|
interface ProposalItem {
|
|
proposal_id: string | number;
|
|
evaluation_point_name: string;
|
|
proposed_score: number;
|
|
reason: string;
|
|
proposer: string;
|
|
votes?: Array<{ voter: string; vote_type: string }>;
|
|
agree_voters?: string[];
|
|
disagree_voters?: string[];
|
|
pending_voters?: string[];
|
|
can_vote?: boolean;
|
|
problem_message?: string;
|
|
evaluation_point_id?: string | number;
|
|
document_id?: string | number;
|
|
status?: string;
|
|
created_at?: string;
|
|
updated_at?: string;
|
|
is_vote?: boolean;
|
|
current_user_is_proposer?: boolean;
|
|
}
|
|
|
|
// 适配后端返回结构,使用新字段
|
|
const opinions: CrossCheckingOpinion[] = Array.isArray(responseData) ? responseData.map((item: ProposalItem) => ({
|
|
proposal_id: item.proposal_id,
|
|
evaluation_point_name: item.evaluation_point_name,
|
|
proposed_score: item.proposed_score,
|
|
reason: item.reason,
|
|
proposer: item.proposer,
|
|
votes: item.votes || [],
|
|
agree_voters: item.agree_voters || [],
|
|
disagree_voters: item.disagree_voters || [],
|
|
pending_voters: item.pending_voters || [],
|
|
can_vote: item.can_vote ?? false,
|
|
problem_message: item.problem_message || '',
|
|
// 兼容旧字段
|
|
id: item.proposal_id,
|
|
evaluation_point_id: item.evaluation_point_id,
|
|
document_id: item.document_id || documentId,
|
|
audit_point: item.evaluation_point_name,
|
|
found_issue: item.problem_message || '',
|
|
audit_opinion: item.reason || '',
|
|
deduction_score: item.proposed_score,
|
|
status: item.status || 'pending',
|
|
created_at: item.created_at || '',
|
|
updated_at: item.updated_at || '',
|
|
is_vote: item.is_vote || false,
|
|
voter_count: (item.agree_voters?.length || 0) + (item.disagree_voters?.length || 0),
|
|
proposer_name: item.proposer,
|
|
current_user_is_proposer: item.current_user_is_proposer || false
|
|
})) : [];
|
|
|
|
return {
|
|
data: {
|
|
opinions,
|
|
total: pagination?.total || opinions.length
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('获取交叉评查意见失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '获取意见列表失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 意见操作类型
|
|
*/
|
|
export type OpinionActionType = 'agree' | 'disagree' | 'withdraw_vote' | 'withdraw_opinion';
|
|
|
|
/**
|
|
* 意见操作请求参数
|
|
*/
|
|
export interface OpinionActionRequest {
|
|
opinionId: string | number;
|
|
action: OpinionActionType;
|
|
}
|
|
|
|
/**
|
|
* 执行意见操作(赞同、反对、撤销投票、撤销意见)
|
|
* @param actionData 操作数据
|
|
* @returns 操作结果
|
|
*/
|
|
export async function performOpinionAction(
|
|
actionData: OpinionActionRequest
|
|
): Promise<ApiResponse<{ success: boolean; message: string }>> {
|
|
try {
|
|
// 模拟API调用延迟
|
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
let message = '';
|
|
switch (actionData.action) {
|
|
case 'agree':
|
|
message = '已赞同该意见';
|
|
break;
|
|
case 'disagree':
|
|
message = '已反对该意见';
|
|
break;
|
|
case 'withdraw_vote':
|
|
message = '已撤销投票';
|
|
break;
|
|
case 'withdraw_opinion':
|
|
message = '已撤销意见';
|
|
break;
|
|
default:
|
|
throw new Error('无效的操作类型');
|
|
}
|
|
|
|
return {
|
|
data: {
|
|
success: true,
|
|
message: message
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('执行意见操作失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '操作失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|