123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import request from "../request";
- import { AxiosPromise } from "axios";
- class Test {
- /** 获取题目列表 */
- 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,
- });
- }
- /** 根据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,
- });
- }
- /** 获取分类专题分类 */
- 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,
- });
- }
- /** 获取顺序练习分类 */
- selectSxQustionInfo(
- params: Partial<Test.getTopicClassParams>
- ): AxiosPromise<Test.selectSxQustionInfoRes[]> {
- return request({
- url: `/student/qustion/info/selectSxQustionInfo`,
- params,
- });
- }
- }
- 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 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 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,
- };
- }),
- };
- return data;
- }
- /**
- * 获取题目分类
- */
- export async function getTopicClass(path: string, params: any) {
- 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;
- };
|