update oj url match question

mast_item_banktwo
tangjiang 5 years ago
parent fe9b028827
commit 875af5efb6

@ -35,7 +35,9 @@ const NewOrEditTask = (props) => {
getUserInfoForNew,
handleCancelPublish,
validateOjForm,
getQuestion
getQuestion,
saveSearchParams,
setOjInitialValue
// updateTestAndValidate,
} = props;
@ -61,7 +63,26 @@ const NewOrEditTask = (props) => {
// 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);
if ($searchs) {
const $params = $searchs.split('&') || [];
let obj = Object.create(null);
$params.forEach(item => {
const keys = item.split('=');
obj[keys[0]] = keys[1];
});
// 保存初始值
if (obj['newoj']) {
setOjInitialValue({
difficult: obj['difficult'],
sub_discipline_id: obj['sub_discipline_id'],
tag_discipline_id: obj['tag_discipline_id'] && obj['tag_discipline_id'].split(',')
});
}
saveSearchParams({searchParams: $searchs, curPage: obj['pages']});
}
if (id) { // id号即 identifier
// TODO id 存在时, 编辑, 获取 store 中的记录数
props.getOJFormById(id);
@ -96,7 +117,8 @@ const NewOrEditTask = (props) => {
props.clearOJFormStore();
// 清空描述信息
toStore('oj_description', '');
props.history.push('/problems');
// props.history.push('/problems');
props.history.push(`/question?${props.searchParams}`);
}
// 发布
@ -236,7 +258,7 @@ const NewOrEditTask = (props) => {
}
const mapStateToProps = (state) => {
const { ojForm, identifier, testCases, isPublish } = state.ojFormReducer;
const { ojForm, identifier, testCases, isPublish, searchParams } = state.ojFormReducer;
const { publishLoading, submitLoading } = state.commonReducer;
const { userInfo } = state.userReducer;
return {
@ -246,7 +268,8 @@ const mapStateToProps = (state) => {
isPublish, // 是否已发布
publishLoading,
submitLoading,
userInfo
userInfo,
searchParams
}
};
@ -278,7 +301,9 @@ const mapDispatchToProps = (dispatch) => ({
// 新建时获取信息
getUserInfoForNew: () => dispatch(actions.getUserInfoForNew()),
validateOjForm: (props, type, cb) => dispatch(actions.validateOjForm(props, type, cb)),
getQuestion: (params) => dispatch(actions.getQuestion(params))
getQuestion: (params) => dispatch(actions.getQuestion(params)),
saveSearchParams: (params) => dispatch(actions.saveSearchParams(params)),
setOjInitialValue: (params) => dispatch(actions.setOjInitialValue(params))
});
export default withRouter(connect(

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-23 10:53:19
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-06 15:27:34
* @LastEditTime : 2020-02-10 18:24:01
*/
import './index.scss';
import React, { useEffect, useState } from 'react';
@ -31,7 +31,9 @@ function StudentStudy (props) {
// user_program_identifier,
restoreInitialCode,
changeUserCodeTab,
changeShowOrHideControl
changeShowOrHideControl,
searchParams,
saveSearchParams
} = props;
const {
@ -47,7 +49,16 @@ function StudentStudy (props) {
saveUserProgramIdentifier(id);
// startProgramQuestion(id);
getUserProgramDetail(id);
const $searchs = window.location.search && window.location.search.substring(1);
if ($searchs) {
const $params = $searchs.split('&') || [];
let obj = Object.create(null);
$params.forEach(item => {
const keys = item.split('=');
obj[keys[0]] = keys[1];
});
saveSearchParams({searchParams: $searchs, curPage: obj['pages']});
}
if (tab) {
changeUserCodeTab(tab);
}
@ -97,7 +108,7 @@ function StudentStudy (props) {
changeShowOrHideControl(false);
props.saveEditorCodeForDetail('');
props.clearOjForUserReducer();
props.history.push(`/problems/${identifier}/edit`);
props.history.push(`/problems/${identifier}/edit?{searchParams}`);
}
// 处理退出
const handleClickQuit = () => {
@ -106,7 +117,8 @@ function StudentStudy (props) {
// 将控制台关闭
changeShowOrHideControl(false);
props.saveEditorCodeForDetail('');
props.history.push('/problems');
// props.history.push('/problems');
props.history.push(`/question?${searchParams}`);
}
return (
@ -163,11 +175,13 @@ function StudentStudy (props) {
const mapStateToProps = (state) => {
const { userInfo } = state.userReducer;
const { hack_identifier, user_program_identifier, hack } = state.ojForUserReducer;
const { searchParams } = state.ojFormReducer;
return {
hack,
userInfo,
user_program_identifier,
hack_identifier
hack_identifier,
searchParams
};
};
@ -182,7 +196,8 @@ const mapDispatchToProps = (dispatch) => ({
restoreInitialCode: (identifier, msg) => dispatch(actions.restoreInitialCode(identifier, msg)),
changeShowOrHideControl: (flag) => dispatch(actions.changeShowOrHideControl(flag)),
clearOjForUserReducer: () => dispatch(actions.clearOjForUserReducer()),
changeUserCodeTab: (tab) => dispatch(actions.changeUserCodeTab(tab))
changeUserCodeTab: (tab) => dispatch(actions.changeUserCodeTab(tab)),
saveSearchParams: (params) => dispatch(actions.saveSearchParams(params))
});
export default withRouter(connect(

@ -37,6 +37,7 @@ const types = {
GET_COURSE_QUESTION: 'GET_COURSE_QUESTION', // 获取编辑题
CHANGE_KNOWLEDGES: 'CHANGE_KNOWLEDGES', // 保存所选择的知识点
SET_OJ_INITIAL_VALUE: 'SET_OJ_INITIAL_VALUE', // 设置初始值
SET_SEARCH_PARAMS: 'SET_SEARCH_PARAMS', // 只在地址栏参数
// study
SAVE_USER_PROGRAM_ID: 'SAVE_USER_PROGRAM_ID',// 保存用户编程题id值
USER_PROGRAM_DETAIL: 'USER_PROGRAM_DETAIL', // 用户编程题详情

@ -38,7 +38,8 @@ import {
getQuestion,
saveKnowledge,
setOjInitialValue,
tagDisciplines
tagDisciplines,
saveSearchParams
} from './ojForm';
import {
@ -145,6 +146,7 @@ export default {
saveKnowledge,
setOjInitialValue,
tagDisciplines,
saveSearchParams,
//
addTestCase,
deleteTestCase,

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-27 13:42:11
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-09 14:14:47
* @LastEditTime : 2020-02-10 18:17:00
*/
import types from "./actionTypes";
import { Base64 } from 'js-base64';
@ -24,7 +24,9 @@ import { notification } from "antd";
// 进入编程页面时,首先调用开启编程题接口
export const startProgramQuestion = (id, props) => {
return (dispatch) => {
return (dispatch, getState) => {
const {searchParams} = getState().ojFormReducer;
console.log(searchParams);
fetchStartProgram(id).then(res => {
const { status, data } = res;
if (status === 200) {
@ -48,7 +50,7 @@ export const startProgramQuestion = (id, props) => {
// console.log(path);
// props.history.push(`/myproblems/${identifier}`);
props.history.push({
pathname: `/myproblems/${identifier}`,
pathname: `/myproblems/${identifier}?${searchParams}`,
});
}
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 16:35:46
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-07 16:45:34
* @LastEditTime : 2020-02-10 18:09:17
*/
import types from './actionTypes';
import CONST from '../../constants';
@ -206,7 +206,7 @@ export const validateOjForm = (props, type, cb) => {
if (hasSuccess) {
// console.log('表单保存的数据为: ', getState());
const {ojFormReducer} = getState();
const {code, score, ojForm, testCases = [], tag_discipline_id = []} = ojFormReducer;
const {code, score, ojForm, testCases = [], tag_discipline_id = [], curPage = 1} = ojFormReducer;
const {category, description, difficult, language, name, openOrNot, timeLimit, sub_discipline_id} = ojForm;
let paramsObj = {};
const hack = { // 编程题干
@ -312,14 +312,19 @@ export const validateOjForm = (props, type, cb) => {
payload: identifier
});
console.log(identifier , props.identifier);
// console.log(identifier , props.identifier);
if (identifier || props.identifier) {
dispatch(getOJFormById(identifier || props.identifier));
}
// 保存成功后,调用编辑接口并改变路
if (paramsObj['submitType'] === 'add' && identifier) {
props.history.push(`/problems/${identifier}/edit`);
//更改查询参数
dispatch({
type: types.SET_SEARCH_PARAMS,
searchParams: `editoj=1&pages=${curPage}`,
curPage: curPage
});
props.history.push(`/problems/${identifier}/edit?editoj=1&pages=${curPage}`);
};
}
// 保存或更新后调用start接口
@ -763,3 +768,11 @@ export const tagDisciplines = (params) => {
});
}
}
// 保存地址栏参数
export const saveSearchParams = (params) => {
return {
type: types.SET_SEARCH_PARAMS,
payload: params
}
}

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 16:40:32
* @LastEditors : tangjiang
* @LastEditTime : 2020-01-03 17:38:50
* @LastEditTime : 2020-02-10 17:59:55
*/
import { Base64 } from 'js-base64';
import types from '../actions/actionTypes';
@ -75,6 +75,8 @@ const init = {
isPublish: 0, // 是否是发布状态: 0 未发布 1 已发布
courseQuestions: [], // 课程题库
knowledges: [], // 知识点下拉值
searchParams: '', // 地址栏参数
curPage: 1, // 当前页数
}
const tcValidateObj = {
@ -350,11 +352,18 @@ const ojFormReducer = (state = initialState, action) => {
}
case types.SET_OJ_INITIAL_VALUE:
const _p = action.payload;
console.log(_p.tag_discipline_id);
return {
...state,
ojForm: Object.assign({}, state.ojForm, {difficult: _p.difficult, sub_discipline_id: _p.sub_discipline_id}),
tag_discipline_id: _p.tag_discipline_id || []
}
case types.SET_SEARCH_PARAMS:
return {
...state,
searchParams: action.payload.searchParams,
curPage: action.payload.curPage
}
default:
return state;
}

Loading…
Cancel
Save