From ee9c926193a3793fb6fb0d9e142f8c8440411797 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, 25 Oct 2019 12:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E8=A1=8C=E6=A6=9Cmdend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Competitimain/CompetitionsIndex.js | 9 -- .../Competition_teams/Competitionteams.js | 2 +- .../Competitioncommon/CompetitionCommon.js | 43 +++++- .../CompetitionContentsChart.js | 54 ++++---- .../CompetitionContentsMd.js | 129 +++++++++++++----- .../src/modules/competitions/Competitions.js | 5 +- 6 files changed, 160 insertions(+), 82 deletions(-) diff --git a/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js b/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js index cd2870ac8..2009588b4 100644 --- a/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js +++ b/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js @@ -6,15 +6,6 @@ import axios from 'axios'; import './Competitionsindex.css'; import NoneData from "../../courses/coursesPublic/NoneData"; -const { SubMenu } = Menu; - -const IconText = ({ type, text }) => ( - - - {text} - -); - class CompetitionsIndex extends Component{ constructor(props) { super(props) diff --git a/public/react/src/modules/competitions/Competition_teams/Competitionteams.js b/public/react/src/modules/competitions/Competition_teams/Competitionteams.js index 303a8b0d6..6dd0de767 100644 --- a/public/react/src/modules/competitions/Competition_teams/Competitionteams.js +++ b/public/react/src/modules/competitions/Competition_teams/Competitionteams.js @@ -6,7 +6,7 @@ import axios from 'axios'; import NoneData from "../../courses/shixunHomework/shixunHomework"; import './Competitionteams.css'; -const { Header, Footer, Sider, Content } = Layout; +const { Content } = Layout; class Competitionteams extends Component{ constructor(props) { diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js index 3991277fb..0ff9f6bab 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js @@ -10,7 +10,7 @@ import NoneData from "../../courses/shixunHomework/shixunHomework"; import './CompetitionCommon.css'; -const { Header, Footer, Sider, Content } = Layout; +const {Sider } = Layout; class CompetitionCommon extends Component{ constructor(props) { @@ -20,6 +20,7 @@ class CompetitionCommon extends Component{ bannerdata:undefined, module_type:undefined, mdContentdata:undefined, + chart_rules:undefined, Competitionedittype:false } } @@ -84,19 +85,39 @@ class CompetitionCommon extends Component{ this.getlistdata(keys) } - getlistdata=(keys)=>{ + getlistdata=(keys,listkey)=>{ let{data}=this.state; this.setState({ thiskeys:keys }) data&&data.competition_modules.map((item,key)=>{ if(keys===item.position){ - this.getrightdata(item.id,item.module_type,item.module_url,item.has_url) + this.getrightdata(item.id,item.module_type,item.module_url,item.has_url,listkey) return } }) } - getrightdata=(id,typeid,module_url,has_url)=>{ + + getnewchartdata=(typeid,tabkey)=>{ + + if(typeid==="chart"){ + let url=`/competitions/${this.props.match.params.identifier}/chart_rules.json`; + axios.get(url) + .then((response) => { + if(response.status===200){ + this.setState({ + chart_rules:response.data, + tabkey:tabkey===undefined?response.data.stages[0].id===null?"0":`${response.data.stages[0].id}`:tabkey + }) + + + } + }).catch((error) => { + console.log(error) + }) + } + } + getrightdata=(id,typeid,module_url,has_url,listkey)=>{ this.setState({ module_id:id, @@ -106,6 +127,9 @@ class CompetitionCommon extends Component{ this.props.history.replace(`/newcompetitions/${this.props.match.params.identifier}/enroll`); return } + + this.getnewchartdata(typeid,listkey) + if(has_url===false){ let url=`${module_url}`; axios.get(url).then((response) => { @@ -176,7 +200,12 @@ class CompetitionCommon extends Component{ } } + Competitioncallback=(key)=>{ + this.setState({ + tabkey:key + }) + } render() { let {data,bannerdata,module_type,Competitionedittype,mdContentdata}=this.state; @@ -228,7 +257,7 @@ class CompetitionCommon extends Component{
{data.competition_status==="nearly_published"?"--":data&&data.visits_count}
-
this.gotocourse(`/newcompetitions/${this.props.match.params.identifier}/enroll`)}>{data.competition_status==="nearly_published"?"--":data&&data.member_count}
+
this.gotocourse(`/newcompetitions/${this.props.match.params.identifier}/enroll`)}>{data.competition_status==="nearly_published"?"--":data&&data.member_count}
@@ -293,6 +322,7 @@ class CompetitionCommon extends Component{ {...this.props} {...this.state} Competitionedit={()=>this.Competitionedit()} + Competitioncallback={(e)=>this.Competitioncallback(e)} />:"":Competitionedittype===false?this.Competitionedit()} {...this.props} @@ -304,7 +334,8 @@ class CompetitionCommon extends Component{ {/*/>*/} {Competitionedittype===true?this.hideCompetitionedit()} - getlistdata={(keys)=>this.getlistdata(keys)} + getlistdata={(keys,listkey)=>this.getlistdata(keys,listkey)} + Competitioncallback={(e)=>this.Competitioncallback(e)} {...this.props} {...this.state} />:""} diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js index a750379d5..bd706d649 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js @@ -1,10 +1,9 @@ import React, { Component } from 'react'; import {Button,Layout,Tabs,Icon, Card, Avatar, Row, Col ,Table} from 'antd'; -import axios from 'axios'; import {markdownToHTML,getImageUrl} from 'educoder'; import NoneData from "../../courses/shixunHomework/shixunHomework"; -const { Header, Footer, Sider, Content } = Layout; +const { Content } = Layout; const { TabPane } = Tabs; const { Meta } = Card; @@ -18,16 +17,6 @@ class CompetitionContents extends Component{ componentDidMount(){ window.document.title = '竞赛'; - this.gettitledata() - } - gettitledata=()=>{ - let url=`/competitions/${this.props.match.params.identifier}/chart_rules.json`; - axios.get(url) - .then((response) => { - console.log(response) - }).catch((error) => { - console.log(error) - }) } @@ -83,23 +72,34 @@ class CompetitionContents extends Component{ } ]; + let {chart_rules,tabkey}=this.props; + - return ( + return (
- - - - - - - - - - - - - - + {chart_rules===undefined?"":this.props.Competitioncallback(e)} activeKey={this.props.tabkey} tabBarExtraContent={this.props.current_user&&this.props.current_user.admin===true||this.props.current_user&&this.props.current_user.business===true?this.props.Competitionedittype===false?operations:"":""}> + + {chart_rules.stages.map((item,key)=>{ + return( + + {chart_rules.rule_contents.map((items,keys)=>{ + if(item.id===items.competition_stage_id){ + return( + + + ) + }else if(item.id===null&&items.competition_stage_id===0){ + return( + + + ) + } + })} + + ) + })} + + } diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js index 8a1bd9fd6..52ac666c1 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js @@ -1,8 +1,8 @@ import React, { Component } from 'react'; -import {Button, Card, Row, Col ,Upload,Icon,message} from 'antd'; +import {Button, Card, Row, Col ,Upload,Icon,message,Tabs} from 'antd'; import axios from 'axios'; import {getImageUrl,getUrl,appendFileSizeToUploadFileAll,appendFileSizeToUploadFile} from 'educoder'; - +const { TabPane } = Tabs; import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor'; class CompetitionContentsMd extends Component{ @@ -10,33 +10,65 @@ class CompetitionContentsMd extends Component{ super(props) this.contentMdRef = React.createRef(); this.state={ - contentFileList:[] + contentFileList:[], + chartmodule_id:undefined + } + } + componentDidUpdate =(prevState)=>{ + if(prevState.tabkey!=this.props.tabkey){ + this.getchartdata() } } - componentDidMount(){ window.document.title = '竞赛'; - let {mdContentdata}=this.props; - // this.gettitledata() + this.getchartdata() + } + + getchartdata=()=>{ + let {mdContentdata,chart_rules}=this.props; // is_pdf: false - // + if(this.props.module_type==="chart"){ + let type=true; + chart_rules.rule_contents.map((items,keys)=>{ + if(parseInt(this.props.tabkey)===items.competition_stage_id){ + console.log(items) + this.contentMdRef.current.setValue(items.content); + this.setState({ + contentFileList:undefined, + chartmodule_id:items.id + }) + type=false; + } + }) + + if(type===true){ + this.contentMdRef.current.setValue(""); + this.setState({ + contentFileList:undefined, + chartmodule_id:undefined + }) + + } + + }else{ let contentFileList = mdContentdata===undefined?[]:mdContentdata.attachments===undefined?[]:mdContentdata.attachments.map((item) => { - return { - id: item.id, - uid: item.id, - name: appendFileSizeToUploadFile(item), - url: item.url, - filesize: item.filesize, - status: 'done', - response:{id: item.id} - } - }) - this.setState({ - contentFileList:contentFileList - }) - this.contentMdRef.current.setValue(mdContentdata===undefined?"":mdContentdata.md_content===undefined?"":mdContentdata.md_content || '') + return { + id: item.id, + uid: item.id, + name: appendFileSizeToUploadFile(item), + url: item.url, + filesize: item.filesize, + status: 'done', + response:{id: item.id} + } + }) + this.setState({ + contentFileList:contentFileList + }) + this.contentMdRef.current.setValue(mdContentdata===undefined?"":mdContentdata.md_content===undefined?"":mdContentdata.md_content || '') + } } handleContentUploadChange = (info) => { @@ -45,7 +77,6 @@ class CompetitionContentsMd extends Component{ } onAttachmentRemove = (file, stateName) => { - debugger if(file.response!=undefined){ this.props.confirm({ content: '是否确认删除?', @@ -90,22 +121,37 @@ class CompetitionContentsMd extends Component{ handleSubmit = () => { let {contentFileList}=this.state; const mdContnet = this.contentMdRef.current.getValue().trim(); - let attachment_ids = contentFileList.map(item => { - return item.response ? item.response.id : item.id - }) - console.log(attachment_ids) + let attachment_ids=undefined + if(contentFileList!=undefined){ + attachment_ids= contentFileList.map(item => { + return item.response ? item.response.id : item.id + }) + } - let url=`/competitions/${this.props.match.params.identifier}/update_md_content.json`; - axios.post(url,{ - md_content_id:this.props.mdContentdata.md_id, - competition_module_id:this.props.mdContentdata.id, - content:mdContnet, - attachment_ids:attachment_ids + let newstage_id=parseInt(this.props.tabkey)===0||null?undefined:parseInt(this.props.tabkey) + let data={} + if(this.props.module_type==="chart"){ + data={ + md_content_id:this.state.chartmodule_id, + competition_module_id:this.props.module_id, + stage_id:newstage_id, + content:mdContnet, + } + }else{ + data={ + md_content_id:this.props.mdContentdata.md_id, + competition_module_id:this.props.mdContentdata.id, + content:mdContnet, + attachment_ids:attachment_ids } + } + + let url=`/competitions/${this.props.match.params.identifier}/update_md_content.json`; + axios.post(url,data ).then((response) => { if(response.data.status===0){ this.props.showNotification(response.data.message); - this.props.getlistdata(this.props.thiskeys); + this.props.getlistdata(this.props.thiskeys,this.props.tabkey); this.props.hideCompetitionedit(); }else{ this.props.showNotification(response.data.message); @@ -117,6 +163,7 @@ class CompetitionContentsMd extends Component{ } render() { let {contentFileList}=this.state; + let {chart_rules}=this.props; const uploadProps = { width: 600, fileList: contentFileList, @@ -136,18 +183,28 @@ class CompetitionContentsMd extends Component{ return isLt150M; }, }; - console.log(contentFileList) + // console.log(this.props.tabkey) + // console.log(chart_rules) + // console.log(this.props.mdContentdata) return (
+ {chart_rules===undefined?"":this.props.module_type==="chart"?this.props.Competitioncallback(e)}> + + {chart_rules.stages.map((item,key)=>{ + return( + + ) + })} + :""} - + {this.props.module_type==="chart"?"": (单个文件150M以内) - + }
{/* htmlType="submit" */} diff --git a/public/react/src/modules/competitions/Competitions.js b/public/react/src/modules/competitions/Competitions.js index bc9623e6f..4ec33b43b 100644 --- a/public/react/src/modules/competitions/Competitions.js +++ b/public/react/src/modules/competitions/Competitions.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { Redirect } from 'react-router'; -import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom"; +import { Route, Link, Switch } from "react-router-dom"; import Loading from '../../Loading'; @@ -41,8 +41,7 @@ class Competitions extends Component { } componentDidMount(){ - console.log("Competitions竞赛"); - console.log(this.props); + window.document.title = '竞赛'; }