From 26294c47af784b26cd3f29d91bd43e96bdfa60f7 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Fri, 6 Dec 2019 15:18:01 +0800 Subject: [PATCH 1/3] add user reduder --- public/react/src/redux/actions/actionTypes.js | 3 +- public/react/src/redux/actions/user.js | 16 ++++++++++ public/react/src/redux/reducers/index.js | 5 ++- .../react/src/redux/reducers/userReducer.js | 31 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 public/react/src/redux/actions/user.js create mode 100644 public/react/src/redux/reducers/userReducer.js diff --git a/public/react/src/redux/actions/actionTypes.js b/public/react/src/redux/actions/actionTypes.js index f6bc7f3b9..4850fc794 100644 --- a/public/react/src/redux/actions/actionTypes.js +++ b/public/react/src/redux/actions/actionTypes.js @@ -46,7 +46,8 @@ const types = { UPDATE_TEST_AND_VALIDATE: 'UPDATE_TEST_AND_VALIDATE', // 更新测试用例及验证值 UPDATE_OPEN_TESTCASE_INDEX: 'UPDATE_OPEN_TESTCASE_INDEX', // 更新测试用例索引 GET_COMMIT_RECORD_DETAIL_BY_ID: 'GET_COMMIT_RECORD_DETAIL_BY_ID', // 根据id号获取提交记录详情 - RESTORE_INITIAL_CODE: 'RESTORE_INITIAL_CODE' // 恢复初始代码 + RESTORE_INITIAL_CODE: 'RESTORE_INITIAL_CODE', // 恢复初始代码 + SAVE_USER_INFO: 'SAVE_USER_INFO', // 只在用户信息 } export default types; diff --git a/public/react/src/redux/actions/user.js b/public/react/src/redux/actions/user.js new file mode 100644 index 000000000..1b7c331c6 --- /dev/null +++ b/public/react/src/redux/actions/user.js @@ -0,0 +1,16 @@ +/* + * @Description: + * @Author: tangjiang + * @Github: + * @Date: 2019-12-06 15:09:22 + * @LastEditors: tangjiang + * @LastEditTime: 2019-12-06 15:15:00 + */ +import types from './actionTypes'; + +// 获取用户信息 +export default function getUserInfo () { + return (dispatch) => { + // 调用获取用户信息, 如果没有登录直接调用登录,成功后保存当前用户信息 + } +} \ No newline at end of file diff --git a/public/react/src/redux/reducers/index.js b/public/react/src/redux/reducers/index.js index 2f60bf8e3..620905459 100644 --- a/public/react/src/redux/reducers/index.js +++ b/public/react/src/redux/reducers/index.js @@ -12,10 +12,13 @@ import ojFormReducer from './ojFormReducer'; import ojListReducer from './ojListReducer'; import ojForUserReducer from './ojForUserReducer'; import commonReducer from './commonReducer'; +import userReducer from './userReducer'; + export default combineReducers({ testReducer, ojFormReducer, ojListReducer, ojForUserReducer, - commonReducer + commonReducer, + userReducer }); diff --git a/public/react/src/redux/reducers/userReducer.js b/public/react/src/redux/reducers/userReducer.js new file mode 100644 index 000000000..0e2718be9 --- /dev/null +++ b/public/react/src/redux/reducers/userReducer.js @@ -0,0 +1,31 @@ +/* + * @Description: 保存信息数据 + * @Author: tangjiang + * @Github: + * @Date: 2019-12-06 15:09:29 + * @LastEditors: tangjiang + * @LastEditTime: 2019-12-06 15:16:15 + */ +import types from "../actions/actionTypes"; + +const initialState = { + userInfo: {} // 当前登录用户信息 +}; + +const userReducer = (state = initialState, action) => { + switch (action.type) { + case types.SAVE_USER_INFO: + return { + userInfo: action.payload + } + default: + return { + ...state + } + } +} + +export default userReducer; +export { + userReducer +}; From 33c4ca049b1dc2037eeca64ce6b5b5361d80add3 Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Fri, 6 Dec 2019 17:18:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/constants/index.js | 21 +++++- .../components/controlSetting/index.scss | 8 +++ .../components/monacoSetting/index.js | 66 ++++++++++++++----- .../components/myMonacoEditor/index.js | 24 +++++-- .../newOrEditTask/leftpane/editorTab/index.js | 6 +- .../modules/developer/studentStudy/index.js | 4 +- .../developer/studentStudy/rightpane/index.js | 16 ++++- public/react/src/redux/actions/ojForUser.js | 16 ++++- 8 files changed, 128 insertions(+), 33 deletions(-) diff --git a/public/react/src/constants/index.js b/public/react/src/constants/index.js index abae13db0..3e7aceab0 100644 --- a/public/react/src/constants/index.js +++ b/public/react/src/constants/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 23:10:48 * @LastEditors: tangjiang - * @LastEditTime: 2019-11-28 14:41:42 + * @LastEditTime: 2019-12-06 15:53:27 */ const CONST = { jcLabel: { @@ -20,8 +20,25 @@ const CONST = { title: '代码格式', type: 'select', content: [ + { + text: '显示风格', + type: 'style', + value: [ + { + key: 'dark', + text: '黑色背景', + value: 'dark' + }, + { + key: 'light', + text: '白色背景', + value: 'light' + } + ] + }, { - text: '字体大小', + text: '字体大小', + type: 'font', value: [ { key: 1, diff --git a/public/react/src/modules/developer/components/controlSetting/index.scss b/public/react/src/modules/developer/components/controlSetting/index.scss index 0c7f726f5..4a2c221c1 100644 --- a/public/react/src/modules/developer/components/controlSetting/index.scss +++ b/public/react/src/modules/developer/components/controlSetting/index.scss @@ -67,6 +67,14 @@ font-size: 12px; } } + + .ant-drawer-body{ + height: calc(100vh - 120px); + overflow-y: auto; + } + .ant-drawer-content{ + top: 120px; + } } diff --git a/public/react/src/modules/developer/components/monacoSetting/index.js b/public/react/src/modules/developer/components/monacoSetting/index.js index ea8448fa0..a101819e0 100644 --- a/public/react/src/modules/developer/components/monacoSetting/index.js +++ b/public/react/src/modules/developer/components/monacoSetting/index.js @@ -4,26 +4,54 @@ * @Github: * @Date: 2019-11-25 17:50:33 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-04 11:26:02 + * @LastEditTime: 2019-12-06 16:51:48 */ -import React from 'react'; -import { Select } from 'antd'; - -const { Option } = Select; +import React, { useState } from 'react'; +import { fromStore, toStore } from 'educoder'; +// import { Select } from 'antd'; +// const { Option } = Select; const SettingDrawer = (props) => { /** * title: '', // 一级标题 * type: '', // 类型: 目录 select 和 文本 * content: [] // 显示的内容 { text: '' , value: string | [{ key: 1, value: '', text: '' }] } */ + + const [fontSize, setFontSize] = useState(() => { + return +fromStore('oj_fontSize') || 14; + }); + const [theme, setTheme] = useState(() => { + return fromStore('oj_theme') || 'dark'; + }); + const {title, type = 'label', content = [] } = props; - const handleFontSize = (e) => { - const {onChangeFontSize} = props; - const value = e.target.value; - console.log('fong size change: ', value); + // 字体改变时, 方法全名: handleChangeXX, XX 为指定的类型; + const { + onChangeFontSize, + onChangeTheme + } = props; + const handleChangeFont = (value) => { + setFontSize(value); + toStore('oj_fontSize', value); onChangeFontSize && onChangeFontSize(value); } + // 风格改变时 + const handleChangeStyle = (value) => { + setTheme(value); + toStore('oj_theme', value); + onChangeTheme && onChangeTheme(value); + } + + const handleSelectChange = (e, type) => { + const value = e.target.value; + if (type === 'font') { + handleChangeFont(value); + } + if (type === 'style') { + handleChangeStyle(value); + } + } const renderCtx = (title, content = [], type = 'label') => { const result = content.map((ctx, index) => { @@ -38,19 +66,25 @@ const SettingDrawer = (props) => { ); } else if (Array.isArray(value)) { + const defaultValue = ctx.type === 'font' ? fontSize : theme; + console.log('++', defaultValue); if (type === 'select') { - const child = ctx.value.map((opt, i) => ( - - )); + const child = ctx.value.map((opt, i) => { + return ( + + )}); renderResult = (
{ctx.text} - handleSelectChange(e, ctx.type)}> {child} -
+ ); } } diff --git a/public/react/src/modules/developer/components/myMonacoEditor/index.js b/public/react/src/modules/developer/components/myMonacoEditor/index.js index cb791f091..50d96db2d 100644 --- a/public/react/src/modules/developer/components/myMonacoEditor/index.js +++ b/public/react/src/modules/developer/components/myMonacoEditor/index.js @@ -4,11 +4,12 @@ * @Github: * @Date: 2019-11-27 15:02:52 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-05 10:17:04 + * @LastEditTime: 2019-12-06 16:50:54 */ import './index.scss'; import React, { useState, useRef, useEffect } from 'react'; import { Icon, Drawer, Modal } from 'antd'; +import { fromStore } from 'educoder'; import { connect } from 'react-redux'; import MonacoEditor from '@monaco-editor/react'; import SettingDrawer from '../../components/monacoSetting'; @@ -31,7 +32,12 @@ function MyMonacoEditor (props, ref) { const [showDrawer, setShowDrawer] = useState(false); // 控制配置滑框 const [editCode, setEditCode] = useState(''); // const [curLang, setCurLang] = useState('C'); - const [fontSize, setFontSize] = useState(12); + const [fontSize, setFontSize] = useState(() => { // 字体 + return +fromStore('oj_fontSize') || 14; + }); + const [theme, setTheme] = useState(() => { // 主题 theme + return fromStore('oj_theme') || 'dark'; + }); const [ height, setHeight ] = useState('calc(100% - 112px)'); const editorRef = useRef(null); @@ -54,9 +60,13 @@ function MyMonacoEditor (props, ref) { setShowDrawer(false); } // 侧边栏改变字体大小 - const handleFontSizeChange = (value) => { + const handleChangeFontSize = (value) => { setFontSize(value); } + // 改变主题 + const handleChangeTheme = (value) => { + setTheme(value); + } // 文本框内容变化时,记录文本框内容 const handleEditorChange = (origin, monaco) => { @@ -105,7 +115,7 @@ function MyMonacoEditor (props, ref) { language={language && language.toLowerCase()} value={editCode} options={editorOptions} - theme="dark" + theme={theme} // dark || light editorDidMount={handleEditorChange} /> @@ -117,7 +127,11 @@ function MyMonacoEditor (props, ref) { onClose={handleDrawerClose} visible={showDrawer} > - + diff --git a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js index f13c53b22..143e8b634 100644 --- a/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js +++ b/public/react/src/modules/developer/newOrEditTask/leftpane/editorTab/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-20 10:35:40 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-05 18:07:32 + * @LastEditTime: 2019-12-06 16:56:24 */ import 'quill/dist/quill.core.css'; import 'quill/dist/quill.bubble.css'; @@ -140,7 +140,7 @@ class EditTab extends React.Component { const { ojForm, ojFormValidate, - testCases = [], // 测试用例集合 + // testCases = [], // 测试用例集合 addTestCase, // 添加测试用例 deleteTestCase, // 删除测试用例 testCasesValidate, @@ -221,7 +221,7 @@ class EditTab extends React.Component { // TODO 点击新增时,需要滚到到最底部 this.scrollToBottom(); } - + // 编辑器配置信息 const quillConfig = [ [{ header: [1, 2, 3, 4, 5, 6, false] }], ['bold', 'italic', 'underline', 'strike'], // 切换按钮 diff --git a/public/react/src/modules/developer/studentStudy/index.js b/public/react/src/modules/developer/studentStudy/index.js index 5c9a89247..83ac2fe59 100644 --- a/public/react/src/modules/developer/studentStudy/index.js +++ b/public/react/src/modules/developer/studentStudy/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-23 10:53:19 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-04 14:02:05 + * @LastEditTime: 2019-12-06 17:02:32 */ import './index.scss'; import React, { useEffect } from 'react'; @@ -30,8 +30,6 @@ const StudentStudy = (props) => { saveUserProgramIdentifier, } = props; - - console.log(props); let { id } = params; // console.log(id); // 保存当前的id diff --git a/public/react/src/modules/developer/studentStudy/rightpane/index.js b/public/react/src/modules/developer/studentStudy/rightpane/index.js index 06f24f4ca..bc57e979d 100644 --- a/public/react/src/modules/developer/studentStudy/rightpane/index.js +++ b/public/react/src/modules/developer/studentStudy/rightpane/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-27 14:59:51 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-05 10:15:25 + * @LastEditTime: 2019-12-06 17:17:27 */ import React, { useState, useEffect } from 'react'; import {connect} from 'react-redux'; @@ -43,6 +43,17 @@ const RightPane = (props) => { // 保存用户提交的代码块 // console.log(code); // 保存用户代码块 + const { userCode } = props; + let timer; + if (!timer) { + timer = setInterval(() => { + if (userCode && userCode !== code) { + } else { + clearInterval(timer); + timer = null; + } + }, 3000); + } saveUserInputCode(code); } // 代码调试 @@ -75,10 +86,11 @@ const RightPane = (props) => { const mapStateToProps = (state) => { - const {user_program_identifier, hack, userTestInput} = state.ojForUserReducer; + const {user_program_identifier, hack, userTestInput, userCode} = state.ojForUserReducer; // const { language, code } = hack; return { hack, + userCode, input: userTestInput, submitInput: hack.input, identifier: user_program_identifier diff --git a/public/react/src/redux/actions/ojForUser.js b/public/react/src/redux/actions/ojForUser.js index f91020a3b..9ee998efc 100644 --- a/public/react/src/redux/actions/ojForUser.js +++ b/public/react/src/redux/actions/ojForUser.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2019-11-27 13:42:11 * @LastEditors: tangjiang - * @LastEditTime: 2019-12-05 10:44:17 + * @LastEditTime: 2019-12-06 17:16:14 */ import types from "./actionTypes"; import { Base64 } from 'js-base64'; @@ -81,8 +81,20 @@ export const getUserProgramDetail = (identifier, type) => { } } +export const saveUserCodeForInterval = (identifier, code) => { + return (dispatch) => { + fetchUpdateCode(identifier, { + code + }).then(res => { + if (res.data.status === 401) { + return; + }; + }); + } +} + /** - * @description 更新代码 + * @description 保存或更新之前先更新代码 * @param {*} identifier * @param {*} inputValue 输入值: 自定义 | 系统返回的 * @param {*} type 测评类型 debug | submit From 9d23d9d5903d4d2dc1e77760ff2a3a3d38076ec6 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, 6 Dec 2019 17:33:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/courses/elearning/YslDetailCards.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/elearning/YslDetailCards.js b/public/react/src/modules/courses/elearning/YslDetailCards.js index e6f362561..e705894e6 100644 --- a/public/react/src/modules/courses/elearning/YslDetailCards.js +++ b/public/react/src/modules/courses/elearning/YslDetailCards.js @@ -511,13 +511,15 @@ class YslDetailCards extends Component{ } -
  • + + {this.props.current_user&&this.props.current_user.admin===false&&line.shixun_status==="暂未公开"?"":
  • { showparagraphkey === key && showparagraphindex === index ? "" : 实验任务 {line.challenges_count} } -
  • + } + ) }) }