刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { ref } from 'vue';
 
import { useBaseStore } from '#/store';
import {
  TMS_DIC,
  labelOfDic,
  labelOfPassFlagOpts,
  loadTmsDic,
  type TmsDicOpt,
} from '#/views/x/tms/shared/dic';
 
/**
 * 答卷状态颜色:
 * notStarted=未开考 / doing=答题中 / submitted=已交卷 / cancelled=已取消
 */
const STATUS_COLOR: Record<string, string> = {
  notStarted: '#8c8c8c',
  doing: '#1890ff',
  submitted: '#52c41a',
  cancelled: '#ff4d4f',
};
 
/** 未开考:与后端 TmsExamStatus.NOT_STARTED 一致;字典缺失时前端兜底 */
const NOT_STARTED: TmsDicOpt = { id: 'notStarted', enCode: 'notStarted', fullName: '未开考' };
 
export const MY_PAPER_STATUS_OPTIONS = ref<TmsDicOpt[]>([NOT_STARTED]);
export const PASS_FLAG_OPTIONS = ref<TmsDicOpt[]>([]);
export const GRADE_STATUS_OPTIONS = ref<TmsDicOpt[]>([]);
 
/** 是否合格(含未出结果) */
export const PASS_FLAG_QUERY_OPTIONS = ref<TmsDicOpt[]>([
  { id: 'none', enCode: 'none', fullName: '未出结果' },
]);
 
/** 考试类型:首考 / 补考(规范外,前端态) */
export const ATTEMPT_TYPE_OPTIONS: TmsDicOpt[] = [
  { id: 'first', enCode: 'first', fullName: '首考' },
  { id: 'retake', enCode: 'retake', fullName: '补考' },
];
 
/** 可补考(规范外文案) */
export const CAN_RETAKE_OPTIONS: TmsDicOpt[] = [
  { id: '1', enCode: '1', fullName: '可补考' },
  { id: '0', enCode: '0', fullName: '不可补考' },
];
 
export async function loadOnlineExamDics() {
  const baseStore = useBaseStore();
  const [examStatus, passFlag, gradeStatus] = await Promise.all([
    loadTmsDic(baseStore, TMS_DIC.examStatus),
    loadTmsDic(baseStore, TMS_DIC.passFlag),
    loadTmsDic(baseStore, TMS_DIC.gradeStatus),
  ]);
  const rest = examStatus.filter((x) => (x.enCode || x.id) !== 'notStarted');
  MY_PAPER_STATUS_OPTIONS.value = [NOT_STARTED, ...rest];
  PASS_FLAG_OPTIONS.value = passFlag;
  GRADE_STATUS_OPTIONS.value = gradeStatus;
  PASS_FLAG_QUERY_OPTIONS.value = [
    ...passFlag.map((x) => ({
      ...x,
      enCode: x.enCode || x.id,
      fullName: x.fullName || x.enCode || x.id,
    })),
    { id: 'none', enCode: 'none', fullName: '未出结果' },
  ];
}
 
export function labelOfMyPaperStatus(v?: string) {
  return labelOfDic(MY_PAPER_STATUS_OPTIONS.value, v);
}
 
export function colorOfMyPaperStatus(v?: string) {
  return (v && STATUS_COLOR[v]) || undefined;
}
 
export function labelOfPassFlag(v?: string | null) {
  return labelOfPassFlagOpts(PASS_FLAG_OPTIONS.value, v);
}
 
export function colorOfPassFlag(v?: string | null) {
  const code = String(v || '').trim().toLowerCase();
  if (code === '1' || code === 'pass') return '#52c41a';
  if (code === '0' || code === 'fail') return '#ff4d4f';
  return undefined;
}
 
export function labelOfGradeStatus(v?: string | null) {
  return labelOfDic(GRADE_STATUS_OPTIONS.value, v);
}