diff --git a/.env b/.env index 783e5c0..97571e0 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ VITE_APP_TITLE=金融产品设计及数字化营销沙盘 VITE_PORT=9520 VITE_PROXY=http://192.168.31.125:8080 VITE_PUBLIC_PATH=./ -# VITE_BASE_API=http://192.168.31.217:9000 -VITE_BASE_API=http://121.37.12.51 +VITE_BASE_API=http://192.168.31.217:9000 +# VITE_BASE_API=http://121.37.12.51 VITE_I18N_LOCALE=zh-cn VITE_I18N_FALLBACK_LOCALE=zh-cn diff --git a/src/api/system.ts b/src/api/system.ts index 210dba4..d8b0ff3 100644 --- a/src/api/system.ts +++ b/src/api/system.ts @@ -14,3 +14,5 @@ export const exportBankExperimentReport = async (data: Record): Pro export const updateReport = async (data: Record): Promise => (await axios.post('/occupationlab/occupationlab/achievement/updateReport', data)).data; export const editExperimentalData = async (data: Record): Promise => (await axios.post('/occupationlab/occupationlab/experimentalReport/editExperimentalData', data)).data; +export const getStartTime = async (params: Record): Promise => (await axios.get('/python/python/getStartTime', { params })).data; +export const getCurrentTime = async (params: Record): Promise => (await axios.get('/competition/competition/management/getCurrentTime', { params })).data; diff --git a/src/components/Panel/index.vue b/src/components/Panel/index.vue index 6ea0e58..a0c1963 100644 --- a/src/components/Panel/index.vue +++ b/src/components/Panel/index.vue @@ -225,7 +225,7 @@ import { ref, reactive, onMounted, inject, computed, watch } from 'vue'; import { submitOpe } from '@/api/bank'; import { deleteCache } from '@/api/judgment'; -import { pageStuAssessment, getProjectBySystemId, getProjectDetail, getDetailById, getCompetition } from '@/api/system'; +import { pageStuAssessment, getProjectBySystemId, getProjectDetail, getDetailById, getCompetition, getStartTime, getCurrentTime } from '@/api/system'; import Settings from '@/settings'; import { useRouter, useRoute } from 'vue-router'; import type { Action } from 'element-plus'; @@ -237,6 +237,7 @@ import { mavonEditor } from 'mavon-editor'; import 'mavon-editor/dist/css/index.css'; import '@vueup/vue-quill/dist/vue-quill.snow.css'; import { useDraggable } from '@vueuse/core'; +import { logout } from '@/store/useCurrentUser'; const router = useRouter(); const route = useRoute(); @@ -263,7 +264,6 @@ const judgmentId = ref(''); const curReq = ref[]>([]); const taskList = ref[]>([]); const pannelTab = ref('first'); -const statusTimer = ref(null); const submiting = ref(false); const reportId = ref(''); const countVal = ref(''); @@ -293,12 +293,13 @@ if (param.token) { Cookies.set('sand-stageId', param.stageId ?? ''); Cookies.set('sand-teamId', param.teamId ?? ''); Cookies.set('sand-mallId', param.mallId ?? ''); - Cookies.set('sand-endTime', param.endTime ?? ''); Cookies.set('sand-referrer', param.referrer ?? ''); Cookies.set('sand-className', param.className ?? ''); Cookies.set('sand-startTime', param.startTime ?? ''); Cookies.set('sand-resultsDetails', param.resultsDetails ?? ''); Cookies.set('sand-resultAnnouncementTime', param.resultAnnouncementTime ?? ''); + Cookies.set('sand-curriculumName', param.curriculumName ?? ''); + Cookies.set('sand-stopTime', param.stopTime ?? ''); Cookies.set('sand-admin', param.admin ?? ''); // 从中台进来的标识 Cookies.remove('sand-submit'); router.replace(route.path); @@ -312,11 +313,12 @@ if (param.token) { param.stageId = Cookies.get('sand-stageId'); param.teamId = Cookies.get('sand-teamId'); param.mallId = Cookies.get('sand-mallId'); - param.endTime = Cookies.get('sand-endTime'); param.className = Cookies.get('sand-className'); param.startTime = Cookies.get('sand-startTime'); param.resultsDetails = Cookies.get('sand-resultsDetails'); param.resultAnnouncementTime = Cookies.get('sand-resultAnnouncementTime'); + param.curriculumName = Cookies.get('sand-curriculumName'); + param.stopTime = Cookies.get('sand-stopTime'); isSubmit.value = Cookies.get('sand-submit') === 'true'; } if (param.projectId) param.projectId = +param.projectId; @@ -332,6 +334,23 @@ watch( }, ); +// 获取上次实验的时间 +const getSumTime = () => { + return new Promise(async (resolve, reject) => { + const res = await getStartTime({ + permissions: per.value, + projectId: param.projectId, + }); + resolve(res.startTime ? new Date(res.startTime) : ''); + }); +}; +// 获取当前时间 +const getNow = () => { + return new Promise(async (resolve, reject) => { + const res = await getCurrentTime(); + resolve(new Date(res.currentTime)); + }); +}; // 倒计时 const timeFormat = (num: number): string | number => { return num < 10 ? `0${num}` : num; @@ -370,23 +389,22 @@ const setSubmit = (val: boolean) => { }; // 获取考核列表来查询该考核是否已经考过 const getAssList = async () => { - const { list } = await pageStuAssessment({ - pageNum: 1, - pageSize: 10000, - }); - let done = false; - // 匹配到该考核,并且已经提交过(有reportId则说明有实验记录),并且classId跟当前用户的classId相同,就提示提交了考核然后返回上一页 - if (list.find((e) => e.assessmentId == param.assessmentId && e.reportId && e.classId == param.classId)) { - done = true; - setSubmit(true); - ElMessage.error('你已经提交过该考核!'); - setTimeout((_) => { - window.history.back(); // 直接返回上一页面 - }, 1500); - } - statusTimer.value = setInterval((_) => { - getAssStatus(); - }, 1000); + // const { list } = await pageStuAssessment({ + // pageNum: 1, + // pageSize: 10000, + // }); + // let done = false; + // // 匹配到该考核,并且已经提交过(有reportId则说明有实验记录),并且classId跟当前用户的classId相同,就提示提交了考核然后返回上一页 + // if (list.find((e) => e.assessmentId == param.assessmentId && e.reportId && e.classId == param.classId)) { + // done = true; + // setSubmit(true); + // ElMessage.error('你已经提交过该考核!'); + // setTimeout((_) => { + // window.history.back(); // 直接返回上一页面 + // }, 1500); + // } + getProDetail(); + getAssStatus(); }; // 定时查询考核状态(查到考核如果结束后,直接提交考核) const getAssStatus = async () => { @@ -396,7 +414,6 @@ const getAssStatus = async () => { const done = data ? data.status === 2 : false; // 状态(0、待开始 1、进行中 2、已结束) // 如果考核已结束,则清除查询考核状态的定时器,并且自动提交 if (done) { - clearInterval(statusTimer.value); // this.$alert('考核时间已到,系统已自动交卷', '提示', { // confirmButtonText: '确定', // }); @@ -413,18 +430,18 @@ const getCompetitionStatus = async () => { const stages = competition.competitionStage; if (stages) { const stage = stages.find((e) => e.stageId == param.stageId); - const endTime = new Date(stage.endTime).getTime(); - const now = Date.now(); + const endTime = new Date(stage.endTime); + const now = await getNow(); // 如果已经结束 - if (now >= new Date(stage.endTime)) { - clearInterval(statusTimer.value); + if (now >= endTime) { // this.$alert('竞赛时间已到,系统已自动交卷', '提示', { // confirmButtonText: '确定', // }); submit(); } else { - // 没结束,则显示倒计时(竞赛才需要通过定时调接口来显示倒计时,因为中台可以修改结束时间,所以需要时刻获取最新的结束时间) - counter((endTime - now) / 1000); + // 没结束,则显示倒计时 + countVal.value = (endTime - now) / 1000; + startCount(); } } } @@ -476,8 +493,8 @@ const submit = async () => { classId: param.classId ? param.classId : '', className: param.className ? param.className : '', curriculumId: param.cid, - startTime: per.value ? param.startTime : dayjs(entryTime.value).format('YYYY-MM-DD HH:mm:ss'), // 开始时间(考核:直接从职站取考核的开始时间;练习:取页面进入的时间) - endTime: per.value ? param.endTime : submitTime, // 结束时间(考核:直接从职站取考核的结束时间;练习:取提交时间) + startTime: dayjs(entryTime.value).format('YYYY-MM-DD HH:mm:ss'), // 取页面进入的时间 + endTime: per.value ? param.stopTime : submitTime, // 结束时间(考核:直接从职站取考核的结束时间;练习:取提交时间) submitTime, // 提交时间,即当前时间(这3个时间都是传完整的日期时间格式) timeSum, checkpointId: Cookies.get('sand-level') ?? '', @@ -493,13 +510,11 @@ const submit = async () => { mallId: param.mallId, }); setSubmit(true); - clearInterval(statusTimer.value); let score = 0; // 给判分列表添加分数和运行结果 taskList.value.map((e) => { const item = retMap?.scoreInfo.find((n) => n.lcId === e.judgmentId); - console.log('🚀 ~ taskList.value.map ~ item:', item); try { if (item) { e.examScore = item.questionScore; @@ -516,16 +531,12 @@ const submit = async () => { localStorage.setItem('sand-taskList', JSON.stringify(taskList.value)); submiting.value = false; - // 如果是竞赛,并且勾选了公布成绩详情的选项,则弹框提示 - param.competitionId && - param.resultsDetails == 0 && - ElMessageBox.alert(`提交成功${param.resultAnnouncementTime != 0 ? ',成绩将在' + param.resultAnnouncementTime + '小时后发布,请去参赛信息模块查看' : ''}`, '提示', { + // 非练习 + per.value && + ElMessageBox.alert(`提交成功${param.resultsDetails == 0 && param.resultAnnouncementTime != 0 ? ',成绩将在' + param.resultAnnouncementTime + '小时后发布,请去参赛信息模块查看' : ''}`, '提示', { confirmButtonText: '确定', callback: (action: Action) => { - ElMessage({ - type: 'info', - message: `action: ${action}`, - }); + logout(); }, }); }) @@ -563,7 +574,8 @@ const getProDetail = async () => { text.value = isPrac ? '已用' : '剩余'; // 竞赛不需要 if (!param.competitionId && !isSubmit.value) { - countVal.value = isPrac ? 0 : (new Date(param.endTime).getTime() - Date.now()) / 1000; // 如果是考核,取考核的结束时间减去当前时间去做倒计时,练习则直接给0做计时 + const now = await getNow(); + countVal.value = (isPrac ? now - entryTime.value : new Date(param.stopTime).getTime() - now) / 1000; // 如果是考核,取考核的结束时间减去当前时间去做倒计时,练习则直接取当前时间减去上次进来的时间做计时 startCount(); } }; @@ -580,18 +592,24 @@ const getList = async () => { if (!per.value && !param.projectId) param.projectId = projects[0]?.projectId ?? 0; // 默认取第一个项目 getProDetail(); }; +// 获取进入时间 +const getEntryTime = async () => { + let now = await getSumTime(); // 获取上次进入实验的时间,如果没有,说明是第一次进入,然后直接从服务器获取当前时间 + if (!now) now = await getNow(); + entryTime.value = now; +}; onMounted(() => { getLevel.value = inject('getLevel'); // 关卡页面获取关卡方法 per.value = param.assessmentId ? 1 : param.competitionId ? 2 : 0; + + param.cid && getEntryTime(); + if (param.assessmentId) { getAssList(); } else { param.cid && getList(); if (param.competitionId) { - clearInterval(statusTimer); - statusTimer.value = setInterval((_) => { - getCompetitionStatus(); - }, 1000); + getCompetitionStatus(); } } }); diff --git a/src/layout/components/AppSidebar/index.vue b/src/layout/components/AppSidebar/index.vue index 8802e8a..8f2f56c 100644 --- a/src/layout/components/AppSidebar/index.vue +++ b/src/layout/components/AppSidebar/index.vue @@ -25,6 +25,8 @@ center>
- diff --git a/src/views/product/interestRate/936.vue b/src/views/product/interestRate/936.vue index d92c825..bd48981 100644 --- a/src/views/product/interestRate/936.vue +++ b/src/views/product/interestRate/936.vue @@ -16,7 +16,7 @@ -