Просмотр исходного кода

修正题目选项缺失问题

wyling007 3 лет назад
Родитель
Сommit
7d21a2c8cf
2 измененных файлов с 147 добавлено и 164 удалено
  1. 104 118
      src/api/modules/test.ts
  2. 43 46
      src/model/collection.ts

+ 104 - 118
src/api/modules/test.ts

@@ -2,71 +2,61 @@ import request from "../request";
 import { AxiosPromise } from "axios";
 
 class Test {
-  /** 获取题目列表 */
-  list(params: Test.listParams): AxiosPromise<Test.listRes> {
-    return request("/student/qustion/info/list", {
-      params,
-    });
-  }
+	/** 获取题目列表 */
+	list(params: Test.listParams): AxiosPromise<Test.listRes> {
+		return request("/student/qustion/info/list", {
+			params,
+		});
+	}
 
-  /** 获取非VIP题目列表 */
-  normalList(params: Test.listParams): AxiosPromise<Test.listRes> {
-    return request("/student/qustion/info/normalList", {
-      params,
-    });
-  }
+	/** 获取非VIP题目列表 */
+	normalList(params: Test.listParams): AxiosPromise<Test.listRes> {
+		return request("/student/qustion/info/normalList", {
+			params,
+		});
+	}
 
-  /** 根据ids批量获取问题详情  */
-  getQuestionInfoByIds(
-    params: Test.QuestionInfoByIdsParams
-  ): AxiosPromise<Test.QuestionInfoByIdsRes> {
-    return request("/student/qustion/info/getQuestionInfoByIds", {
-      params: {
-        ...params,
-        ids: params.ids.toString(),
-      },
-    });
-  }
+	/** 根据ids批量获取问题详情  */
+	getQuestionInfoByIds(params: Test.QuestionInfoByIdsParams): AxiosPromise<Test.QuestionInfoByIdsRes> {
+		return request("/student/qustion/info/getQuestionInfoByIds", {
+			params: {
+				...params,
+				ids: params.ids.toString(),
+			},
+		});
+	}
 
-  /** 获取地方题分类 */
-  selectDfQustionInfo(
-    params: Partial<Test.getTopicClassParams>
-  ): AxiosPromise<Test.selectDfQustionInfoRes[]> {
-    return request({
-      url: `/student/qustion/info/selectDfQustionInfo`,
-      params,
-    });
-  }
+	/** 获取地方题分类 */
+	selectDfQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectDfQustionInfoRes[]> {
+		return request({
+			url: `/student/qustion/info/selectDfQustionInfo`,
+			params,
+		});
+	}
 
-  /** 获取分类专题分类 */
-  selectFlQustionInfo(
-    params: Partial<Test.getTopicClassParams>
-  ): AxiosPromise<Test.selectFlQustionInfoRes[]> {
-    return request({
-      url: `/student/qustion/info/selectFlQustionInfo`,
-      params,
-    });
-  }
+	/** 获取分类专题分类 */
+	selectFlQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectFlQustionInfoRes[]> {
+		return request({
+			url: `/student/qustion/info/selectFlQustionInfo`,
+			params,
+		});
+	}
 
-  /** 获取精选题分类 */
-  selectJxQustionInfo(
-    params: Partial<Test.getTopicClassParams>
-  ): AxiosPromise<Test.selectJxQustionInfoRes[]> {
-    return request({
-      url: `/student/qustion/info/selectJxQustionInfo`,
-      params,
-    });
-  }
+	/** 获取精选题分类 */
+	selectJxQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectJxQustionInfoRes[]> {
+		return request({
+			url: `/student/qustion/info/selectJxQustionInfo`,
+			params,
+		});
+	}
 
-  /** 获取顺序练习分类 */
-  selectSxQustionInfo(
-    params: Partial<Test.getTopicClassParams>
-  ): AxiosPromise<Test.selectSxQustionInfoRes[]> {
-    return request({
-      url: `/student/qustion/info/selectSxQustionInfo`,
-      params,
-    });
-  }
+	/** 获取顺序练习分类 */
+	selectSxQustionInfo(params: Partial<Test.getTopicClassParams>): AxiosPromise<Test.selectSxQustionInfoRes[]> {
+		return request({
+			url: `/student/qustion/info/selectSxQustionInfo`,
+			params,
+		});
+	}
 }
 
 export const test = new Test();
