jsonMark.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { httpApp } from "@/plugins/axiosApp";
  2. import { RichTextQuestion, UnionStore } from "@/types";
  3. /** 清理复核任务 */
  4. export async function getJSON(url: string) {
  5. return httpApp.get(url, { withCredentials: false });
  6. }
  7. export async function getPaper(store: UnionStore) {
  8. const res = await getJSON(store.setting.subject.paperUrl);
  9. store.setting.subject.questions = [];
  10. if (res.data.questions) {
  11. // 云平台格式
  12. const questions = res.data.questions; // TODO: add type
  13. for (const q of questions) {
  14. const tempQuestion = {
  15. unionOrder: q.mainNumber + "-" + q.subNumber,
  16. body: q.body,
  17. parentBody: q.parentBody,
  18. answer: [q.answer],
  19. } as RichTextQuestion;
  20. store.setting.subject.questions.push(tempQuestion);
  21. }
  22. } else {
  23. const details = res.data.details;
  24. for (let order1 of details) {
  25. for (let order2 of order1.questions) {
  26. if (order2.subQuestions) {
  27. for (let order3 of order2.subQuestions) {
  28. const tempQuestion = {
  29. unionOrder:
  30. order1.number + "-" + order2.number + "-" + order3.number,
  31. body: order3.body,
  32. parentBody: order2.body,
  33. answer: order3.answer,
  34. } as RichTextQuestion;
  35. store.setting.subject.questions.push(tempQuestion);
  36. }
  37. } else {
  38. const tempQuestion = {
  39. unionOrder: order1.number + "-" + order2.number,
  40. body: order2.body,
  41. parentBody: null,
  42. answer: order2.answer,
  43. } as RichTextQuestion;
  44. store.setting.subject.questions.push(tempQuestion);
  45. }
  46. }
  47. }
  48. }
  49. }