You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.4 KiB
118 lines
3.4 KiB
/*
|
|
* @Description: 用户编程信息
|
|
* @Author: tangjiang
|
|
* @Github:
|
|
* @Date: 2019-11-27 13:41:48
|
|
* @LastEditors: tangjiang
|
|
* @LastEditTime: 2019-12-05 13:37:17
|
|
*/
|
|
import types from "../actions/actionTypes";
|
|
import { Base64 } from 'js-base64';
|
|
|
|
const initialState = {
|
|
user_program_identifier: '', // 开启OJ题的唯一标题
|
|
hack: {}, // 编程题主要内容
|
|
test_case: {}, // 测试用例
|
|
commitRecordDetail: {}, // 提交成功后记录提交的详情
|
|
commitRecord: [], // 提交记录
|
|
userCode: '', // 保存当前用户输入的代码
|
|
isUpdateCode: false, // 是否更新了代码内容
|
|
userCodeTab: 'task', // 学员测评tab位置: task | record | comment
|
|
userTestInput: '', // 用户自定义输入值
|
|
recordDetail: {}, // 根据id号获取的记录详情
|
|
};
|
|
|
|
const ojForUserReducer = (state = initialState, action) => {
|
|
let tempDetail = null;
|
|
switch (action.type) {
|
|
case types.SAVE_USER_PROGRAM_ID:
|
|
return {
|
|
...state,
|
|
user_program_identifier: action.payload
|
|
}
|
|
case types.USER_PROGRAM_DETAIL:
|
|
const { hack, test_case } = action.payload;
|
|
const { code }= hack;
|
|
let tempCode = Base64.decode(code)
|
|
Object.assign(hack, {code: tempCode});
|
|
return {
|
|
...state,
|
|
hack: Object.assign({}, hack),
|
|
test_case: Object.assign({}, test_case)
|
|
}
|
|
case types.COMMIT_RECORD_DETAIL:
|
|
let result = action.payload;
|
|
if (result['expected_output']) {
|
|
result['expected_output'] = Base64.decode(result['expected_output'])
|
|
}
|
|
if (result['output']) {
|
|
result['output'] = Base64.decode(result['output']);
|
|
}
|
|
try {
|
|
result['error_msg'] = Base64.decode(result['error_msg']);
|
|
} catch (e) {
|
|
console.log('错误信息:', e);
|
|
}
|
|
return {
|
|
...state,
|
|
commitRecordDetail: Object.assign({}, result)
|
|
}
|
|
case types.COMMIT_RECORD:
|
|
return {
|
|
...state,
|
|
commitRecord: [...action.payload]
|
|
}
|
|
case types.SAVE_USER_CODE:
|
|
let curCode = Base64.encode(action.payload);
|
|
|
|
return {
|
|
...state,
|
|
userCode: curCode,
|
|
isUpdateCode: true
|
|
}
|
|
case types.IS_UPDATE_CODE:
|
|
return {
|
|
...state,
|
|
isUpdateCode: action.payload
|
|
}
|
|
case types.CHANGE_USER_CODE_TAB:
|
|
return {
|
|
...state,
|
|
userCodeTab: action.payload
|
|
}
|
|
case types.GET_COMMIT_RECORD_DETAIL_BY_ID:
|
|
tempDetail = action.payload;
|
|
if (tempDetail['error_msg']) {
|
|
tempDetail['error_msg'] = Base64.decode(tempDetail['error_msg']);
|
|
}
|
|
if (tempDetail['expected_output']) {
|
|
tempDetail['expected_output'] = Base64.decode(tempDetail['expected_output']);
|
|
}
|
|
if (tempDetail['output']) {
|
|
tempDetail['output'] = Base64.decode(tempDetail['output']);
|
|
}
|
|
if (tempDetail['code']) {
|
|
tempDetail['code'] = Base64.decode(tempDetail['code']);
|
|
}
|
|
return {
|
|
...state,
|
|
recordDetail: tempDetail
|
|
}
|
|
case types.RESTORE_INITIAL_CODE:
|
|
const curHack = state.hack;
|
|
let restoreCode = action.payload
|
|
if (restoreCode) {
|
|
curHack['code'] = Base64.decode(restoreCode);
|
|
}
|
|
console.log('当前的代码内容:', curHack);
|
|
return {
|
|
...state,
|
|
hack: Object.assign({}, curHack)
|
|
}
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default ojForUserReducer;
|