From 5951519c27e3b7a8a101e0a8e2b2bbe1bce7b5ea Mon Sep 17 00:00:00 2001 From: tangjiang <465264938@qq.com> Date: Fri, 17 Jan 2020 10:21:30 +0800 Subject: [PATCH] add cookie --- public/react/package.json | 1 + public/react/src/modules/wxcode/index.js | 14 +++++++++++++- public/react/src/services/wxcodeService.js | 12 +++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/public/react/package.json b/public/react/package.json index 25aa1d87f..a30780480 100644 --- a/public/react/package.json +++ b/public/react/package.json @@ -75,6 +75,7 @@ "react-codemirror": "^1.0.0", "react-codemirror2": "^6.0.0", "react-content-loader": "^3.1.1", + "react-cookies": "^0.1.1", "react-dev-utils": "^5.0.0", "react-dom": "^16.9.0", "react-hot-loader": "^4.0.0", diff --git a/public/react/src/modules/wxcode/index.js b/public/react/src/modules/wxcode/index.js index 72892599a..15f3673b7 100644 --- a/public/react/src/modules/wxcode/index.js +++ b/public/react/src/modules/wxcode/index.js @@ -4,7 +4,7 @@ * @Github: * @Date: 2020-01-15 09:56:34 * @LastEditors : tangjiang - * @LastEditTime : 2020-01-16 15:22:25 + * @LastEditTime : 2020-01-17 10:19:51 */ import './index.scss'; import React, {useState, useEffect, useRef} from 'react'; @@ -12,6 +12,7 @@ import MonacoEditor from '@monaco-editor/react'; import { Input, Icon } from 'antd'; import { connect } from 'react-redux'; import actions from '../../redux/actions'; +import cookie from 'react-cookies'; const { TextArea } = Input; const App = (props) => { @@ -37,6 +38,17 @@ const App = (props) => { } = props; const {identifier} = props.match.params; + // 获取路径参数 + const _params = window.location.search; + if (_params) { + let _cookie = ''; + let _search = _params.split('?')[1]; + if(_search.split('=')) { + _cookie = _search.split('=')[1]; + cookie.save('_educoder_session', _cookie); + } + console.log(_cookie); + } const [isActive, setIsActive] = useState(-1); // const [isVisible, setIsVisible] = useState(false); const editorRef = useRef(null); diff --git a/public/react/src/services/wxcodeService.js b/public/react/src/services/wxcodeService.js index 0ab203b26..4c44b259e 100644 --- a/public/react/src/services/wxcodeService.js +++ b/public/react/src/services/wxcodeService.js @@ -4,41 +4,47 @@ * @Github: * @Date: 2020-01-15 15:44:36 * @LastEditors : tangjiang - * @LastEditTime : 2020-01-16 11:20:24 + * @LastEditTime : 2020-01-17 10:06:45 */ import axios from 'axios'; // 获取代码块 export async function fetchWxCode (identifier, params) { const url = `/tasks/${identifier}/rep_content.json`; + params = Object.assign({}, params, {withCredentials: true}); return axios.get(url, {params}); } // 获取测试值 export async function fetchWxCodeTextCase (identifier) { const url = `/tasks/${identifier}.json`; - return axios.get(url); + const params = Object.assign({}, {withCredentials: true}); + return axios.get(url, {params}); } // 更新代码块内容 export async function fetchUpdateWxCode (identifier, params) { // /myshixuns/8etu3pilsa/update_file.json const url = `/myshixuns/${identifier}/update_file.json`; + params = Object.assign({}, params, {withCredentials: true}); return axios.post(url, params); } // 恢复初始化 export async function fetchRestoreWxCode (identifier, params) { const url = `/tasks/${identifier}/reset_original_code.json`; + params = Object.assign({}, params, {withCredentials: true}); return axios.get(url, {params}); } // 评测 export async function fetchWxCodeGameBuild (identifier, params) { const url = `/tasks/${identifier}/game_build.json`; + params = Object.assign({}, params, {withCredentials: true}); return axios.get(url, {params}); } export async function fetchWxCodeGameStatus (identifier) { const url = `/tasks/${identifier}/game_status.json`; - return axios.get(url); + const params = Object.assign({}, {withCredentials: true}); + return axios.get(url, {params}); }