+
{
this.state.jupyter_url===null || this.state.jupyter_url===undefined?
(
diff --git a/public/react/src/redux/actions/ojForUser.js b/public/react/src/redux/actions/ojForUser.js
index 9cb814d80..5484b6eec 100644
--- a/public/react/src/redux/actions/ojForUser.js
+++ b/public/react/src/redux/actions/ojForUser.js
@@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-27 13:42:11
* @LastEditors: tangjiang
- * @LastEditTime: 2019-12-19 15:11:56
+ * @LastEditTime: 2019-12-20 10:25:42
*/
import types from "./actionTypes";
import { Base64 } from 'js-base64';
@@ -87,7 +87,7 @@ export const getUserProgramDetail = (identifier, type) => {
type: types.SAVE_USE_TEST_CASE_VALUE,
payload: data.test_case || {}
});
- // 代码是否更新
+ // 代码是否更新
let _modify_code = false;
if (data.hack) {
_modify_code = data.hack.modify_code;
@@ -171,15 +171,103 @@ export const updateCode = (identifier, inputValue, type) => {
}
}
+// 代码评测
+export const codeEvaluate = (dispatch, identifier, type, time_limit) => {
+ // 调试代码成功后,调用轮循接口, 注意: 代码执行的时间要小于设置的时间限制
+ const intervalTime = 500;
+ let count = 1;
+ /**
+ * @param {*} excuteTime 执行时间
+ * @param {*} finalTime 总时间
+ * @param {*} count 执行次数
+ * @param {*} timer 定时器
+ */
+ function getCodeSubmit (intervalTime, finalTime, count, timer){
+ const excuteTime = (count++) * intervalTime; // 当前执行时间
+ fetchCodeSubmit(identifier, { mode: type }).then(res => {
+ const { status } = res.data; // 评测返回结果
+ // 清除定时器条件: 评测通过或者评测时间大于指定时间
+ if (+status === 0 || (excuteTime / 1000) > (finalTime + 1)) {
+ clearInterval(timer); // 清除定时器
+ timer = null;
+ let returnData = null;
+ if (status === 1) { // 结果没有返回
+ returnData = {
+ error_line: -1,
+ error_msg: '',
+ execute_memory: '',
+ execute_time: finalTime,
+ input: '',
+ output: '',
+ status: 2,
+ expected_output: ''
+ };
+ } else { // 成功返回结果
+ returnData = res.data.data;
+ }
+ // 返回评测结果
+ dispatch({
+ type: types.COMMIT_RECORD_DETAIL,
+ payload: returnData
+ });
+ if (!type || type === 'debug') {
+ dispatch({ // 改变 loading 值
+ type: types.LOADING_STATUS,
+ payload: false
+ });
+ // 保存执行状态
+ dispatch({
+ type: types.TEST_CODE_STATUS,
+ payload: 'finish'
+ });
+ } else {
+ // 回滚提交按钮状态
+ dispatch({
+ type: types.SUBMIT_LOADING_STATUS,
+ payload: false
+ });
+ // 改变tab值至提交记录(只在提交时才跳转,测评时,切换到代码执行结果就可以了)
+ dispatch({
+ type: types.CHANGE_USER_CODE_TAB,
+ payload: 'record'
+ });
+ // 重新调用一下提交记录接口
+ dispatch(getUserCommitRecord(identifier));
+ }
+ }
+ }).catch(err => { // 评测异常时
+ // 清除定时器
+ clearInterval(timer);
+ timer = null;
+ // 回滚按钮状态
+ if (!type || type === 'debug') {
+ dispatch({ // 改变 loading 值
+ type: types.LOADING_STATUS,
+ payload: false
+ });
+ } else { // 回滚提交按钮状态
+ dispatch({
+ type: types.SUBMIT_LOADING_STATUS,
+ payload: false
+ });
+ }
+ });
+ }
+ // 开启定时器,调用监听接口
+ let timer = setInterval(() => {
+ getCodeSubmit(intervalTime, time_limit, count++, timer);
+ }, intervalTime);
+}
+
/**
* @description 调试代码
- * @param {*} identifier
+ * @param {*} identifier
* @param {*} inputValue 输入值: 自定义 | 系统返回的
* @param {*} type 测评类型 debug | submit
*/
export const debuggerCode = (identifier,value, type) => {
return (dispatch, getState) => {
- // 调用之前 先保存 code
+ // 调用之前 先保存 code
// TODO
// console.log(identifier, value);
const {hack: {time_limit = 0}} = getState().ojForUserReducer;
@@ -194,15 +282,6 @@ export const debuggerCode = (identifier,value, type) => {
// console.log('调用调试代码成功并返回结果: ', res);
const { status } = res;
if (status === 200) {
- // 调试代码成功后,调用轮循接口, 注意: 代码执行的时间要小于设置的时间限制
- const intervalTime = 500;
- let count = 1;
- /**
- * @param {*} excuteTime 执行时间
- * @param {*} finalTime 总时间
- * @param {*} count 执行次数
- * @param {*} timer 定时器
- */
if (res.data.status === 401) {
dispatch({ // 改变 loading 值
type: types.LOADING_STATUS,
@@ -210,81 +289,8 @@ export const debuggerCode = (identifier,value, type) => {
});
return;
};
- function getCodeSubmit (intervalTime, finalTime, count, timer){
- const excuteTime = (count++) * intervalTime; // 当前执行时间
- fetchCodeSubmit(identifier, { mode: type }).then(res => {
- const { status } = res.data; // 评测返回结果
- // 清除定时器条件: 评测通过或者评测时间大于指定时间
- if (+status === 0 || (excuteTime / 1000) > (finalTime + 1)) {
- clearInterval(timer); // 清除定时器
- timer = null;
- let returnData = null;
- if (status === 1) { // 结果没有返回
- returnData = {
- error_line: -1,
- error_msg: '',
- execute_memory: '',
- execute_time: finalTime,
- input: '',
- output: '',
- status: 2,
- expected_output: ''
- };
- } else { // 成功返回结果
- returnData = res.data.data;
- }
- // 返回评测结果
- dispatch({
- type: types.COMMIT_RECORD_DETAIL,
- payload: returnData
- });
- if (!type || type === 'debug') {
- dispatch({ // 改变 loading 值
- type: types.LOADING_STATUS,
- payload: false
- });
- // 保存执行状态
- dispatch({
- type: types.TEST_CODE_STATUS,
- payload: 'finish'
- });
- } else {
- // 回滚提交按钮状态
- dispatch({
- type: types.SUBMIT_LOADING_STATUS,
- payload: false
- });
- // 改变tab值至提交记录(只在提交时才跳转,测评时,切换到代码执行结果就可以了)
- dispatch({
- type: types.CHANGE_USER_CODE_TAB,
- payload: 'record'
- });
- // 重新调用一下提交记录接口
- dispatch(getUserCommitRecord(identifier));
- }
- }
- }).catch(err => { // 评测异常时
- // 清除定时器
- clearInterval(timer);
- timer = null;
- // 回滚按钮状态
- if (!type || type === 'debug') {
- dispatch({ // 改变 loading 值
- type: types.LOADING_STATUS,
- payload: false
- });
- } else { // 回滚提交按钮状态
- dispatch({
- type: types.SUBMIT_LOADING_STATUS,
- payload: false
- });
- }
- });
- }
- // 开启定时器,调用监听接口
- let timer = setInterval(() => {
- getCodeSubmit(intervalTime, time_limit, count++, timer);
- }, intervalTime);
+ // 测评
+ codeEvaluate(dispatch, identifier, type, time_limit);
}
}).catch(() => {
dispatch({
@@ -362,7 +368,8 @@ export const changeUserCodeTab = (key) => {
*/
export const submitUserCode = (identifier, inputValue, type) => {
return (dispatch, getState) => {
- const { userCode, isUpdateCode } = getState().ojForUserReducer;
+ const { userCode, isUpdateCode, hack: {time_limit = 0} } = getState().ojForUserReducer;
+
function userCodeSubmit () {
fetchUserCodeSubmit(identifier).then(res => {
// console.log('用户提交代码成功======》》》》》', res);
@@ -374,12 +381,8 @@ export const submitUserCode = (identifier, inputValue, type) => {
});
return;
};
- // 将编辑代码清空
- dispatch({
- type: types.SAVE_EDITOR_CODE,
- payload: ''
- });
- dispatch(debuggerCode(identifier, inputValue, type || 'submit'));
+ // 测评
+ codeEvaluate(dispatch, identifier, type, time_limit);
}
}).catch(() => {
dispatch({
diff --git a/public/react/src/services/ojService.js b/public/react/src/services/ojService.js
index 373805b73..e552c1211 100644
--- a/public/react/src/services/ojService.js
+++ b/public/react/src/services/ojService.js
@@ -4,11 +4,10 @@
* @Github:
* @Date: 2019-11-20 10:55:38
* @LastEditors: tangjiang
- * @LastEditTime: 2019-12-17 14:10:37
+ * @LastEditTime: 2019-12-20 10:10:53
*/
import axios from 'axios';
-import { func } from 'prop-types';
export async function fetchOJList (params) {
console.log('传递的参数: ', params);
@@ -137,4 +136,4 @@ export async function fetchUploadImage (file) {
export async function fetchUploadImageUrl (id) {
const url = `/attachments/${id}`;
return axios.get(url);
-}
+}