From a4d2b5976406b1c178c66e9c1d944916dae358ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 20 Dec 2019 16:54:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/jupyter.js | 10 +++++---- public/react/src/AppConfig.js | 2 +- public/react/src/modules/tpm/jupyter/index.js | 21 +++++++++++++++++++ .../modules/tpm/jupyter/rightPane/index.js | 14 ++++++------- .../Challenges/Challengesjupyter.js | 1 - 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/public/javascripts/jupyter.js b/public/javascripts/jupyter.js index 021d46a2e..aa738a644 100644 --- a/public/javascripts/jupyter.js +++ b/public/javascripts/jupyter.js @@ -2,15 +2,17 @@ //guange 2019.12.18 -$(function(){ +window.onload=function(){ console.log("开始发送消息了"); runEvery10Sec(); -}) +} function runEvery10Sec() { // 1000 * 10 = 10 秒钟 - console.log("每隔10秒中一次runEvery10Sec"); + console.log("每隔10秒中一次"); + require(["base/js/namespace"],function(Jupyter) { + Jupyter.notebook.save_checkpoint(); + }); window.parent.postMessage('jupytermessage','*'); setTimeout( runEvery10Sec, 1000 * 10 ); - } diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index ac39562a7..acd18e6c3 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -52,7 +52,7 @@ export function initAxiosInterceptors(props) { //proxy="http://47.96.87.25:48080" proxy="https://pre-newweb.educoder.net" proxy="https://test-newweb.educoder.net" - //proxy="https://test-jupyterweb.educoder.net" + proxy="https://test-jupyterweb.educoder.net" //proxy="http://192.168.2.63:3001" // 在这里使用requestMap控制,避免用户通过双击等操作发出重复的请求; diff --git a/public/react/src/modules/tpm/jupyter/index.js b/public/react/src/modules/tpm/jupyter/index.js index 617ef0936..9d3ec50ec 100644 --- a/public/react/src/modules/tpm/jupyter/index.js +++ b/public/react/src/modules/tpm/jupyter/index.js @@ -75,11 +75,30 @@ function JupyterTPI (props) { const [updateTip, setUpdateTip] = useState(true); const [myIdentifier, setMyIdentifier] = useState(''); const [renderCtx, setRenderCtx] = useState(() => (emptyCtx)); + + // 保存代码 + const addEventListeners = () => { + window.addEventListener('message', (e) => { + console.log("触发了jupytermessage"); + if(e){ + if(e.data){ + if(e.data==="jupytermessage"){ + saveJupyterTpi(); + } + } + + } + + }); + } + + useEffect(() => { /* 先调用 jupyter的 TPI 接口, * 获取 用户信息, * 实训的 identifier, 状态, 名称, 是否被修改等信息 */ + addEventListeners() getJupyterInfo(identifier); }, [identifier]); @@ -234,6 +253,8 @@ function JupyterTPI (props) { setRenderCtx(oUl); } }, [props]); + + return (