From dd25f38b8fd7bafea33b521044c27f9bc77034db 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 00:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E5=86=85=E5=AE=B9end?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/config/webpack.config.prod.js | 2 +- .../Competition_teams/Competitionteams.js | 24 ++- .../Competitioncommon/CompetitionCommon.js | 71 +++++++- .../Competitioncommon/CompetitionContents.js | 14 +- .../CompetitionContentsChart.js | 4 +- .../CompetitionContentsMd.js | 163 ++++++++++++++++++ .../src/modules/competitions/Competitions.js | 4 +- 7 files changed, 257 insertions(+), 25 deletions(-) create mode 100644 public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js diff --git a/public/react/config/webpack.config.prod.js b/public/react/config/webpack.config.prod.js index 886d97313..1cc105517 100644 --- a/public/react/config/webpack.config.prod.js +++ b/public/react/config/webpack.config.prod.js @@ -321,7 +321,7 @@ module.exports = { }, compress: { drop_debugger: true, - drop_console: true + drop_console: false } } }), diff --git a/public/react/src/modules/competitions/Competition_teams/Competitionteams.js b/public/react/src/modules/competitions/Competition_teams/Competitionteams.js index 46302b5ab..303a8b0d6 100644 --- a/public/react/src/modules/competitions/Competition_teams/Competitionteams.js +++ b/public/react/src/modules/competitions/Competition_teams/Competitionteams.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { Breadcrumb,Layout,Table, Divider, Tag,Badge,Tooltip} from 'antd'; - +import { Link } from 'react-router-dom'; import axios from 'axios'; import NoneData from "../../courses/shixunHomework/shixunHomework"; @@ -19,6 +19,18 @@ class Competitionteams extends Component{ componentDidMount(){ window.document.title = '竞赛'; + if(this.props.match.params.identifier!=null){ + let url=`/competitions/${this.props.match.params.identifier}/common_header.json`; + axios.get(url).then((response) => { + if(response.status===200){ + this.setState({ + data:response.data, + }) + } + }).catch((error) => { + console.log(error) + }) + } this.getshixundata(); this.getcoursedata(); @@ -131,7 +143,7 @@ class Competitionteams extends Component{ } render() { - + let {data}=this.state; const shixuncolumns = [ { title: '创建者', @@ -224,14 +236,14 @@ class Competitionteams extends Component{ ]; - console.log(this.state.shixundata) + // console.log(this.state.shixundata) return (
- 全国高校计算机大赛战 - 报名 - 战队详情 + {data&&data.name} + 报名 + 战队详情 diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js index 845182958..a83f799fb 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionCommon.js @@ -5,6 +5,7 @@ import axios from 'axios'; import {markdownToHTML,getImageUrl} from 'educoder'; import CompetitionContents from './CompetitionContents'; import CompetitionContentsChart from './CompetitionContentsChart'; +import CompetitionContentsMd from './CompetitionContentsMd'; import NoneData from "../../courses/shixunHomework/shixunHomework"; import './CompetitionCommon.css'; @@ -18,7 +19,8 @@ class CompetitionCommon extends Component{ data:undefined, bannerdata:undefined, module_type:undefined, - mdContentdata:undefined + mdContentdata:undefined, + Competitionedittype:false } } @@ -46,6 +48,7 @@ class CompetitionCommon extends Component{ if(response.status===200){ this.setState({ data:response.data, + thiskeys:response.data.competition_modules[0].position }) this.getrightdata( response.data.competition_modules[0].id, @@ -59,12 +62,33 @@ class CompetitionCommon extends Component{ }) } + getrightdatas=(e)=>{ + let keys=parseInt(e.key); + this.getlistdata(keys) + } + + getlistdata=(keys)=>{ + 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) + return + } + }) + } getrightdata=(id,typeid,module_url,has_url)=>{ console.log(id,typeid,module_url,has_url) this.setState({ module_id:id, module_type:typeid }) + if(typeid==="enroll"){ + this.props.history.replace(`/newcompetitions/${this.props.match.params.identifier}/enroll`); + return + } if(has_url===false){ let url=`${module_url}`; axios.get(url).then((response) => { @@ -76,19 +100,38 @@ class CompetitionCommon extends Component{ }).catch((error) => { console.log(error) }) + }else{ + this.props.history.replace(module_url); + return } } + Competitionedit=()=>{ + + this.setState({ + Competitionedittype:true + }) + + } + + hideCompetitionedit=()=>{ + this.setState({ + Competitionedittype:false + }) + + } + + render() { - let {data,bannerdata,module_type,module_id,mdContentdata}=this.state; + let {data,bannerdata,module_type,Competitionedittype,mdContentdata}=this.state; console.log(module_type) return ( data===undefined?"":
- 在线竞赛 - {data&&data.name} + 在线竞赛 + {data&&data.name}
@@ -173,12 +216,14 @@ class CompetitionCommon extends Component{ - + this.getrightdatas(e)}> {data&&data.competition_modules.map((item,key)=>{ return( - {item.has_url===false?this.getrightdata(item.id,item.module_type,item.module_url,item.has_url)}>{item.name}:this.getrightdata(item.id,item.module_type,item.module_url,item.has_url)} + >{item.name}:this.getrightdata(item.id,item.module_type)} @@ -191,17 +236,25 @@ class CompetitionCommon extends Component{ - {this.state.module_type==="chart"?:this.Competitionedit()} + />:"":Competitionedittype===false?this.Competitionedit()} {...this.props} {...this.state} - />} + />:""} {/**/} + {Competitionedittype===true?this.hideCompetitionedit()} + getlistdata={(keys)=>this.getlistdata(keys)} + {...this.props} + {...this.state} + />:""} diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContents.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContents.js index f9d966be0..3f0ad049e 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionContents.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContents.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import {Button,Layout} from 'antd'; import axios from 'axios'; -import {markdownToHTML,getImageUrl} from 'educoder'; +import {markdownToHTML,getImageUrl,AttachmentList} from 'educoder'; import NoneData from "../../courses/shixunHomework/shixunHomework"; const { Header, Footer, Sider, Content } = Layout; @@ -26,12 +26,16 @@ class CompetitionContents extends Component{ return (
- {this.props.current_user&&this.props.current_user.admin===true||this.props.current_user&&this.props.current_user.business===true?:""} -
- + :"":""} +
+ + +
+ +
diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js index 765559e52..d86f8af97 100644 --- a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsChart.js @@ -32,7 +32,7 @@ class CompetitionContents extends Component{ render() { - const operations = ; + const operations = ; const columns = [ { title: 'usersum', @@ -86,7 +86,7 @@ class CompetitionContents extends Component{ return (
- + diff --git a/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js new file mode 100644 index 000000000..f5043f187 --- /dev/null +++ b/public/react/src/modules/competitions/Competitioncommon/CompetitionContentsMd.js @@ -0,0 +1,163 @@ +import React, { Component } from 'react'; +import {Button, Card, Row, Col ,Upload,Icon,message} from 'antd'; +import axios from 'axios'; +import {getImageUrl,getUrl,appendFileSizeToUploadFileAll,appendFileSizeToUploadFile} from 'educoder'; + +import TPMMDEditor from '../../tpm/challengesnew/TPMMDEditor'; + +class CompetitionContentsMd extends Component{ + constructor(props) { + super(props) + this.contentMdRef = React.createRef(); + this.state={ + contentFileList:[] + } + } + + componentDidMount(){ + window.document.title = '竞赛'; + let {mdContentdata}=this.props; + // this.gettitledata() + + // is_pdf: false + // + 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 || '') + + } + + handleContentUploadChange = (info) => { + let contentFileList = info.fileList; + this.setState({ contentFileList: appendFileSizeToUploadFileAll(contentFileList) }); + } + + onAttachmentRemove = (file, stateName) => { + debugger + if(file.response!=undefined){ + this.props.confirm({ + content: '是否确认删除?', + + onOk: () => { + this.deleteAttachment(file, stateName) + }, + onCancel() { + console.log('Cancel'); + }, + }); + return false; + } + + } + deleteAttachment = (file, stateName) => { + // 初次上传不能直接取uid + const url = `/attachments/${file.response ? file.response.id : file.uid}.json` + axios.delete(url, { + }) + .then((response) => { + if (response.data) { + const { status } = response.data; + if (status == 0) { + console.log('--- success') + this.props.showNotification(response.data.message); + this.setState((state) => { + const index = state[stateName].indexOf(file); + const newFileList = state[stateName].slice(); + newFileList.splice(index, 1); + return { + [stateName]: newFileList, + }; + }); + } + } + }) + .catch(function (error) { + console.log(error); + }); + } + 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 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, + name:"编辑", + attachment_ids:attachment_ids + } + ).then((response) => { + if(response.data.status===0){ + this.props.showNotification(response.data.message); + this.props.getlistdata(this.props.thiskeys); + this.props.hideCompetitionedit(); + }else{ + this.props.showNotification(response.data.message); + } + }).catch((error) => { + console.log(error) + }) + + } + render() { + let {contentFileList}=this.state; + const uploadProps = { + width: 600, + fileList: contentFileList, + multiple: true, + // https://github.com/ant-design/ant-design/issues/15505 + // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 + // showUploadList: false, + action: `${getUrl()}/api/attachments.json`, + onChange: this.handleContentUploadChange, + onRemove: (file) => this.onAttachmentRemove(file, 'contentFileList'), + beforeUpload: (file) => { + console.log('beforeUpload', file.name); + const isLt150M = file.size / 1024 / 1024 < 150; + if (!isLt150M) { + message.error('文件大小必须小于150MB!'); + } + return isLt150M; + }, + }; + console.log(contentFileList) + return ( + + + ) + } +} +export default CompetitionContentsMd; \ No newline at end of file diff --git a/public/react/src/modules/competitions/Competitions.js b/public/react/src/modules/competitions/Competitions.js index 1b8da55d7..bc9623e6f 100644 --- a/public/react/src/modules/competitions/Competitions.js +++ b/public/react/src/modules/competitions/Competitions.js @@ -8,7 +8,7 @@ import Loading from '../../Loading'; import Loadable from 'react-loadable'; import { TPMIndexHOC } from '../tpm/TPMIndexHOC'; -import { SnackbarHOC } from 'educoder'; +import { CNotificationHOC } from '../courses/common/CNotificationHOC'; //新版竞赛首页 const CompetitionsIndex = Loadable({ @@ -90,4 +90,4 @@ class Competitions extends Component { } } -export default SnackbarHOC() (TPMIndexHOC (Competitions)) ; \ No newline at end of file +export default CNotificationHOC() (TPMIndexHOC (Competitions)) ; \ No newline at end of file