harry 5 years ago
parent 971483ac17
commit 593b973217

@ -33,6 +33,7 @@ function MyMonacoEditor(props, ref) {
identifier, identifier,
hadCodeUpdate, hadCodeUpdate,
showOrHideControl, showOrHideControl,
// saveUserInputCode,
onCodeChange, onCodeChange,
onRestoreInitialCode, onRestoreInitialCode,
onUpdateNotice onUpdateNotice
@ -48,6 +49,10 @@ function MyMonacoEditor(props, ref) {
const [height, setHeight] = useState('calc(100% - 56px)'); const [height, setHeight] = useState('calc(100% - 56px)');
const editorRef = useRef(null); const editorRef = useRef(null);
// useEffect(() => {
// setEditCode(props.code || '');
// }, [props]);
useEffect(() => { useEffect(() => {
setHeight(showOrHideControl ? 'calc(100% - 378px)' : 'calc(100% - 56px)'); setHeight(showOrHideControl ? 'calc(100% - 378px)' : 'calc(100% - 56px)');
}, [showOrHideControl]); }, [showOrHideControl]);
@ -70,19 +75,20 @@ function MyMonacoEditor(props, ref) {
} }
// 文本框内容变化时,记录文本框内容 // 文本框内容变化时,记录文本框内容
const handleEditorChange = (origin, monaco) => { const handleEditorChange = (_, monaco) => {
editorRef.current = monaco; // 获取当前monaco实例 editorRef.current = monaco; // 获取当前monaco实例
// setEditCode(origin); // 保存编辑器初始值 }
useEffect(() => {
if (editorRef.current) {
editorRef.current.onDidChangeModelContent(e => { // 监听编辑器内容的变化 editorRef.current.onDidChangeModelContent(e => { // 监听编辑器内容的变化
// TODO 需要优化 节流
const val = editorRef.current.getValue(); const val = editorRef.current.getValue();
// setEditCode(val);
// console.log('编辑器代码====>>>>', val);
onCodeChange(val); onCodeChange(val);
// 值一变化保存当前代码值
// saveUserInputCode(val);
}); });
} }
}, [
editorRef.current
])
// 配置编辑器属性 // 配置编辑器属性
const editorOptions = { const editorOptions = {

@ -8,23 +8,19 @@
import './index.less'; import './index.less';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import SplitPane from 'react-split-pane';// import { Form } from 'antd'; import SplitPane from 'react-split-pane';
import { Button } from 'antd'; import { Button } from 'antd';
import LeftPane from './leftpane'; import LeftPane from './leftpane';
import RightPane from './rightpane'; import RightPane from './rightpane';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
import { toStore, CNotificationHOC } from 'educoder'; import { toStore, CNotificationHOC } from 'educoder';
import UserInfo from '../components/userInfo'; import UserInfo from '../components/userInfo';
// import RightPane from './rightpane/index';
import actions from '../../../redux/actions'; import actions from '../../../redux/actions';
// import {ModalConfirm} from '../../../common/components/ModalConfirm';
const NewOrEditTask = (props) => { const NewOrEditTask = (props) => {
const { const {
publishLoading, publishLoading,
handlePublish, handlePublish,
// testCases = [],
// ojTestCaseValidate = [],
identifier, identifier,
isPublish, isPublish,
userInfo, userInfo,
@ -38,15 +34,10 @@ const NewOrEditTask = (props) => {
getQuestion, getQuestion,
saveSearchParams, saveSearchParams,
setOjInitialValue, setOjInitialValue,
courseQuestions
// updateTestAndValidate,
} = props; } = props;
// 表单提交
const handleSubmitForm = () => { const handleSubmitForm = () => {
// 改变loading状态
changeSubmitLoadingStatus(true); changeSubmitLoadingStatus(true);
// 调用输入表单验证功能
if (props.identifier) { if (props.identifier) {
props.handleUpdateOjForm(props); props.handleUpdateOjForm(props);
} else { } else {
@ -54,12 +45,10 @@ const NewOrEditTask = (props) => {
} }
}; };
const id = props.match.params.id;
useEffect(() => { useEffect(() => {
// 获取用户信息 // 获取用户信息
getUserInfoForNew(); getUserInfoForNew();
// console.log('获取路由参数: ====', props.match.params);
const id = props.match.params.id;
// 保存OJForm的id号指明是编辑还是新增
props.saveOJFormId(id); props.saveOJFormId(id);
// 获取地址栏查询参数 // 获取地址栏查询参数
const $searchs = window.location.search && window.location.search.substring(1); const $searchs = window.location.search && window.location.search.substring(1);
@ -80,21 +69,16 @@ const NewOrEditTask = (props) => {
tag_discipline_id: tag_arrs tag_discipline_id: tag_arrs
}); });
} }
saveSearchParams({searchParams: $searchs, curPage: obj['pages']}); saveSearchParams({ searchParams: $searchs, curPage: obj['pages'] });
} }
// 获取课程列表 // 获取课程列表
getQuestion({ getQuestion({
source: 'question' source: 'question'
}); });
if (id) { // id号即 identifier if (id) { // id号即 identifier
// TODO id 存在时, 编辑, 获取 store 中的记录数
props.getOJFormById(id); props.getOJFormById(id);
} else {
// 清空store中的测试用例集合
// props.clearOJFormStore();
} }
return () => { } }, [id])
}, []);
// 模拟挑战 // 模拟挑战
const imitationChallenge = () => { const imitationChallenge = () => {
@ -107,11 +91,9 @@ const NewOrEditTask = (props) => {
// 开始挑战 // 开始挑战
const startChallenge = () => { const startChallenge = () => {
// 调用 start 接口, 成功后跳转到开启实战 // 调用 start 接口, 成功后跳转到开启实战
// TODO
identifier && validateOjForm(props, 'challenge', () => { identifier && validateOjForm(props, 'challenge', () => {
startProgramQuestion(identifier, props); startProgramQuestion(identifier, props);
}); });
// identifier && startProgramQuestion(identifier, props);
} }
// 取消 // 取消
@ -120,16 +102,11 @@ const NewOrEditTask = (props) => {
props.clearOJFormStore(); props.clearOJFormStore();
// 清空描述信息 // 清空描述信息
toStore('oj_description', ''); toStore('oj_description', '');
// props.history.push('/problems');
props.history.push(`/problemset?${props.searchParams}`); props.history.push(`/problemset?${props.searchParams}`);
} }
// 发布 // 发布
const handleClickPublish = () => { const handleClickPublish = () => {
// ModalConfirm('提示', (<p>发布后即可应用到自己管理的课堂<br /> 是否确认发布?</p>), () => {
// changePublishLoadingStatus(true);
// handlePublish(props, 'publish');
// });
props.confirm({ props.confirm({
title: '提示', title: '提示',
content: (<p>发布后即可应用到自己管理的课堂<br /> 是否确认发布?</p>), content: (<p>发布后即可应用到自己管理的课堂<br /> 是否确认发布?</p>),
@ -141,10 +118,6 @@ const NewOrEditTask = (props) => {
} }
// 撤销发布 // 撤销发布
const handleClickCancelPublish = () => { const handleClickCancelPublish = () => {
// ModalConfirm('提示', (<p>是否确认撤销发布?</p>), () => {
// changePublishLoadingStatus(true);
// handleCancelPublish(props, identifier);
// });
props.confirm({ props.confirm({
title: '提示', title: '提示',
content: ((<p>是否确认撤销发布?</p>)), content: ((<p>是否确认撤销发布?</p>)),
@ -248,7 +221,6 @@ const NewOrEditTask = (props) => {
</SplitPane> </SplitPane>
</SplitPane> </SplitPane>
</div> </div>
{/* 控制台 */}
<div className='new_add_task_ctl'> <div className='new_add_task_ctl'>
{ {
/* 录入时: 取消 保存 */ /* 录入时: 取消 保存 */

@ -37,16 +37,6 @@ const RightPane = (props) => {
const [noteClazz, setNoteClazz] = useState('editor_nodte_area'); const [noteClazz, setNoteClazz] = useState('editor_nodte_area');
const [noteCount] = useState(5000); const [noteCount] = useState(5000);
// const [code, setCode] = useState(editor_code || hack.code);
// let initFlag = true;
// useEffect(() => {
// if (editor_code) {
// setEditorCode(editor_code);
// } else {
// setEditorCode(hack.code);
// }
// }, [hack, editor_code]);
const handleSubmitForm = () => { const handleSubmitForm = () => {
@ -56,22 +46,18 @@ const RightPane = (props) => {
let timer = null; // 定时器 let timer = null; // 定时器
// 代码块内容变化时 // 代码块内容变化时
const handleCodeChange = (value) => { const handleCodeChange = (value) => {
// console.log('编辑器代码 ======》》》》》》》》》++++++++++', value);
saveUserInputCode(value); saveUserInputCode(value);
// setEditorCode(value);
if (!timer) { if (!timer) {
timer = setInterval(function () { timer = setInterval(function () {
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
saveUserCodeForInterval(identifier); saveUserCodeForInterval(identifier);
}, 3000); }, 10000);
} }
} }
// 代码调试 // 代码调试
const handleDebuggerCode = (value) => { const handleDebuggerCode = (value) => {
// 调用保存代码块接口,成功后,调用调试接口
// saveOpacityType('debug');
updateCode(identifier, value, 'debug'); updateCode(identifier, value, 'debug');
} }
// 恢复初始代码 // 恢复初始代码
@ -104,7 +90,6 @@ const RightPane = (props) => {
} }
}); });
} }
const { getFieldDecorator } = props.form; const { getFieldDecorator } = props.form;
return ( return (
<div className={'right_pane_code_wrap'}> <div className={'right_pane_code_wrap'}>

@ -25,11 +25,10 @@ import { notification } from "antd";
// 进入编程页面时,首先调用开启编程题接口 // 进入编程页面时,首先调用开启编程题接口
export const startProgramQuestion = (id, props) => { export const startProgramQuestion = (id, props) => {
return (dispatch, getState) => { return (dispatch, getState) => {
const {searchParams} = getState().ojFormReducer;
fetchStartProgram(id).then(res => { fetchStartProgram(id).then(res => {
const { status, data } = res; const { status, data } = res;
if (status === 200) { if (status === 200) {
const {identifier} = data; const { identifier } = data;
dispatch({ dispatch({
type: types.SAVE_USER_PROGRAM_ID, type: types.SAVE_USER_PROGRAM_ID,
payload: identifier payload: identifier
@ -41,13 +40,6 @@ export const startProgramQuestion = (id, props) => {
}); });
// 跳转至开启编程 // 跳转至开启编程
if (identifier) { if (identifier) {
// let data = Object.assign({}, props);
// const path = {
// pathname: `/myproblems/${identifier}`,
// state: data
// }
// console.log(path);
// props.history.push(`/myproblems/${identifier}`);
props.history.push({ props.history.push({
pathname: `/myproblems/${identifier}`, pathname: `/myproblems/${identifier}`,
}); });
@ -115,24 +107,18 @@ export const saveUserCodeForInterval = (identifier, code) => {
type: types.AUTO_UPDATE_CODE, type: types.AUTO_UPDATE_CODE,
payload: true payload: true
}); });
// console.log('+++', userCode);
fetchUpdateCode(identifier, { fetchUpdateCode(identifier, {
code: Base64.encode(userCode) code: Base64.encode(userCode)
}).then(res => { }).then(res => {
if (res.data.status === 401) { if (res.data.status === 401) {
return; return;
}; };
// dispatch({
// type: types.RESTORE_INITIAL_CODE,
// payload: userCode
// });
setTimeout(() => { setTimeout(() => {
dispatch({ dispatch({
type: types.AUTO_UPDATE_CODE, type: types.AUTO_UPDATE_CODE,
payload: false payload: false
}) })
}, 1000); }, 1000);
// console.log('代码保存成功', res);
}).catch(() => { }).catch(() => {
dispatch({ dispatch({
type: types.AUTO_UPDATE_CODE, type: types.AUTO_UPDATE_CODE,
@ -190,7 +176,7 @@ export const codeEvaluate = (dispatch, identifier, type, time_limit, hackStatus,
* @param {*} count 执行次数 * @param {*} count 执行次数
* @param {*} timer 定时器 * @param {*} timer 定时器
*/ */
function getCodeSubmit (intervalTime, finalTime, count, timer){ function getCodeSubmit(intervalTime, finalTime, count, timer) {
const excuteTime = (count++) * intervalTime; // 当前执行时间 const excuteTime = (count++) * intervalTime; // 当前执行时间
fetchCodeSubmit(identifier, { mode: type }).then(res => { fetchCodeSubmit(identifier, { mode: type }).then(res => {
const { status } = res.data; // 评测返回结果 const { status } = res.data; // 评测返回结果
@ -290,7 +276,7 @@ export const codeEvaluate = (dispatch, identifier, type, time_limit, hackStatus,
* @param {*} inputValue 输入值: 自定义 | 系统返回的 * @param {*} inputValue 输入值: 自定义 | 系统返回的
* @param {*} type 测评类型 debug | submit * @param {*} type 测评类型 debug | submit
*/ */
export const debuggerCode = (identifier,value, type) => { export const debuggerCode = (identifier, value, type) => {
return (dispatch, getState) => { return (dispatch, getState) => {
// 调用之前 先保存 code // 调用之前 先保存 code
// TODO // TODO
@ -337,19 +323,26 @@ export const debuggerCode = (identifier,value, type) => {
// 获取提交记录 // 获取提交记录
export const getUserCommitRecord = (identifier) => { export const getUserCommitRecord = (identifier) => {
return (dispatch, getState) => { return (dispatch, getState) => {
try {
const { pages: { limit, page } } = getState().ojForUserReducer; const { pages: { limit, page } } = getState().ojForUserReducer;
fetchUserCommitRecord(identifier, { fetchUserCommitRecord(identifier, {
limit, limit,
page page
}).then(res => { }).then(res => {
const {status, data} = res; if (res) {
const { status, data } = res;
if (status === 200) { if (status === 200) {
dispatch({ dispatch({
type: types.COMMIT_RECORD, type: types.COMMIT_RECORD,
payload: data payload: data
}) })
} }
}); }
})
} catch (error) {
console.log(error, '-------')
}
;
} }
} }
// 获取提交记录详情 // 获取提交记录详情
@ -401,11 +394,10 @@ export const changeUserCodeTab = (key) => {
*/ */
export const submitUserCode = (identifier, inputValue, type) => { export const submitUserCode = (identifier, inputValue, type) => {
return (dispatch, getState) => { return (dispatch, getState) => {
const { userCode, isUpdateCode, hack} = getState().ojForUserReducer; const { userCode, isUpdateCode, hack } = getState().ojForUserReducer;
function userCodeSubmit () { function userCodeSubmit() {
fetchUserCodeSubmit(identifier).then(res => { fetchUserCodeSubmit(identifier).then(res => {
// console.log('用户提交代码成功======》》》》》', res);
if (res.status === 200) { if (res.status === 200) {
if (res.data.status === 401) { if (res.data.status === 401) {
dispatch({ dispatch({
@ -415,7 +407,6 @@ export const submitUserCode = (identifier, inputValue, type) => {
return; return;
}; };
// 测评 // 测评
console.log('hack=====', hack);
codeEvaluate(dispatch, identifier, type, hack.time_limit, hack.status, hack.score, hack.passed); codeEvaluate(dispatch, identifier, type, hack.time_limit, hack.status, hack.score, hack.passed);
} }
}).catch(() => { }).catch(() => {
@ -427,10 +418,9 @@ export const submitUserCode = (identifier, inputValue, type) => {
} }
if (isUpdateCode) { if (isUpdateCode) {
fetchUpdateCode(identifier, { fetchUpdateCode(identifier, {
code: userCode code: Base64.encode(userCode)
}).then(res => { }).then(res => {
// 是否更新了代码, 目的是当代码没有更新时不调用更新代码接口,目录没有实现 // 是否更新了代码, 目的是当代码没有更新时不调用更新代码接口,目录没有实现
// TODO 需要优化
if (res.data.status === 401) { if (res.data.status === 401) {
dispatch({ dispatch({
type: types.SUBMIT_LOADING_STATUS, type: types.SUBMIT_LOADING_STATUS,
@ -460,8 +450,7 @@ export const restoreInitialCode = (identifier, msg) => {
return (dispatch) => { return (dispatch) => {
fetchRestoreInitialCode(identifier).then(res => { fetchRestoreInitialCode(identifier).then(res => {
if (res.data.status === 401) return; if (res.data.status === 401) return;
// console.log('恢复初始代码====》》》》', res); const { status, data } = res;
const {status, data} = res;
if (status === 200) { if (status === 200) {
dispatch({ dispatch({
type: types.RESTORE_INITIAL_CODE, type: types.RESTORE_INITIAL_CODE,
@ -515,7 +504,6 @@ export const changeRecordPagination = (page) => {
export const addNotes = (identifier, params, cb) => { export const addNotes = (identifier, params, cb) => {
return (dispatch) => { return (dispatch) => {
fetchAddNotes(identifier, params).then(res => { fetchAddNotes(identifier, params).then(res => {
// console.log('添加笔记成功===>>', res);
dispatch({ dispatch({
type: types.LOADING_STATUS, type: types.LOADING_STATUS,
payload: false payload: false

Loading…
Cancel
Save