import httpService from "./httpService"; import type { ApiResponse } from "./httpService"; export enum StageType { INTRO = "intro", TEST = "test", RESULT = "result", } // 单个选项类型 interface Option { text: string; score: number; } // 单个问题类型 export interface Question { id: number; question_title: string; question_content: string; options: Option[]; radar_mapping: string[]; } // 单项能力分数 interface AbilityScore { current_score: number; max_score: number; percentage: number; } // 雷达图数据 interface RadarData { abilities: Record; // key 是能力名称,如 "正手球质" summary: { total_questions: number; calculation_time: string; // ISO 字符串 }; } // 单题答案 interface Answer { question_id: number; question_title: string; answer_index: number; selected_option: string; score: number; } // 提交测试结果 对象类型 export interface TestResultData { record_id: number; total_score: number; ntrp_level: string; is_coverage: boolean; old_ntrp_level: string; level_description: string; level_img?: string; // 等级图片URL radar_data: RadarData; answers: Answer[]; sort?: string[]; // 雷达图能力项排序,如 ["正手球质", "正手控制", ...] } // 单条测试记录 interface TestRecord { id: number; total_score: number; ntrp_level: string; level_description: string; test_duration: number; // 单位:秒 create_time: string; // 时间字符串 } // 测试历史对象类型 export interface TestResultList { count: number; rows: TestRecord[]; } // 单次测试结果 interface TestResult { id: number; total_score: number; ntrp_level: string; level_description: string; level_img?: string; // 等级图片URL radar_data: RadarData; test_duration: number; // 单位秒 create_time: string; // 时间字符串 } // data 对象 // 上一次测试结果 export interface LastTimeTestResult { has_test_record: boolean; has_ntrp_level: boolean; user_ntrp_level: string; last_test_result: TestResult; has_test_in_last_month: boolean; // 最近一个月是否有测试记录 } class EvaluateService { // 获取测试题目 async getQuestions(): Promise> { return httpService.post("/ntrp/questions", {}, { showLoading: true }); } // 提交答案 async submit(req: { answers: { question_id: number; answer_index: number }[]; test_duration: number; }): Promise> { return httpService.post("/ntrp/submit", req, { showLoading: true }); } // 获取测试历史 async getResultList(): Promise> { return httpService.post("/ntrp/history", {}, { showLoading: true }); } // 获取测试详情 async getTestResult(req: { record_id: number; }): Promise> { return httpService.post("/ntrp/detail", req, { showLoading: true }); } // 获取最后一次(最新)测试结果 async getLastResult(): Promise> { return httpService.post("/ntrp/last_result", {}, { showLoading: false }); } // 更新NTRP等级 async updateNtrp(req: { record_id: number; ntrp_level: string; update_type: string; }): Promise> { return httpService.post("/ntrp/update_user_level", req, { showLoading: true, }); } } // 导出认证服务实例 export default new EvaluateService();