liuyu
22 小时以前 8534025c45b4736975730678b9ccf23570a75f95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ref } from 'vue';
 
import { useBaseStore } from '#/store';
import { TMS_DIC, labelOfDic, loadTmsDic, type TmsDicOpt } from '#/views/x/tms/shared/dic';
 
type StatusOpt = TmsDicOpt & { tip?: string; tipColor?: string };
 
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 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 labelOfDic(QUESTION_TYPE_OPTIONS.value, type);
}
 
export function labelOfStatus(status?: string) {
  return labelOfDic(STATUS_OPTIONS.value, status);
}
 
export function labelOfDifficulty(v?: string) {
  return labelOfDic(DIFFICULTY_OPTIONS.value, v);
}
 
export function labelOfSource(v?: string) {
  return labelOfDic(SOURCE_OPTIONS.value, v);
}