wordCard.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {
  2. stemTypeList,
  3. scoreTypeList,
  4. questionNumberTypeList,
  5. optionTypeList,
  6. switchOption,
  7. fontSizeList,
  8. } from './common';
  9. import { getRandomNumber } from '@/utils/index';
  10. import { handleChineseStrokes, handleItemPinyin } from './chinese';
  11. export function getOption(content = '') {
  12. return {
  13. content,
  14. mark: getRandomNumber(),
  15. audio_file_id: '',
  16. pinyin: '',
  17. definition: '',
  18. collocation: '',
  19. example_sentence: ['', ''],
  20. picture_file_id: '',
  21. hz_strokes_list: [],
  22. };
  23. }
  24. // 音频生成方式类型
  25. export const audioGenerationMethodList = [
  26. {
  27. value: 'upload',
  28. label: '上传',
  29. },
  30. {
  31. value: 'auto',
  32. label: '自动生成',
  33. },
  34. {
  35. value: 'record',
  36. label: '录音',
  37. },
  38. ];
  39. // 修改拼音
  40. function changePinyin(item) {
  41. let index = item.pinyin.search(/0|1|2|3|4/);
  42. if (index > -1) {
  43. let matically_pinyin_obj = {};
  44. handleItemPinyin(item.pinyin, item.mark, matically_pinyin_obj);
  45. setTimeout(() => {
  46. item.pinyin = matically_pinyin_obj[item.mark];
  47. }, 100);
  48. }
  49. }
  50. /**
  51. * 解析智能识别数据
  52. * @param {array} arr 智能识别数据
  53. * @returns object
  54. */
  55. export async function analysisRecognitionWordCardData(arr) {
  56. let option_list = await Promise.all(
  57. arr.map(async (content) => {
  58. let content_item = content.split('/');
  59. let option = {
  60. content: content_item[0] ? content_item[0] : '',
  61. mark: getRandomNumber(),
  62. audio_file_id: '',
  63. pinyin: content_item[1] ? content_item[1] : '',
  64. definition: content_item[2] ? content_item[2] : '',
  65. collocation: content_item[3] ? content_item[3] : '',
  66. example_sentence: content_item.length > 3 ? content_item.slice(4) : [''],
  67. picture_file_id: '',
  68. hz_strokes_list: [],
  69. };
  70. await handleChineseStrokes(option);
  71. changePinyin(option);
  72. return option;
  73. }),
  74. );
  75. return {
  76. 'data.option_list': option_list,
  77. };
  78. }
  79. // 字词卡片数据模板
  80. export const wordCardData = {
  81. type: 'word_card', // 题型
  82. stem: '', // 题干
  83. description: '', // 描述
  84. option_number_show_mode: optionTypeList[1].value, // 选项类型
  85. answer: { score: 1, score_type: scoreTypeList[0].value }, // 答案
  86. option_list: [getOption()], // 选项
  87. file_id_list: [],
  88. // 题型属性
  89. property: {
  90. stem_type: stemTypeList[1].value, // 题干类型
  91. question_number: '1', // 题号
  92. stem_question_number_font_size: fontSizeList[6], // 题干题号
  93. is_enable_description: switchOption[1].value, // 描述
  94. score: 1, // 分值
  95. score_type: scoreTypeList[0].value, // 分值类型
  96. },
  97. // 其他属性
  98. other: {
  99. question_number_type: questionNumberTypeList[1].value, // 题号类型
  100. audio_generation_method: audioGenerationMethodList[0].value, // 音频生成方式
  101. },
  102. };