chromesetting
tangjiang 5 years ago
parent a99b4d3aac
commit 806630e1e4

@ -0,0 +1,30 @@
/*
* @Description:
* @Author: tangjiang
* @Github:
* @Date: 2019-12-13 10:28:15
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-13 10:37:17
*/
import { Modal } from 'antd';
export function ModalConfirm (
title,
content,
handleOk,
handleCancel
) {
Modal.confirm({
title,
content,
okText: '确定',
cancelText: '取消',
onOk () {
handleOk && handleOk();
},
onCancel () {
handleCancel && handleCancel();
}
});
}

@ -44,6 +44,13 @@ const maps = {
'value': '2'
}
],
'languageMenu': [
{
'key': 'c',
'name': 'C语言',
'value': 'c'
}
],
'difficultMenu': [
{
'key': '1',
@ -119,15 +126,14 @@ class DeveloperHome extends React.PureComponent {
>
{/* <Link to={`/problems/${record.identifier}/edit`}></Link> */}
</Button>
<Button
<Button
shape="circle"
type="danger"
icon="close"
size="small"
style={{ marginLeft: '10px' }}
style={{ marginLeft: '10px', display: record.open_or_not ? 'none' : 'inline-block' }}
onClick={() => this.handleClickDelete(record)}
>
{/* <Link to={`/problems/${record.identifier}/edit`}></Link> */}
</Button>
</React.Fragment>
),
@ -197,7 +203,6 @@ class DeveloperHome extends React.PureComponent {
componentDidMount() {
// 是否是我的,如果是我的 显示编辑按钮
const { isMySource } = this.props;
console.log(this.props);
if (isMySource) {
this.handleFilterSearch({come_from: 'mine'});
let _columns = this.columns.concat([this.options]);
@ -346,6 +351,14 @@ class DeveloperHome extends React.PureComponent {
});
this.handleFilterSearch({category: +item.key === 0 ? '' : +item.key});
}
// 下拉语言
handleLanguageMenuClick = (item) => {
this.addShowFilterCtx({
type: 'language',
key: item.key
});
this.handleFilterSearch({language: item.key})
}
// 难度下拉
handleHardMenuClick = (item) => {
this.addShowFilterCtx({
@ -474,6 +487,9 @@ class DeveloperHome extends React.PureComponent {
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('categoryMenu', this.handleCategoryMenuClick)}>
<span className={'dropdown-span'}>分类 <Icon type="down"/></span>
</Dropdown>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('languageMenu', this.handleLanguageMenuClick)}>
<span className={'dropdown-span'}>语言 <Icon type="down"/></span>
</Dropdown>
<Dropdown className={'dropdonw-style'} placement="bottomLeft" overlay={this.getMenuItems('difficultMenu', this.handleHardMenuClick)}>
<span className={'dropdown-span'}>难度 <Icon type="down"/></span>
</Dropdown>

@ -9,7 +9,7 @@ import './index.scss';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import SplitPane from 'react-split-pane';// import { Form } from 'antd';
import { Button } from 'antd';
import { Button, Modal } from 'antd';
import LeftPane from './leftpane';
import RightPane from './rightpane';
import { withRouter } from 'react-router';
@ -17,6 +17,7 @@ import { toStore } from 'educoder';
import UserInfo from '../components/userInfo';
// import RightPane from './rightpane/index';
import actions from '../../../redux/actions';
import {ModalConfirm} from '../../../common/components/ModalConfirm';
const NewOrEditTask = (props) => {
const {
@ -32,17 +33,18 @@ const NewOrEditTask = (props) => {
changePublishLoadingStatus,
startProgramQuestion,
getUserInfoForNew,
handleCancelPublish,
// updateTestAndValidate,
} = props;
// 表单提交
const handleSubmitForm = () => {
// 改变loading状态
changeSubmitLoadingStatus(true);
// 调用输入表单验证功能
if (props.identifier) {
props.handleUpdateOjForm(props);
} else {
// 改变loading状态
changeSubmitLoadingStatus(true);
props.handleFormSubmit(props); // 提交表单
}
};
@ -66,6 +68,9 @@ const NewOrEditTask = (props) => {
}, []);
// 模拟挑战
const imitationChallenge = () => {
}
// 开始挑战
const startChallenge = () => {
// 调用 start 接口, 成功后跳转到模拟页面
startProgramQuestion(identifier, props);
@ -84,9 +89,20 @@ const NewOrEditTask = (props) => {
// 发布
const handleClickPublish = () => {
// console.log('public has click');
changePublishLoadingStatus(true);
handlePublish(props, 'publish');
ModalConfirm('提示', (<p>发布后即可应用到自己管理的课堂<br /> 是否确认发布?</p>), () => {
changePublishLoadingStatus(true);
handlePublish(props, 'publish');
});
}
// 撤销发布
const handleClickCancelPublish = () => {
ModalConfirm('提示', (<p>是否确认撤销发布?</p>), () => {
changePublishLoadingStatus(true);
handleCancelPublish(props, identifier);
});
}
// 取消保存/取消按钮
@ -107,11 +123,23 @@ const NewOrEditTask = (props) => {
}
// 发布/模拟挑战
const renderPubOrFight = () => {
const pubButton = isPublish ? '' : (<Button
type="primary"
loading={publishLoading}
onClick={handleClickPublish}
>立即发布</Button>);
const pubButton = isPublish
? (<Button
type="primary"
loading={publishLoading}
onClick={handleClickCancelPublish}
>撤销发布</Button>)
: (<Button
type="primary"
loading={publishLoading}
onClick={handleClickPublish}
>立即发布</Button>);
// 未发布: 模拟挑战 已发布: 开始挑战
const challengeBtn = isPublish ? (
<Button type="primary" onClick={startChallenge}>开始挑战</Button>
) : (
<Button type="primary" onClick={imitationChallenge}>模拟挑战</Button>
);
return (
<React.Fragment>
<Button
@ -120,7 +148,8 @@ const NewOrEditTask = (props) => {
onClick={handleSubmitForm}
>更新</Button>
{pubButton}
<Button type="primary" onClick={startChallenge}>模拟挑战</Button>
{challengeBtn}
{/* <Button type="primary" onClick={startChallenge}>模拟挑战</Button> */}
</React.Fragment>
)
}
@ -142,24 +171,9 @@ const NewOrEditTask = (props) => {
return (
<div className={'new_add_task_wrap'}>
<div className={'task_header'}>
{/* <Link to="/problems" className={'header_btn'} >
<Icon type="left" style={{ marginRight: '5px'}}/>后退
</Link> */}
<UserInfo userInfo={userInfo}/>
<p className={'header_title'}>{props.name || ''}</p>
{ renderQuit() }
{/* <Link style={{
position: 'absolute',
right: '30px',
top: 0,
color: '#5091FF'
}} to="/problems">退出</Link> */}
{/* <Button
style={{ display: identifier ? 'none' : 'block'}}
loading={publishLoading}
className={`header_btn`}
type="primary"
onClick={handleClickPublish}>立即发布</Button> */}
</div>
<div className="split-pane-area">
<SplitPane split="vertical" minSize={350} maxSize={-350} defaultSize="40%">
@ -206,6 +220,8 @@ const mapDispatchToProps = (dispatch) => ({
handleFormSubmit: (props) => dispatch(actions.validateOjForm(props)),
// 发布表单
handlePublish: (props, type) => dispatch(actions.validateOjForm(props, type)),
// 撤销发布
handleCancelPublish: (props, identifier) => dispatch(actions.handleClickCancelPublish(props, identifier)),
// 更新OJForm
handleUpdateOjForm: (props) => dispatch(actions.validateOjForm(props)),
// 根据id号获取表单信息

@ -31,6 +31,7 @@ import {
testCaseOutputChange,
updateTestAndValidate,
updateOpenTestCaseIndex,
handleClickCancelPublish,
} from './ojForm';
import {
@ -79,6 +80,7 @@ export default {
validateOjTimeLimit,
validateOjCategory,
validateOpenOrNot,
handleClickCancelPublish,
addTestCase,
deleteTestCase,
testCaseInputChange,

@ -4,11 +4,16 @@
* @Github:
* @Date: 2019-11-20 16:35:46
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-10 19:54:56
* @LastEditTime: 2019-12-13 10:46:15
*/
import types from './actionTypes';
import CONST from '../../constants';
import { fetchPostOjForm, fetchGetOjById, publishTask } from '../../services/ojService';
import {
fetchPostOjForm,
fetchGetOjById,
publishTask,
cancelPublicTask
} from '../../services/ojService';
import { Base64 } from 'js-base64';
import { message, notification, Modal } from 'antd';
import { toStore } from 'educoder';
@ -80,6 +85,18 @@ const payloadInfo = (key, value, errMsg, validateInfo) => ({
}
});
// 接口调用成功后,跳转至列表页
function linkToDev (dispatch, props) {
toStore('oj_description', '');
dispatch({
type: types.IS_MY_SOURCE,
payload: true
});
setTimeout(() => {
props.history.push('/problems');
}, 1000);
}
// 表单提交验证
export const validateOjForm = (props, type) => {
return (dispatch, getState) => {
@ -229,59 +246,31 @@ export const validateOjForm = (props, type) => {
paramsObj['identifier'] = identifier;
}
// 接口调用成功后,跳转至列表页
function linkToDev () {
toStore('oj_description', '');
dispatch({
type: types.IS_MY_SOURCE,
payload: true
});
setTimeout(() => {
props.history.push('/problems');
}, 1000);
}
// 调用保存或更新
if (type === 'publish') {
// 提示发布信息
Modal.confirm({
title: '提示',
content: `
发布后即可应用到自己管理的课堂,
是否确定发布?`,
okText: '确定',
cancelText: '取消',
onOk () {
publishTask(identifier).then(res => {
if (res.data.status === 0) {
message.success('发布成功!');
linkToDev();
}
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
}).catch(() => {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
});
},
onCancel () {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
publishTask(identifier).then(res => {
if (res.data.status === 0) {
message.success('发布成功!');
linkToDev(dispatch, props);
}
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
}).catch(() => {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
});
} else {
// 调用更新
fetchPostOjForm(paramsObj).then(res => {
if (res.status === 200) { // 保存成功后,重新跳转至列表页
if (res.data.identifier) {
message.success('保存成功!');
linkToDev();
if (res.data.status === 0) {
message.success(paramsObj['submitType'] === 'update' ? '更新成功' : '保存成功');
linkToDev(dispatch, props);
}
dispatch({
type: types.SUBMIT_LOADING_STATUS,
@ -299,6 +288,29 @@ export const validateOjForm = (props, type) => {
}
}
};
// 撤销发布
export const handleClickCancelPublish = (props, identifier) => {
return (dispatch) => {
cancelPublicTask(identifier).then(res => {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
if (res.status = 200) {
const { data} = res;
if (data.status === 0) {
message.success('撤销发布成功!');
linkToDev(dispatch, props);
}
}
}).catch(() => {
dispatch({
type: types.PUBLISH_LOADING_STATUS,
payload: false
});
})
}
}
// 保存提交的代码
export const saveOjFormCode = (value) => {
return {

@ -4,7 +4,7 @@
* @Github:
* @Date: 2019-11-20 10:55:38
* @LastEditors: tangjiang
* @LastEditTime: 2019-12-10 20:46:16
* @LastEditTime: 2019-12-13 10:09:12
*/
import axios from 'axios';
@ -95,6 +95,12 @@ export async function publishTask (identifier) {
return axios.post(url);
}
// 撤销发布
export async function cancelPublicTask (identifier) {
const url = `/problems/${identifier}/cancel_publish.json`;
return axios.post(url);
}
// 更新用户编辑代码
export async function fetchUpdateCode (identifier, params) {
const url = `/myproblems/${identifier}/update_code.json`;

Loading…
Cancel
Save