12345678910111213141516171819202122232425262728293031323334353637 |
- import {array} from "@/uni_modules/uv-ui-tools/libs/function/test";
- export function useQuestionTranslate(question) {
- // 将旧的题属性转换为新题属性,以方便
- // 使用mx-question-content 和mx-question-parse
- // 自动获得MathJax支持
- const makeOptions = () => {
- const result = []
- if (array(question.options)) result.push(...question.options)
- const opts = Object.keys(question)
- .filter(k => k.startsWith('option') && k != 'options' && question[k])
- .sort()
- .map(k => question[k])
- result.push(...opts)
- return result
- }
- const fixTypeId = (q) => {
- if (q.typeId) return
- if (['单选题', '选择题', '判断题'].includes(q.type)) return q.typeId = 1
- if (['多选题'].includes(q.type)) return q.typeId = 3
- }
- const formatted = {
- ...question,
- questionId: question.id || question.questionId,
- type: question.qtpye || question.type,
- options: makeOptions(),
- answers: [question.answer1, question.answer2],
- knowledge: question.knownledgeName || question.knowledges || question.knowledge,
- _raw: question
- }
- fixTypeId(formatted)
- return formatted
- }
|