import { digitToChinese } from '@/utils/transform'; // 题型选项 export const questionTypeOption = [ { value: 'base', label: '基础题型', children: [ { label: '选择题', value: 'select' }, { label: '判断题', value: 'judge' }, { label: '填空题', value: 'fill' }, { label: '排序题', value: 'sort', disabled: true }, { label: '连线题', value: 'matching' }, { label: '选择声调', value: 'choose_tone' }, ], }, { value: 'spoken', label: '口语题', children: [ { label: '朗读题', value: 'read_aloud' }, { label: '听说训练', value: 'repeat' }, { label: '看图说话', value: 'talk_picture' }, { label: '对话练习', value: 'dialogue' }, ], }, { value: 'read', label: '阅读题', }, { value: 'write', label: '写作题', }, { value: 'chinese', label: '汉字题', }, ]; // 练习名称 export const exerciseNames = questionTypeOption .map(({ label, value, children }) => { if (children) return children; return { label, value }; }) .flat() .reduce((obj, { label, value }) => { obj[value] = label; return obj; }, {}); // 题型类型列表 export const exerciseTypeList = questionTypeOption .map(({ value, children }) => { if (children) { return children.map(({ value: children_value }) => { return { [children_value]: [value, children_value] }; }); } return { [value]: [value] }; }) .flat() .reduce((obj, item) => { return { ...obj, ...item }; }, {}); // 选项类型 export const optionTypeList = [ { value: 'letter', label: '字母' }, { value: 'number', label: '数字' }, { value: 'chinese', label: '中文数字' }, ]; // 计算选项方法 export const computeOptionMethods = { [optionTypeList[0].value]: (i) => String.fromCharCode(97 + i), [optionTypeList[1].value]: (i) => i + 1, [optionTypeList[2].value]: (i) => digitToChinese(i + 1), }; /** * 改变选项类型 * @param {object} data 数据 */ export function changeOptionType(data) { let index = optionTypeList.findIndex(({ value }) => value === data.option_number_show_mode); data.option_number_show_mode = optionTypeList[index + 1]?.value || optionTypeList[0].value; } /** * 计算选项题号 * @param {Number} i 序号 * @param {String} option_number_show_mode 选项类型 * @returns String 题号 */ export function computedQuestionNumber(i, option_number_show_mode) { const computationMethod = computeOptionMethods[option_number_show_mode]; if (computationMethod) { return computationMethod(i); } return ''; } // 题干类型 export const stemTypeList = [ { value: 'text', label: '纯文本' }, { value: 'rich', label: '富文本' }, ]; // 分值类型 export const scoreTypeList = [ { value: 'aggregate', label: '总分' }, { value: 'subdivision', label: '细分' }, ]; // 选择类型 export const selectTypeList = [ { value: 'single', label: '单选' }, { value: 'multiple', label: '多选' }, ]; // 开关选项 export const switchOption = [ { value: 'true', label: '开启' }, { value: 'false', label: '关闭' }, ]; // 题号类型 export const questionNumberTypeList = [ { value: 'recalculate', label: '重新计算' }, { value: 'follow', label: '跟随上题' }, ]; export const svgNS = 'http://www.w3.org/2000/svg'; // SVG命名空间