| | |
| | | import type { Difficulty, QuestionStatus, QuestionType, SourceType } from './types'; |
| | | import { ref } from 'vue'; |
| | | |
| | | export const QUESTION_TYPE_OPTIONS: { id: QuestionType; fullName: string }[] = [ |
| | | { id: 'single', fullName: '单选题' }, |
| | | { id: 'multi', fullName: '多选题' }, |
| | | { id: 'judge', fullName: '判断题' }, |
| | | { id: 'blank', fullName: '填空题' }, |
| | | { id: 'essay', fullName: '问答题' }, |
| | | ]; |
| | | import { useBaseStore } from '#/store'; |
| | | import { TMS_DIC, labelOfDic, loadTmsDic, type TmsDicOpt } from '#/views/x/tms/shared/dic'; |
| | | |
| | | export const DIFFICULTY_OPTIONS: { id: Difficulty; fullName: string }[] = [ |
| | | { id: 'easy', fullName: '简单' }, |
| | | { id: 'normal', fullName: '一般' }, |
| | | { id: 'hard', fullName: '困难' }, |
| | | ]; |
| | | type StatusOpt = TmsDicOpt & { tip?: string; tipColor?: string }; |
| | | |
| | | export const SOURCE_OPTIONS: { id: SourceType; fullName: string }[] = [ |
| | | { id: 'self', fullName: '自主命题' }, |
| | | { id: 'import', fullName: '导入' }, |
| | | { id: 'external', fullName: '外购' }, |
| | | ]; |
| | | function withStatusTip(list: TmsDicOpt[]): StatusOpt[] { |
| | | return list.map((x) => { |
| | | const code = x.enCode || x.id; |
| | | if (code === 'open') return { ...x, tip: '学生可以模拟', tipColor: 'green' }; |
| | | if (code === 'closed') return { ...x, tip: '学生不能模拟', tipColor: 'red' }; |
| | | return x; |
| | | }); |
| | | } |
| | | |
| | | export const STATUS_OPTIONS: { id: QuestionStatus; fullName: string; tip?: string; tipColor?: string }[] = [ |
| | | { id: 'open', fullName: '开放', tip: '学生可以模拟', tipColor: 'green' }, |
| | | { id: 'closed', fullName: '不开放', tip: '学生不能模拟', tipColor: 'red' }, |
| | | { id: 'invalid', fullName: '废弃' }, |
| | | ]; |
| | | export const QUESTION_TYPE_OPTIONS = ref<TmsDicOpt[]>([]); |
| | | export const DIFFICULTY_OPTIONS = ref<TmsDicOpt[]>([]); |
| | | export const SOURCE_OPTIONS = ref<TmsDicOpt[]>([]); |
| | | export const STATUS_OPTIONS = ref<StatusOpt[]>([]); |
| | | |
| | | export async function loadQuestionDics() { |
| | | const baseStore = useBaseStore(); |
| | | const [questionType, difficulty, source, status] = await Promise.all([ |
| | | loadTmsDic(baseStore, TMS_DIC.questionType), |
| | | loadTmsDic(baseStore, TMS_DIC.difficulty), |
| | | loadTmsDic(baseStore, TMS_DIC.questionSource), |
| | | loadTmsDic(baseStore, TMS_DIC.openClosedInvalid), |
| | | ]); |
| | | QUESTION_TYPE_OPTIONS.value = questionType; |
| | | DIFFICULTY_OPTIONS.value = difficulty; |
| | | SOURCE_OPTIONS.value = source; |
| | | STATUS_OPTIONS.value = withStatusTip(status); |
| | | } |
| | | |
| | | export const OPTION_LABELS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); |
| | | |
| | | export function labelOfType(type?: string) { |
| | | return QUESTION_TYPE_OPTIONS.find((x) => x.id === type)?.fullName ?? type ?? '-'; |
| | | return labelOfDic(QUESTION_TYPE_OPTIONS.value, type); |
| | | } |
| | | |
| | | export function labelOfStatus(status?: string) { |
| | | return STATUS_OPTIONS.find((x) => x.id === status)?.fullName ?? status ?? '-'; |
| | | return labelOfDic(STATUS_OPTIONS.value, status); |
| | | } |
| | | |
| | | export function labelOfDifficulty(v?: string) { |
| | | return DIFFICULTY_OPTIONS.find((x) => x.id === v)?.fullName ?? v ?? '-'; |
| | | return labelOfDic(DIFFICULTY_OPTIONS.value, v); |
| | | } |
| | | |
| | | export function labelOfSource(v?: string) { |
| | | return SOURCE_OPTIONS.find((x) => x.id === v)?.fullName ?? v ?? '-'; |
| | | return labelOfDic(SOURCE_OPTIONS.value, v); |
| | | } |