feat: 问卷调查
This commit is contained in:
@@ -1,71 +1,123 @@
|
||||
import httpService from "./httpService";
|
||||
import type { ApiResponse } from "./httpService";
|
||||
|
||||
export interface AnswerResItem {
|
||||
question_id: number;
|
||||
answer_index: number;
|
||||
// 单个选项类型
|
||||
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<string, AbilityScore>; // 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 type AnswerItem = Pick<AnswerResItem, "question_id" | "answer_index">;
|
||||
|
||||
export interface Answers {
|
||||
answers: AnswerItem[];
|
||||
test_duration: number;
|
||||
}
|
||||
|
||||
export interface QuestionItem {
|
||||
id: number;
|
||||
question_title: string;
|
||||
question_content: string;
|
||||
options: string[];
|
||||
scores: number[];
|
||||
}
|
||||
|
||||
export interface SubmitAnswerRes {
|
||||
// 提交测试结果 对象类型
|
||||
export interface TestResultData {
|
||||
record_id: number;
|
||||
total_score: number;
|
||||
ntrp_level: string;
|
||||
is_coverage: boolean;
|
||||
old_ntrp_level: string;
|
||||
level_description: string;
|
||||
answers: AnswerResItem[];
|
||||
radar_data: RadarData;
|
||||
answers: Answer[];
|
||||
}
|
||||
|
||||
// 单条测试记录
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
// 发布球局类
|
||||
class EvaluateService {
|
||||
async getEvaluateQuestions(): Promise<ApiResponse<QuestionItem[]>> {
|
||||
return httpService.post("/ntrp/questions", {
|
||||
showLoading: true,
|
||||
});
|
||||
// 获取测试题目
|
||||
async getQuestions(): Promise<ApiResponse<Question[]>> {
|
||||
return httpService.post("/ntrp/questions", {}, { showLoading: true });
|
||||
}
|
||||
|
||||
async submitEvaluateAnswers({
|
||||
answers,
|
||||
}: Answers): Promise<ApiResponse<SubmitAnswerRes>> {
|
||||
return httpService.post(
|
||||
"/ntrp/submit",
|
||||
{ answers },
|
||||
{
|
||||
showLoading: true,
|
||||
},
|
||||
);
|
||||
// 提交答案
|
||||
async submit(req: { answers: { question_id: number, answer_index: number }[], test_duration: number }): Promise<ApiResponse<TestResultData>> {
|
||||
return httpService.post("/ntrp/submit", req, { showLoading: true });
|
||||
}
|
||||
|
||||
async getHistoryNtrp(): Promise<ApiResponse<any>> {
|
||||
return httpService.post("/ntrp/history", {
|
||||
showLoading: true,
|
||||
});
|
||||
// 获取测试历史
|
||||
async getResultList(): Promise<ApiResponse<TestResultList>> {
|
||||
return httpService.post("/ntrp/history", {}, { showLoading: true });
|
||||
}
|
||||
|
||||
async getNtrpDetail(record_id: number): Promise<ApiResponse<any>> {
|
||||
return httpService.post(
|
||||
"/ntrp/detail",
|
||||
{ record_id },
|
||||
{
|
||||
showLoading: true,
|
||||
},
|
||||
);
|
||||
// 获取测试详情
|
||||
async getTestResult(req: { record_id: number }): Promise<ApiResponse<TestResultData>> {
|
||||
return httpService.post("/ntrp/detail", req, { showLoading: true });
|
||||
}
|
||||
|
||||
// 获取最后一次(最新)测试结果
|
||||
async getLastResult(): Promise<ApiResponse<LastTimeTestResult>> {
|
||||
return httpService.post("/ntrp/last_result", {}, { showLoading: true });
|
||||
}
|
||||
|
||||
// 更新NTRP等级
|
||||
async updateNtrp(req: { record_id: number, ntrp_level: string, update_type: string }): Promise<ApiResponse<any>> {
|
||||
return httpService.post("/ntrp/update_user_level", req, { showLoading: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user