diff --git a/src/components/timer-panel/index.jsx b/src/components/timer-panel/index.jsx index 2135db7..51d9306 100644 --- a/src/components/timer-panel/index.jsx +++ b/src/components/timer-panel/index.jsx @@ -22,6 +22,7 @@ export default ({ identifier, onUpdateCostTime, status, defaultTime = 0,type }) lastV.current = defaultTime setCostTime(defaultTime) //已经评测完成的不需要再计时 + if (status !== 2) { let timeHandler = function () { setCostTime(costTime => costTime + 1) @@ -36,7 +37,20 @@ export default ({ identifier, onUpdateCostTime, status, defaultTime = 0,type }) return () => { clearInterval(tid) unSub() + + if(type===1){ + let bodys = { + answer_long_time: lastV.current*1000, + }; + let headers = { + type: 'application/json', + }; + let blob = new Blob([JSON.stringify(bodys)], headers); + window.navigator.sendBeacon( + `https://test-data.educoder.net/api/myproblems/${identifier}/save_long_time.json?answer_long_time=${lastV.current*1000}`, + blob, + ); mediator.publish('reset-game') return } diff --git a/src/routes/tasks/hack-game/index.jsx b/src/routes/tasks/hack-game/index.jsx index 922671b..ea592d8 100644 --- a/src/routes/tasks/hack-game/index.jsx +++ b/src/routes/tasks/hack-game/index.jsx @@ -1,10 +1,10 @@ import React, { useState, useEffect, useRef, useCallback, Fragment } from 'react' import Editor from './ace-editor' -import Modal from '../../../components/modal' +import Modals from '../../../components/modal' import FooterBar from './footer-bar' import TestCaseList from './test-case-list' import './index.less' -import { fetchWxCode, UpdateHackWxCode, restoreWxHackCode, fetchWxHackCodeGameBuild, sumbitCode, updateCostTime } from '../../../util/rest-api' +import { fetchWxCode, UpdateHackWxCode, restoreWxHackCode, fetchWxHackCodeGameBuild, sumbitCode, updateCostTimes } from '../../../util/rest-api' import { useHistory, Route, Switch, useRouteMatch,useParams } from 'react-router-dom' import { Toast } from 'antd-mobile' import TestResultDialog from './test-result-dialog' @@ -62,6 +62,8 @@ export default ({ source, taskId,callback }) => { const [isShowTest, setIsShowTest] = useState(false) const [isShowResult, setIsShowResult] = useState(false) const [language,setlanguage]=useState() + const [isshow,setisshow]=useState(false); + const [datas,setdatas]=useState(); const [opacity, setOpacity] = useState(1) const [code, setCode] = useState({ content: { @@ -122,7 +124,9 @@ export default ({ source, taskId,callback }) => { fetchWxHackCodeGameBuilds() }, 1000); }else{ - Toast.show(ExecuteDict[rs?.data?.data?.status]) + setdatas(rs?.data?.data); + // Toast.show(ExecuteDict[rs?.data?.data?.status]) + setisshow(true); setTimeout(() => { Toast.hide() }, 3000); @@ -141,7 +145,6 @@ export default ({ source, taskId,callback }) => { } async function onReset() { - debugger if (taskId) { const response = await restoreWxHackCode(taskId,{}) const { data } = response @@ -165,9 +168,9 @@ export default ({ source, taskId,callback }) => { lastedValue.current = window.decodeURIComponent( escape(window.atob(hack?.code))) setEditValue(lastedValue.current) - } if (taskId) { + init() } }, [hack.code]) @@ -181,6 +184,10 @@ export default ({ source, taskId,callback }) => { setOpacity(routeMatch.isExact ? 1 : 0) }, [routeMatch.isExact]) + useEffect(()=>{ + // mediator.publish('update-cost-time') + },[]) + useEffect(() => { document.body.addEventListener('focusout', scrollT) @@ -198,9 +205,9 @@ export default ({ source, taskId,callback }) => { } const timePanelOpt = { identifier: taskId, - // onUpdateCostTime: updateCostTime, + onUpdateCostTime: updateCostTimes, type:1, - defaultTime: hack.answer_long_time, + defaultTime: hack.answer_long_time/1000, status: hack.status } @@ -254,14 +261,14 @@ export default ({ source, taskId,callback }) => { - - {isShowTest ? : null} + + {isshow ? {setisshow(false)}}/> : null} {isShowPath ? : null} {isShowResult ? : null} - + ) diff --git a/src/routes/tasks/hack-game/test-case-list/index.jsx b/src/routes/tasks/hack-game/test-case-list/index.jsx index de5d32f..bac74c7 100644 --- a/src/routes/tasks/hack-game/test-case-list/index.jsx +++ b/src/routes/tasks/hack-game/test-case-list/index.jsx @@ -4,9 +4,18 @@ import markUrl from './mark.svg' import successUrl from '../test-case-item/success.svg' import './index.less' import RenderHtml from '../../../../components/render-html' +import { Base64 } from 'js-base64' +const ExecuteDict = { + [-1]: '测试用例结果不匹配', + [0]: '调试通过', + 2: '调试超时', + 3: '调试pod失败', + 4: '编译失败', + 5: '执行失败' +} -export default ({ test_sets = [], test_sets_count, sets_error_count, last_compile_output, onClose }) => { +export default ({ onClose,datas }) => { const [index, setIndex] = useState(-1) function trigger(id) { @@ -17,10 +26,37 @@ export default ({ test_sets = [], test_sets_count, sets_error_count, last_compil
- 共{test_sets.length}个测试用例 + 执行结果:{ExecuteDict[datas.status]} 关闭
- {last_compile_output ? +
+ 实际输入: +
+ {datas.input} + {/* */} +
+
+
+ 实际输出: +
+ {/* { + (datas.status === 4 || datas.status === 5) && */} + {Base64.decode(datas?.error_msg)} + {/* // } */} + {/* */} +
+
+
+ 预期输出: +
+ {/* { + (datas.status === 4 || datas.status === 5) && */} + {Base64.decode(datas?.expected_output)} + {/* // } */} + {/* */} +
+
+ {/* {last_compile_output ?
@@ -28,10 +64,10 @@ export default ({ test_sets = [], test_sets_count, sets_error_count, last_compil {sets_error_count == 0 ? 全部通过 : }
: null - } -
    + } */} + {/*
      {test_sets.map((item, i) => )} -
    +
*/}
diff --git a/src/util/rest-api.js b/src/util/rest-api.js index 2cd9e0d..67ec0eb 100644 --- a/src/util/rest-api.js +++ b/src/util/rest-api.js @@ -84,6 +84,11 @@ export function updateCostTime(identifier, params) { return axios.post(url, params); } +export function updateCostTimes(identifier, params) { + const url = `/api/myproblems/${identifier}/save_long_time.json`; + return axios.post(url, params); +} + //获取公告详情信息 export function getNoticeDetail(identifier, params) { const url = `/courses/${identifier}/inform_detail.json`;