@@ -76,78 +66,74 @@ export const test = new Test();
  * @returns
  */
 export async function getTopicList(params: any, isVip: Boolean = true) {
-  const getUserAnswer = (type: string) => {
-    switch (type) {
-      case "判断题":
-        return null;
-      case "单选题":
-        return null;
-      case "多选题":
-        return [];
-    }
-  };
+	const getUserAnswer = (type: string) => {
+		switch (type) {
+			case "判断题":
+				return null;
+			case "单选题":
+				return null;
+			case "多选题":
+				return [];
+		}
+	};
 
-  const getType = (answer: Array<string>) => {
-    if (answer.length === 1) {
-      if (["√", "×"].includes(answer[0])) {
-        return "判断题";
-      } else {
-        return "单选题";
-      }
-    } else {
-      return "多选题";
-    }
-  };
+	const getType = (answer: Array<string>) => {
+		if (answer.length === 1) {
+			if (["√", "×"].includes(answer[0])) {
+				return "判断题";
+			} else {
+				return "单选题";
+			}
+		} else {
+			return "多选题";
+		}
+	};
 
-  const res = await request({
-    url: isVip
-      ? "/student/qustion/info/list"
-      : "/student/qustion/info/normalList",
-    params,
-  });
+	const res = await request({
+		url: isVip ? "/student/qustion/info/list" : "/student/qustion/info/normalList",
+		params,
+	});
 
-  const data = {
-    total: res.data.total,
-    list: res.data.rows.map((item: any) => {
-      return {
-        ...item,
-        explain: item.issue,
-        opts: item.opts.split("-"),
-        image: item.image,
-        type: getType(item.answer.split("-")),
-        answer: item.answer,
-        userAnswer: getUserAnswer(getType(item.answer.split("-"))),
-        isTrue: null,
-        isCollection: false,
-      };
-    }),
-  };
+	const data = {
+		total: res.data.total,
+		list: res.data.rows.map((item: any) => {
+			return {
+				...item,
+				explain: item.issue,
+				opts: item.opts.split("-").filter((item: any) => !!item),
+				image: item.image,
+				type: getType(item.answer.split("-")),
+				answer: item.answer,
+				userAnswer: getUserAnswer(getType(item.answer.split("-"))),
+				isTrue: null,
+				isCollection: false,
+			};
+		}),
+	};
 
-  return data;
+	return data;
 }
 
 /**
  * 获取题目分类
  */
 export async function getTopicClass(path: string, params: any) {
-  return request({
-    url: `/student/qustion/info/${path}`,
-    params,
-  });
+	return request({
+		url: `/student/qustion/info/${path}`,
+		params,
+	});
 }
 
 /**
  * 根据ids批量获取问题详情
  */
-export const getQuestionInfoByIds = async (
-  params: Test.QuestionInfoByIdsParams
-) => {
-  const res = await request({
-    url: "/student/qustion/info/getQuestionInfoByIds",
-    params: {
-      ...params,
-      ids: params.ids.toString(),
-    },
-  });
-  return <Test.QuestionInfoByIdsRes>res.data;
+export const getQuestionInfoByIds = async (params: Test.QuestionInfoByIdsParams) => {
+	const res = await request({
+		url: "/student/qustion/info/getQuestionInfoByIds",
+		params: {
+			...params,
+			ids: params.ids.toString(),
+		},
+	});
+	return <Test.QuestionInfoByIdsRes>res.data;
 };

+ 43 - 46
src/model/collection.ts

@@ -2,54 +2,51 @@ import { getQuestionInfoByIds, CollectionAndWrong } from "@/api";
 
 /**收藏与错题列表模型 */
 export class CollectionModel {
-  private collectionApi;
+	private collectionApi;
 
-  constructor(apiType: CollectionAndWrongType.type) {
-    this.collectionApi = new CollectionAndWrong(apiType);
-  }
+	constructor(apiType: CollectionAndWrongType.type) {
+		this.collectionApi = new CollectionAndWrong(apiType);
+	}
 
-  /**获取列表 */
-  async getList(params: CollectionAndWrongType.ListParams): Promise<{
-    total: number;
-    rows: Test.QuestionInfo[];
-    collectionList: CollectionAndWrongType.QuestionRes[];
-  }> {
-    const collectionListRes = await this.collectionApi.getList(params);
-    if (collectionListRes.rows.length > 0) {
-      const ids = collectionListRes.rows.map((item) => item.questionId);
-      const questions = await getQuestionInfoByIds({
-        ids,
-      });
-      return {
-        total: collectionListRes.total,
-        rows: questions.rows,
-        collectionList: collectionListRes.rows,
-      };
-    } else {
-      return {
-        total: collectionListRes.total,
-        rows: [],
-        collectionList: collectionListRes.rows,
-      };
-    }
-  }
+	/**获取列表 */
+	async getList(params: CollectionAndWrongType.ListParams): Promise<{
+		total: number;
+		rows: Test.QuestionInfo[];
+		collectionList: CollectionAndWrongType.QuestionRes[];
+	}> {
+		const collectionListRes = await this.collectionApi.getList(params);
+		if (collectionListRes.rows.length > 0) {
+			const ids = collectionListRes.rows.map((item) => item.questionId);
+			const questions = await getQuestionInfoByIds({
+				ids,
+			});
+			return {
+				total: collectionListRes.total,
+				rows: questions.rows,
+				collectionList: collectionListRes.rows,
+			};
+		} else {
+			return {
+				total: collectionListRes.total,
+				rows: [],
+				collectionList: collectionListRes.rows,
+			};
+		}
+	}
 
-  /** 删除已收藏的问题 */
-  async deletes(
-    ids: number[],
-    collectionList: CollectionAndWrongType.QuestionRes[]
-  ) {
-    const deletesCollectionList = collectionList.filter((item) => {
-      return ids.includes(item.questionId);
-    });
-    const deletesIds = deletesCollectionList.map((item) => item.id);
-    const res = await this.collectionApi.deletes(deletesIds);
-    return res;
-  }
+	/** 删除已收藏的问题 */
+	async deletes(ids: number[], collectionList: CollectionAndWrongType.QuestionRes[]) {
+		const deletesCollectionList = collectionList.filter((item) => {
+			return ids.includes(item.questionId);
+		});
+		const deletesIds = deletesCollectionList.map((item) => item.id);
+		const res = await this.collectionApi.deletes(deletesIds);
+		return res;
+	}
 
-  /** 新增收藏或者错题 */
-  async adds(params: CollectionAndWrongType.AddCullectionsParams) {
-    const res = await this.collectionApi.adds(params);
-    return res.data;
-  }
+	/** 新增收藏或者错题 */
+	async adds(params: CollectionAndWrongType.AddCullectionsParams) {
+		const res = await this.collectionApi.adds(params);
+		return res.data;
+	}
 }