fix 从编辑入口代码未更新的bug

video_transcode
harry 5 years ago
parent 50b0a907e4
commit 282557ef53

@ -18,12 +18,12 @@ const { TabPane } = Tabs;
const ControlSetting = (props) => { const ControlSetting = (props) => {
const { const {
editor_code,
inputValue, inputValue,
loading, loading,
submitLoading, submitLoading,
identifier, identifier,
excuteState, excuteState,
editor_code,
// showOrHideControl, // showOrHideControl,
commitTestRecordDetail, commitTestRecordDetail,
changeLoadingState, changeLoadingState,

@ -19,7 +19,7 @@ import ErrorResult from '../../../components/errorResult';
const numberal = require('numeral'); const numberal = require('numeral');
const {reviewResult} = CONST; const { reviewResult } = CONST;
// 表格列 // 表格列
const columns = [ const columns = [
{ {
@ -35,7 +35,7 @@ const columns = [
dataIndex: 'status', dataIndex: 'status',
render: (value, record) => ( render: (value, record) => (
<Link to={`/myproblems/record_detail/${record.id}`}> <Link to={`/myproblems/record_detail/${record.id}`}>
<span style={{ color: value === 0 ? '#28BD8B' : '#E6262E'}}>{reviewResult[value]}</span> <span style={{ color: value === 0 ? '#28BD8B' : '#E6262E' }}>{reviewResult[value]}</span>
</Link> </Link>
) )
}, },
@ -72,28 +72,18 @@ const CommitRecord = (props) => {
identifier, identifier,
pages, pages,
commitRecord, commitRecord,
// excuteState,
language, language,
operateType,
commitRecordDetail, commitRecordDetail,
getUserCommitRecord, getUserCommitRecord,
changeRecordPagination changeRecordPagination
} = props; } = props;
const [current, setCurrent] = useState(1); const [current, setCurrent] = useState(pages.page);
// const [pagination, setPagination] = useState(paginationConfig);
// const [tableData, setTableData] = useState([]);
// 复制面板 // 复制面板
let clipboard; let clipboard;
// const [recordDetail, setRecordDetail] = useState({});
// const [renderCtx, setRenderCtx] = useState(() => {
// return function () {
// return '';
// }
// });
// 渲染提交记录详情 // 渲染提交记录详情
const renderRecordDetail = (commitRecordDetail = {}) => { const renderRecordDetail = (commitRecordDetail = {}) => {
const {id, status} = commitRecordDetail; const { id, status } = commitRecordDetail;
if (Object.keys(commitRecordDetail).length > 0) { if (Object.keys(commitRecordDetail).length > 0) {
// console.log('当前状态====》》》', status); // console.log('当前状态====》》》', status);
const classes = status === 0 ? 'record_result_suc' : 'record_result_err'; const classes = status === 0 ? 'record_result_suc' : 'record_result_err';
@ -105,22 +95,22 @@ const CommitRecord = (props) => {
<p className={'record_result'}> <p className={'record_result'}>
执行结果: <span className={classes}>{reviewResult[status]}</span> 执行结果: <span className={classes}>{reviewResult[status]}</span>
</p> </p>
<p <p
id="copyError" id="copyError"
onClick={clickCopyErrInfo} onClick={clickCopyErrInfo}
className={showErrorCopy} data-clipboard-target="#errcode"> className={showErrorCopy} data-clipboard-target="#errcode">
<span> <span>
复制错误信息 <Icon type="copy" className={'icon_style'}/> 复制错误信息 <Icon type="copy" className={'icon_style'} />
</span> </span>
</p> </p>
<p className={'show_detail'} style={{ visibility: id ? 'visible' : 'hidden' }}> <p className={'show_detail'} style={{ visibility: id ? 'visible' : 'hidden' }}>
<Link to={`/myproblems/record_detail/${id}`}> <Link to={`/myproblems/record_detail/${id}`}>
显示详情 <Icon type="right" className={'icon_style'}/> 显示详情 <Icon type="right" className={'icon_style'} />
</Link> </Link>
</p> </p>
</div> </div>
<div id="errcode" className={showErrorCode}> <div id="errcode" className={showErrorCode}>
<ErrorResult detail={commitRecordDetail} language={language}/> <ErrorResult detail={commitRecordDetail} language={language} />
</div> </div>
</React.Fragment> </React.Fragment>
); );
@ -131,7 +121,7 @@ const CommitRecord = (props) => {
// 根据id获取用户提交记录 // 根据id获取用户提交记录
useEffect(() => { useEffect(() => {
getUserCommitRecord(identifier); getUserCommitRecord(identifier);
}, []); }, [identifier]);
// 提交记录变化时,同步到表单数据 // 提交记录变化时,同步到表单数据
// useEffect(() => { // useEffect(() => {
// // const len = commitRecord.length; // // const len = commitRecord.length;
@ -149,9 +139,9 @@ const CommitRecord = (props) => {
// 复制功能 // 复制功能
let count = 0; let count = 0;
// useEffect(() => { // useEffect(() => {
// }, []); // }, []);
const clickCopyErrInfo = () => { const clickCopyErrInfo = () => {
count = 0; count = 0;
if (!clipboard) { if (!clipboard) {
@ -174,76 +164,27 @@ const CommitRecord = (props) => {
changeRecordPagination(page); changeRecordPagination(page);
// 调用查询接口 // 调用查询接口
getUserCommitRecord(identifier); getUserCommitRecord(identifier);
// setPagination(Object.assign({}, pagination, { current: page}));
// console.log('======>>>>>>', pagination)
} }
// console.log(commitRecord);
const _style = { const _style = {
display: pages.total > pages.limit ? 'block' : 'none' display: pages.total > pages.limit ? 'block' : 'none'
}; };
const {status, id} = commitRecordDetail || {};
const classes = status === 0 ? 'record_result_suc' : 'record_result_err';
const showErrorCode = status !== 0 ? `ecord_error_info show_error_code` : `ecord_error_info`;
const showErrorCopy = status !== 0 ? `copy_error show_error_copy` : `copy_error`;
// if (!clipboard) {
// console.log('==========>>>>>>>', 11111111111);
// clipboard = new ClipboardJS('#copyError');
// }
// clipboard.on('success', (e) => {
// e.clearSelection();
// // if (count > 0) return;
// // count++;
// message.success('复制成功');
// setTimeout(() => {
// message.destroy();
// }, 3000);
// });
// return () => {
// clipboard = null;
// }
return ( return (
<div className={'commit_record_area'}> <div className={'commit_record_area'}>
{renderRecordDetail(commitRecordDetail)} {renderRecordDetail(commitRecordDetail)}
{/* <div className={'record_header'}>
<p className={'record_result'}>
执行结果: <span className={classes}>{reviewResult[status]}</span>
</p>
<p
id="copyError"
onClick={clickCopyErrInfo}
className={showErrorCopy} data-clipboard-target="#errcode">
<span>
复制错误信息 <Icon type="copy" className={'icon_style'}/>
</span>
</p>
<p className={'show_detail'} style={{ visibility: id ? 'visible' : 'hidden' }}>
<Link to={`/myproblems/record_detail/${id}`}>
显示详情 <Icon type="right" className={'icon_style'}/>
</Link>
</p>
</div>
<div id="errcode" className={showErrorCode}>
<ErrorResult detail={commitRecordDetail} language={language}/>
</div> */}
<div className="commit_record_table_pagination"> <div className="commit_record_table_pagination">
<Table <Table
columns={columns} columns={columns}
rowKey={function (record) { return `key_${record.id}`}} rowKey={function (record) { return `key_${record.id}` }}
dataSource={commitRecord} dataSource={commitRecord}
// pagination={pagination}
// onChange={handleTableChange}
pagination={false} pagination={false}
/> />
<div className="commit_record_pagination" style={_style}> <div className="commit_record_pagination" style={_style}>
<Pagination <Pagination
showQuickJumper showQuickJumper
pageSize={pages.limit} pageSize={pages.limit}
current={current} current={current}
total={pages.total} total={pages.total}
onChange={handlePaginationChange} onChange={handlePaginationChange}
/> />

@ -133,28 +133,28 @@ export const saveUserCodeForInterval = (identifier, code) => {
* @param {*} inputValue 输入值: 自定义 | 系统返回的 * @param {*} inputValue 输入值: 自定义 | 系统返回的
* @param {*} type 测评类型 debug | submit * @param {*} type 测评类型 debug | submit
*/ */
//原来的方法未能区分从编辑入口进来的情况,这时代码也是更新了的。
export const updateCode = (identifier, inputValue, type) => { export const updateCode = (identifier, inputValue, type) => {
return (dispatch, getState) => { return (dispatch, getState) => {
const { userCode, isUpdateCode } = getState().ojForUserReducer; const { editor_code, isUpdateCode } = getState().ojForUserReducer;
if (isUpdateCode) { if (isUpdateCode) {
fetchUpdateCode(identifier, { fetchUpdateCode(identifier, {
code: Base64.encode(userCode) code: Base64.encode(editor_code)
}).then(res => { }).then(res => {
// 是否更新了代码, 目的是当代码没有更新时不调用更新代码接口,目录没有实现 if (res) {
// TODO 需要优化 if (res.data.status === 401) {
if (res.data.status === 401) { dispatch({ // 改变 loading 值
dispatch({ // 改变 loading 值 type: types.LOADING_STATUS,
type: types.LOADING_STATUS, payload: false
payload: false });
return;
};
dispatch({
type: types.IS_UPDATE_CODE,
flag: false
}); });
return; dispatch(debuggerCode(identifier, inputValue, type));
}; }
dispatch({
type: types.IS_UPDATE_CODE,
flag: false
});
// debuggerCode(identifier, inputValue);
dispatch(debuggerCode(identifier, inputValue, type));
}); });
} else { } else {
// 没有更新时,直接调用调试接口 // 没有更新时,直接调用调试接口
@ -393,7 +393,6 @@ export const changeUserCodeTab = (key) => {
export const submitUserCode = (identifier, inputValue, type) => { export const submitUserCode = (identifier, inputValue, type) => {
return (dispatch, getState) => { return (dispatch, getState) => {
const { editor_code, isUpdateCode, hack } = getState().ojForUserReducer; const { editor_code, isUpdateCode, hack } = getState().ojForUserReducer;
function userCodeSubmit() { function userCodeSubmit() {
fetchUserCodeSubmit(identifier).then(res => { fetchUserCodeSubmit(identifier).then(res => {
if (res.status === 200) { if (res.status === 200) {

@ -151,7 +151,8 @@ const ojForUserReducer = (state = initialState, action) => {
case types.SAVE_EDITOR_CODE: case types.SAVE_EDITOR_CODE:
return { return {
...state, ...state,
editor_code: action.payload editor_code: action.payload,
isUpdateCode: true
} }
case types.SAVE_USE_TEST_CASE_VALUE: case types.SAVE_USE_TEST_CASE_VALUE:
return { return {

Loading…
Cancel
Save