|
|
|
@ -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';
|
|
|
|
@ -171,29 +171,8 @@ export const updateCode = (identifier, inputValue, type) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 调试代码
|
|
|
|
|
* @param {*} identifier
|
|
|
|
|
* @param {*} inputValue 输入值: 自定义 | 系统返回的
|
|
|
|
|
* @param {*} type 测评类型 debug | submit
|
|
|
|
|
*/
|
|
|
|
|
export const debuggerCode = (identifier,value, type) => {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
// 调用之前 先保存 code
|
|
|
|
|
// TODO
|
|
|
|
|
// console.log(identifier, value);
|
|
|
|
|
const {hack: {time_limit = 0}} = getState().ojForUserReducer;
|
|
|
|
|
if (!type || type === 'debug') {
|
|
|
|
|
dispatch({ // 加载中...
|
|
|
|
|
type: types.TEST_CODE_STATUS,
|
|
|
|
|
payload: 'loading'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetchDebuggerCode(identifier, value).then(res => {
|
|
|
|
|
// console.log('调用调试代码成功并返回结果: ', res);
|
|
|
|
|
const { status } = res;
|
|
|
|
|
if (status === 200) {
|
|
|
|
|
// 代码评测
|
|
|
|
|
export const codeEvaluate = (dispatch, identifier, type, time_limit) => {
|
|
|
|
|
// 调试代码成功后,调用轮循接口, 注意: 代码执行的时间要小于设置的时间限制
|
|
|
|
|
const intervalTime = 500;
|
|
|
|
|
let count = 1;
|
|
|
|
@ -203,13 +182,6 @@ export const debuggerCode = (identifier,value, type) => {
|
|
|
|
|
* @param {*} count 执行次数
|
|
|
|
|
* @param {*} timer 定时器
|
|
|
|
|
*/
|
|
|
|
|
if (res.data.status === 401) {
|
|
|
|
|
dispatch({ // 改变 loading 值
|
|
|
|
|
type: types.LOADING_STATUS,
|
|
|
|
|
payload: false
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
function getCodeSubmit (intervalTime, finalTime, count, timer){
|
|
|
|
|
const excuteTime = (count++) * intervalTime; // 当前执行时间
|
|
|
|
|
fetchCodeSubmit(identifier, { mode: type }).then(res => {
|
|
|
|
@ -285,6 +257,40 @@ export const debuggerCode = (identifier,value, type) => {
|
|
|
|
|
let timer = setInterval(() => {
|
|
|
|
|
getCodeSubmit(intervalTime, time_limit, count++, timer);
|
|
|
|
|
}, intervalTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description 调试代码
|
|
|
|
|
* @param {*} identifier
|
|
|
|
|
* @param {*} inputValue 输入值: 自定义 | 系统返回的
|
|
|
|
|
* @param {*} type 测评类型 debug | submit
|
|
|
|
|
*/
|
|
|
|
|
export const debuggerCode = (identifier,value, type) => {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
// 调用之前 先保存 code
|
|
|
|
|
// TODO
|
|
|
|
|
// console.log(identifier, value);
|
|
|
|
|
const {hack: {time_limit = 0}} = getState().ojForUserReducer;
|
|
|
|
|
if (!type || type === 'debug') {
|
|
|
|
|
dispatch({ // 加载中...
|
|
|
|
|
type: types.TEST_CODE_STATUS,
|
|
|
|
|
payload: 'loading'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetchDebuggerCode(identifier, value).then(res => {
|
|
|
|
|
// console.log('调用调试代码成功并返回结果: ', res);
|
|
|
|
|
const { status } = res;
|
|
|
|
|
if (status === 200) {
|
|
|
|
|
if (res.data.status === 401) {
|
|
|
|
|
dispatch({ // 改变 loading 值
|
|
|
|
|
type: types.LOADING_STATUS,
|
|
|
|
|
payload: false
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
// 测评
|
|
|
|
|
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({
|
|
|
|
|