|
|
|
@ -4,7 +4,7 @@
|
|
|
|
|
* @Github:
|
|
|
|
|
* @Date: 2020-01-15 15:41:10
|
|
|
|
|
* @LastEditors : tangjiang
|
|
|
|
|
* @LastEditTime : 2020-01-16 15:25:25
|
|
|
|
|
* @LastEditTime : 2020-01-17 21:06:46
|
|
|
|
|
*/
|
|
|
|
|
import types from './actionTypes.js';
|
|
|
|
|
import {
|
|
|
|
@ -38,6 +38,7 @@ export const getWXCodeTestCase = (identifier, params) => {
|
|
|
|
|
try{
|
|
|
|
|
const {data = {}} = res;
|
|
|
|
|
console.log(data.test_sets);
|
|
|
|
|
const _path = data.challenge.path;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.GET_WXCODE_TEST_CASE,
|
|
|
|
|
payload: {
|
|
|
|
@ -45,7 +46,7 @@ export const getWXCodeTestCase = (identifier, params) => {
|
|
|
|
|
game_id: data.game && data.game.id,
|
|
|
|
|
myIdentifier: data.myshixun.identifier,
|
|
|
|
|
exec_time: data.challenge.exec_time,
|
|
|
|
|
path: data.challenge.path,
|
|
|
|
|
path: _path.split(';')[0] || _path.split(';')[0],
|
|
|
|
|
last_compile_output: data.last_compile_output,
|
|
|
|
|
test_sets_count: data.test_sets_count,
|
|
|
|
|
sets_error_count: data.sets_error_count
|
|
|
|
@ -103,6 +104,7 @@ export const evaluateWxCode = (identifier, path) => {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const {
|
|
|
|
|
userCode,
|
|
|
|
|
wxCode,
|
|
|
|
|
game_id,
|
|
|
|
|
myIdentifier,
|
|
|
|
|
exec_time,
|
|
|
|
@ -115,61 +117,90 @@ export const evaluateWxCode = (identifier, path) => {
|
|
|
|
|
// build
|
|
|
|
|
// const {} = res;
|
|
|
|
|
console.log(res);
|
|
|
|
|
const _resubmit = res.data.resubmit;
|
|
|
|
|
const params = {
|
|
|
|
|
content_modified: 1,
|
|
|
|
|
sec_key: res.data.sec_key
|
|
|
|
|
first: 1,
|
|
|
|
|
content_modified: userCode !== wxCode ? 1 : 0,
|
|
|
|
|
sec_key: res.data.sec_key,
|
|
|
|
|
resubmit: _resubmit
|
|
|
|
|
}
|
|
|
|
|
console.log(params);
|
|
|
|
|
fetchWxCodeGameBuild(identifier, params).then(res => {
|
|
|
|
|
if (res.data.status === 1) {
|
|
|
|
|
// 定时调用 game_status fetchWxCodeGameStatus
|
|
|
|
|
let count = 1;
|
|
|
|
|
const intervalTime = 500;
|
|
|
|
|
function wxCodeGameStatus (intervalTime, finalTime, count, timer) {
|
|
|
|
|
const excuteTime = (count++) * intervalTime; // 当前执行时间
|
|
|
|
|
console.log(finalTime, count, excuteTime);
|
|
|
|
|
fetchWxCodeGameStatus(identifier).then(r => {
|
|
|
|
|
const { status, test_sets = [] } = r.data;
|
|
|
|
|
if (+status > -1 || ((excuteTime / 1000) > (finalTime + 1))) {
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = null;
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// console.log(params);
|
|
|
|
|
fetchWxCodeGameBuild(identifier, params).then(res => {
|
|
|
|
|
const {status} = res.data;
|
|
|
|
|
if (status === 1) {
|
|
|
|
|
// 定时调用 game_status fetchWxCodeGameStatus
|
|
|
|
|
let count = 1;
|
|
|
|
|
const intervalTime = 500;
|
|
|
|
|
function wxCodeGameStatus (intervalTime, finalTime, count, timer) {
|
|
|
|
|
const excuteTime = (count++) * intervalTime; // 当前执行时间
|
|
|
|
|
console.log(finalTime, count, excuteTime);
|
|
|
|
|
fetchWxCodeGameStatus(identifier, {resubmit: _resubmit}).then(r => {
|
|
|
|
|
const { status, test_sets = [], gold, experience, next_game, sets_error_count } = r.data;
|
|
|
|
|
if (+status > -1 || ((excuteTime / 1000) > (finalTime + 1))) {
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
timer = null;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SHOW_WX_CODE_LOADING,
|
|
|
|
|
payload: false
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// 显示测试集弹框
|
|
|
|
|
// dispatch({
|
|
|
|
|
// type: types.IS_SHOW_WXCODE_TEST_CASES,
|
|
|
|
|
// payload: true
|
|
|
|
|
// });
|
|
|
|
|
// 评测是否通过, 通过 弹通过,否则 弹测试集
|
|
|
|
|
if (status === 2 && sets_error_count === 0) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SET_GOLD_AND_EXPERIENCE,
|
|
|
|
|
payload: {
|
|
|
|
|
gold,
|
|
|
|
|
experience,
|
|
|
|
|
next_game
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SHOW_WX_CODE_DIALOG,
|
|
|
|
|
payload: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.IS_SHOW_WXCODE_TEST_CASES,
|
|
|
|
|
payload: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.GET_WXCODE_TEST_CASE,
|
|
|
|
|
payload: {
|
|
|
|
|
test_sets,
|
|
|
|
|
game_id,
|
|
|
|
|
myIdentifier,
|
|
|
|
|
exec_time,
|
|
|
|
|
path,
|
|
|
|
|
last_compile_output,
|
|
|
|
|
test_sets_count,
|
|
|
|
|
sets_error_count
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, 50);
|
|
|
|
|
}
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SHOW_WX_CODE_LOADING,
|
|
|
|
|
payload: false
|
|
|
|
|
});
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// 显示测试集弹框
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.IS_SHOW_WXCODE_TEST_CASES,
|
|
|
|
|
payload: true
|
|
|
|
|
});
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.GET_WXCODE_TEST_CASE,
|
|
|
|
|
payload: {
|
|
|
|
|
test_sets,
|
|
|
|
|
game_id,
|
|
|
|
|
myIdentifier,
|
|
|
|
|
exec_time,
|
|
|
|
|
path,
|
|
|
|
|
last_compile_output,
|
|
|
|
|
test_sets_count,
|
|
|
|
|
sets_error_count
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, 50);
|
|
|
|
|
}
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SHOW_WX_CODE_LOADING,
|
|
|
|
|
payload: false
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
let timer = setInterval(() => {
|
|
|
|
|
wxCodeGameStatus(intervalTime, exec_time, count++, timer);
|
|
|
|
|
}, intervalTime);
|
|
|
|
|
}
|
|
|
|
|
let timer = setInterval(() => {
|
|
|
|
|
wxCodeGameStatus(intervalTime, exec_time, count++, timer);
|
|
|
|
|
}, intervalTime);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}, 50);
|
|
|
|
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: types.SHOW_WX_CODE_LOADING,
|
|
|
|
@ -193,4 +224,12 @@ export const changeWXCodeEvaluateLoading = (flag) => {
|
|
|
|
|
type: types.SHOW_WX_CODE_LOADING,
|
|
|
|
|
payload: flag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭对话框
|
|
|
|
|
export const changeWXCodeEvaluateDialog = (flag) => {
|
|
|
|
|
return {
|
|
|
|
|
type: types.SHOW_WX_CODE_DIALOG,
|
|
|
|
|
payload: flag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|