update commit tip info

dev_forge
tangjiang 5 years ago
parent 3ede569941
commit 1130b010c1

@ -4,49 +4,72 @@
* @Github:
* @Date: 2019-12-03 15:20:55
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-03 15:31:15
* @LastEditTime: 2019-12-03 20:36:24
*/
import './index.scss';
import React from 'react';
import MonacoEditor from '@monaco-editor/react';
function ErrorResult (props) {
const { detail } = props;
const { detail, language } = props;
const renderError = (detail = {}) => {
const {
status,
error_line,
// error_line,
error_msg,
expected_output,
input,
output,
execute_time,
execute_memory
// execute_memory
} = detail;
// 根据状态渲染不同的错误信息
let result = null;
switch (status) {
case -1:
result = (
<div className={'error_result_wrap'}>
<p>输入: [input]</p>
<p>输出: [output]</p>
<p>预期: [expected_output]</p>
<div className={'error_result_wrap error_result_txt'}>
<p>输入: [{input}]</p>
<p>输出: [{output}]</p>
<p>预期: [{expected_output}]</p>
</div>
);
break;
break;
case 2: // 评测超时
return (
<div className={'error_result_wrap'}>
<p>执行超时限制时限: {`${execute_time}s`}</p>
</div>
);
break;
result = (
<div className={'error_result_wrap error_result_txt'}>
<p>执行超时限制时限: {`${execute_time}s`}</p>
</div>
);
break;
case 3: // 创建pod失败
result = (
<div className={'error_result_wrap'}>
</div>
);
break;
case 4: // 编译失败
result = (
<div className={'error_result_wrap error_result_code'}>
{/* <p>{error_msg}</p> */}
<MonacoEditor
height="100%"
width="100%"
language={(language && language.toLowerCase()) || 'c'}
value={error_msg}
theme="dark"
/>
</div>
);
break;
case 5: // 执行失败
result = (
<div className={'error_result_wrap'}>
<p>执行出错信息: </p>
<p>最后执行的输入: {input}</p>
</div>
);
break;
default:
return result;

@ -0,0 +1,11 @@
.error_result_wrap{
&.error_result_txt{
padding: 20px 30px;
}
&.error_result_code{
height: 150px;
.error_result_code_txt{
line-height: 32px;
}
}
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-27 09:49:33
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-03 15:14:34
* @LastEditTime: 2019-12-03 20:47:59
*/
import './index.scss';
import React, { useState, useEffect } from 'react';
@ -14,6 +14,7 @@ import actions from '../../../../../redux/actions';
import CONST from '../../../../../constants';
import moment from 'moment';
import ClipboardJS from 'clipboard';
import ErrorResult from '../../../components/errorResult';
const numberal = require('numeral');
@ -66,6 +67,7 @@ const CommitRecord = (props) => {
identifier,
commitRecord,
// excuteState,
language,
commitRecordDetail,
getUserCommitRecord
} = props;
@ -110,7 +112,9 @@ const CommitRecord = (props) => {
显示详情 <Icon type="right" className={'icon_style'}/>
</p>
</div>
<div id="errcode" className={showErrorCode}>{error_msg}</div>
<div id="errcode" className={showErrorCode}>
<ErrorResult detail={commitRecordDetail} language={language}/>
</div>
</React.Fragment>
);
} else {
@ -123,7 +127,10 @@ const CommitRecord = (props) => {
}, []);
// 提交记录变化时,同步到表单数据
useEffect(() => {
const len = commitRecord.length;
const pageConfig = Object.assign({}, paginationConfig, {total: len});
setTableData(commitRecord);
setPagination(pageConfig);
}, [commitRecord]);
// 提交详情变化时,显示当前提交信息
useEffect(() => {
@ -140,15 +147,21 @@ const CommitRecord = (props) => {
});
}
}, [commitRecordDetail.status]);
//
const handleTableChange = (pagination) => {
setPagination(Object.assign({}, pagination));
}
// console.log(commitRecord);
return (
<div className={'commit_record_area'}>
{renderRecordDetail()}
{renderCtx()}
<Table
columns={columns}
rowKey={function (record) { return `key_${record.id}`}}
dataSource={tableData}
pagination={pagination}
onChange={handleTableChange}
/>
</div>
)
@ -162,7 +175,8 @@ const mapStateToProps = (state) => {
const {
user_program_identifier,
commitRecordDetail,
commitRecord
commitRecord,
hack
} = ojForUserReducer;
const { excuteState } = commonReducer;
return {
@ -170,6 +184,7 @@ const mapStateToProps = (state) => {
commitRecordDetail,
commitRecord, // 提交记录
excuteState, // 代码执行状态
language: hack.language
}
}
const mapDispatchToProps = (dispatch) => ({

@ -42,11 +42,12 @@
.record_error_info{
display: none;
padding: 20px 30px;
word-wrap:break-word;
}
.show_error_code{
display: block;
background: rgba(250,250,250,1);
padding: 20px 30px;
// padding: 20px 30px;
color: #E51C24;
margin-bottom: 20px;
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-27 13:42:11
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-03 11:19:46
* @LastEditTime: 2019-12-03 20:44:47
*/
import types from "./actionTypes";
import { Base64 } from 'js-base64';
@ -131,7 +131,7 @@ export const debuggerCode = (identifier,value, type) => {
if (+status === 0 || (excuteTime / 1000) > (finalTime + 1)) {
clearInterval(timer); // 清除定时器
timer = null;
let returnData = null;
let returnData = null;
if (status === 1) { // 结果没有返回
returnData = {
error_line: -1,
@ -266,15 +266,7 @@ export const changeUserCodeTab = (key) => {
export const submitUserCode = (identifier, inputValue, type) => {
return (dispatch, getState) => {
const { userCode, isUpdateCode } = getState().ojForUserReducer;
isUpdateCode && fetchUpdateCode(identifier, {
code: userCode
}).then(res => {
// 是否更新了代码, 目的是当代码没有更新时不调用更新代码接口,目录没有实现
// TODO 需要优化
dispatch({
type: types.IS_UPDATE_CODE,
flag: false
});
function userCodeSubmit () {
fetchUserCodeSubmit(identifier).then(res => {
// console.log('用户提交代码成功======》》》》》', res);
if (res.status === 200) {
@ -286,12 +278,27 @@ export const submitUserCode = (identifier, inputValue, type) => {
payload: false
});
});
}).catch(() => {
dispatch({
type: types.SUBMIT_LOADING_STATUS,
payload: false
})
});
}
if (isUpdateCode) {
fetchUpdateCode(identifier, {
code: userCode
}).then(res => {
// 是否更新了代码, 目的是当代码没有更新时不调用更新代码接口,目录没有实现
// TODO 需要优化
dispatch({
type: types.IS_UPDATE_CODE,
flag: false
});
userCodeSubmit();
}).catch(() => {
dispatch({
type: types.SUBMIT_LOADING_STATUS,
payload: false
})
});
} else {
userCodeSubmit();
}
}
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-27 13:41:48
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-03 10:54:34
* @LastEditTime: 2019-12-03 20:00:26
*/
import types from "../actions/actionTypes";
import { Base64 } from 'js-base64';
@ -40,9 +40,18 @@ const ojForUserReducer = (state = initialState, action) => {
}
case types.COMMIT_RECORD_DETAIL:
let result = action.payload;
result['output'] = Base64.decode(result['output']);
result['error_msg'] = Base64.decode(result['error_msg']);
return {
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)
}

Loading…
Cancel
Save