common.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { digitToChinese } from '@/utils/transform';
  2. // 题型选项
  3. export const questionTypeOption = [
  4. {
  5. value: 'base',
  6. label: '基础题型',
  7. children: [
  8. { label: '选择题', value: 'select' },
  9. { label: '判断题', value: 'judge' },
  10. { label: '填空题', value: 'fill' },
  11. { label: '排序题', value: 'sort', disabled: true },
  12. { label: '连线题', value: 'matching' },
  13. { label: '选择声调', value: 'choose_tone' },
  14. ],
  15. },
  16. {
  17. value: 'spoken',
  18. label: '口语题',
  19. children: [
  20. { label: '朗读题', value: 'read_aloud' },
  21. { label: '听说训练', value: 'repeat' },
  22. { label: '看图说话', value: 'talk_picture' },
  23. { label: '对话练习', value: 'dialogue' },
  24. ],
  25. },
  26. {
  27. value: 'read',
  28. label: '阅读题',
  29. },
  30. {
  31. value: 'write',
  32. label: '写作题',
  33. },
  34. {
  35. value: 'chinese',
  36. label: '汉字题',
  37. },
  38. ];
  39. // 练习名称
  40. export const exerciseNames = questionTypeOption
  41. .map(({ label, value, children }) => {
  42. if (children) return children;
  43. return { label, value };
  44. })
  45. .flat()
  46. .reduce((obj, { label, value }) => {
  47. obj[value] = label;
  48. return obj;
  49. }, {});
  50. // 题型类型列表
  51. export const exerciseTypeList = questionTypeOption
  52. .map(({ value, children }) => {
  53. if (children) {
  54. return children.map(({ value: children_value }) => {
  55. return { [children_value]: [value, children_value] };
  56. });
  57. }
  58. return { [value]: [value] };
  59. })
  60. .flat()
  61. .reduce((obj, item) => {
  62. return { ...obj, ...item };
  63. }, {});
  64. // 选项类型
  65. export const optionTypeList = [
  66. { value: 'letter', label: '字母' },
  67. { value: 'number', label: '数字' },
  68. { value: 'chinese', label: '中文数字' },
  69. ];
  70. // 计算选项方法
  71. export const computeOptionMethods = {
  72. [optionTypeList[0].value]: (i) => String.fromCharCode(97 + i),
  73. [optionTypeList[1].value]: (i) => i + 1,
  74. [optionTypeList[2].value]: (i) => digitToChinese(i + 1),
  75. };
  76. /**
  77. * 改变选项类型
  78. * @param {object} data 数据
  79. */
  80. export function changeOptionType(data) {
  81. let index = optionTypeList.findIndex(({ value }) => value === data.option_number_show_mode);
  82. data.option_number_show_mode = optionTypeList[index + 1]?.value || optionTypeList[0].value;
  83. }
  84. /**
  85. * 计算选项题号
  86. * @param {Number} i 序号
  87. * @param {String} option_number_show_mode 选项类型
  88. * @returns String 题号
  89. */
  90. export function computedQuestionNumber(i, option_number_show_mode) {
  91. const computationMethod = computeOptionMethods[option_number_show_mode];
  92. if (computationMethod) {
  93. return computationMethod(i);
  94. }
  95. return '';
  96. }
  97. // 题干类型
  98. export const stemTypeList = [
  99. { value: 'text', label: '纯文本' },
  100. { value: 'rich', label: '富文本' },
  101. ];
  102. // 分值类型
  103. export const scoreTypeList = [
  104. { value: 'aggregate', label: '总分' },
  105. { value: 'subdivision', label: '细分' },
  106. ];
  107. // 选择类型
  108. export const selectTypeList = [
  109. { value: 'single', label: '单选' },
  110. { value: 'multiple', label: '多选' },
  111. ];
  112. // 开关选项
  113. export const switchOption = [
  114. { value: 'true', label: '开启' },
  115. { value: 'false', label: '关闭' },
  116. ];
  117. // 题号类型
  118. export const questionNumberTypeList = [
  119. { value: 'recalculate', label: '重新计算' },
  120. { value: 'follow', label: '跟随上题' },
  121. ];
  122. export const svgNS = 'http://www.w3.org/2000/svg'; // SVG命名空间