liuyu
22 小时以前 93c133349a5ccd7a328371fa113dce69d5611f21
apps/jnpf-web-apps-main/src/views/x/tms/onlineExam/constants.ts
@@ -1,19 +1,58 @@
import type { MyPaperStatus } from './types';
import { ref } from 'vue';
export const MY_PAPER_STATUS_OPTIONS: {
  id: MyPaperStatus;
  fullName: string;
  color?: string;
}[] = [
  { id: 'notStarted', fullName: '未开始', color: '#8c8c8c' },
  { id: 'doing', fullName: '考试中', color: '#1890ff' },
  { id: 'submitted', fullName: '已交卷', color: '#52c41a' },
];
import { useBaseStore } from '#/store';
import { TMS_DIC, labelOfDic, loadTmsDic, type TmsDicOpt } from '#/views/x/tms/shared/dic';
/** 我的试卷「未开始」为前端态,字典 tmsExamStatus 不含该项 */
const NOT_STARTED: TmsDicOpt = { id: 'notStarted', enCode: 'notStarted', fullName: '未开始' };
const STATUS_COLOR: Record<string, string> = {
  notStarted: '#8c8c8c',
  doing: '#1890ff',
  submitted: '#52c41a',
  cancelled: '#ff4d4f',
};
export const MY_PAPER_STATUS_OPTIONS = ref<TmsDicOpt[]>([NOT_STARTED]);
export const PASS_FLAG_OPTIONS = ref<TmsDicOpt[]>([]);
export async function loadOnlineExamDics() {
  const baseStore = useBaseStore();
  const [examStatus, passFlag] = await Promise.all([
    loadTmsDic(baseStore, TMS_DIC.examStatus),
    loadTmsDic(baseStore, TMS_DIC.passFlag),
  ]);
  const rest = examStatus.filter((x) => (x.enCode || x.id) !== 'notStarted');
  MY_PAPER_STATUS_OPTIONS.value = [NOT_STARTED, ...rest];
  PASS_FLAG_OPTIONS.value = passFlag;
}
export function labelOfMyPaperStatus(v?: string) {
  return MY_PAPER_STATUS_OPTIONS.find((x) => x.id === v)?.fullName ?? v ?? '-';
  return labelOfDic(MY_PAPER_STATUS_OPTIONS.value, v);
}
export function colorOfMyPaperStatus(v?: string) {
  return MY_PAPER_STATUS_OPTIONS.find((x) => x.id === v)?.color;
  return (v && STATUS_COLOR[v]) || undefined;
}
export function labelOfPassFlag(v?: string | null) {
  if (v == null || v === '') return '-';
  const code = String(v);
  if (code === '1') return '合格';
  if (code === '0') return '不合格';
  return labelOfDic(PASS_FLAG_OPTIONS.value, code);
}
export function colorOfPassFlag(v?: string | null) {
  if (v === '1') return '#52c41a';
  if (v === '0') return '#ff4d4f';
  return undefined;
}
export function labelOfGradeStatus(v?: string | null) {
  if (!v) return '-';
  if (v === 'auto') return '自动阅卷';
  if (v === 'pending') return '待阅卷';
  if (v === 'graded') return '已阅卷';
  return v;
}