test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import request from "../request";
  2. import { AxiosPromise } from "axios";
  3. class Test {
  4. /** 获取题目列表 */
  5. list(params: Test.listParams): AxiosPromise<Test.listRes> {
  6. return request("/student/qustion/info/list", {
  7. params,
  8. });
  9. }
  10. /** 获取非VIP题目列表 */
  11. normalList(params: Test.listParams): AxiosPromise<Test.listRes> {
  12. return request("/student/qustion/info/normalList", {
  13. params,
  14. });
  15. }
  16. /** 根据ids批量获取问题详情 */
  17. getQuestionInfoByIds(
  18. params: Test.QuestionInfoByIdsParams
  19. ): AxiosPromise<Test.QuestionInfoByIdsRes> {
  20. return request("/student/qustion/info/getQuestionInfoByIds", {
  21. params: {
  22. ...params,
  23. ids: params.ids.toString(),
  24. },
  25. });
  26. }
  27. /** 获取地方题分类 */
  28. selectDfQustionInfo(
  29. params: Partial<Test.getTopicClassParams>
  30. ): AxiosPromise<Test.selectDfQustionInfoRes[]> {
  31. return request({
  32. url: `/student/qustion/info/selectDfQustionInfo`,
  33. params,
  34. });
  35. }
  36. /** 获取分类专题分类 */
  37. selectFlQustionInfo(
  38. params: Partial<Test.getTopicClassParams>
  39. ): AxiosPromise<Test.selectFlQustionInfoRes[]> {
  40. return request({
  41. url: `/student/qustion/info/selectFlQustionInfo`,
  42. params,
  43. });
  44. }
  45. /** 获取精选题分类 */
  46. selectJxQustionInfo(
  47. params: Partial<Test.getTopicClassParams>
  48. ): AxiosPromise<Test.selectJxQustionInfoRes[]> {
  49. return request({
  50. url: `/student/qustion/info/selectJxQustionInfo`,
  51. params,
  52. });
  53. }
  54. /** 获取顺序练习分类 */
  55. selectSxQustionInfo(
  56. params: Partial<Test.getTopicClassParams>
  57. ): AxiosPromise<Test.selectSxQustionInfoRes[]> {
  58. return request({
  59. url: `/student/qustion/info/selectSxQustionInfo`,
  60. params,
  61. });
  62. }
  63. }
  64. export const test = new Test();
  65. /**
  66. * 获取题目列表
  67. * @returns
  68. */
  69. export async function getTopicList(params: any, isVip: Boolean = true) {
  70. const getUserAnswer = (type: string) => {
  71. switch (type) {
  72. case "判断题":
  73. return null;
  74. case "单选题":
  75. return null;
  76. case "多选题":
  77. return [];
  78. }
  79. };
  80. const getType = (answer: Array<string>) => {
  81. if (answer.length === 1) {
  82. if (["√", "×"].includes(answer[0])) {
  83. return "判断题";
  84. } else {
  85. return "单选题";
  86. }
  87. } else {
  88. return "多选题";
  89. }
  90. };
  91. const res = await request({
  92. url: isVip
  93. ? "/student/qustion/info/list"
  94. : "/student/qustion/info/normalList",
  95. params,
  96. });
  97. const data = {
  98. total: res.data.total,
  99. list: res.data.rows.map((item: any) => {
  100. return {
  101. ...item,
  102. explain: item.issue,
  103. opts: item.opts.split("-"),
  104. image: item.image,
  105. type: getType(item.answer.split("-")),
  106. answer: item.answer,
  107. userAnswer: getUserAnswer(getType(item.answer.split("-"))),
  108. isTrue: null,
  109. isCollection: false,
  110. };
  111. }),
  112. };
  113. return data;
  114. }
  115. /**
  116. * 获取题目分类
  117. */
  118. export async function getTopicClass(path: string, params: any) {
  119. return request({
  120. url: `/student/qustion/info/${path}`,
  121. params,
  122. });
  123. }
  124. /**
  125. * 根据ids批量获取问题详情
  126. */
  127. export const getQuestionInfoByIds = async (
  128. params: Test.QuestionInfoByIdsParams
  129. ) => {
  130. const res = await request({
  131. url: "/student/qustion/info/getQuestionInfoByIds",
  132. params: {
  133. ...params,
  134. ids: params.ids.toString(),
  135. },
  136. });
  137. return <Test.QuestionInfoByIdsRes>res.data;
  138. };