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);
|
}
|