From 4aa080fed702728705c0a7eaf46c8771339ddfe5 Mon Sep 17 00:00:00 2001 From: kdxcxs Date: Tue, 3 Nov 2020 23:07:41 +0800 Subject: [PATCH] feat: support register --- public/favicon.ico | Bin 0 -> 4286 bytes src/App.js | 47 ++++++++++---- src/Female.js | 152 ++++++++++++++++++++++++++++++++++++++++++++ src/Login.js | 18 +++++- src/Male.js | 155 +++++++++++++++++++++++++++++++++++++++++++++ src/Team.js | 143 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 500 insertions(+), 15 deletions(-) create mode 100644 public/favicon.ico create mode 100644 src/Female.js create mode 100644 src/Male.js create mode 100644 src/Team.js diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..bd1b49baf5269beea8bb312d99fa32c30778bdee GIT binary patch literal 4286 zcmc&&XHb<_8ot@|=9pNq#Z)z#xRYeuO*7dPvum;@(M;T|pdyMufD2M0SP&`FdzW@E zZe zjjZ?tROS|-G(8Jhssw05!m&RmAJ;m&Fg!FQ*NC-uDdUe00XaH)e_dZsFHW=^Mrv3D zn#!wCTUL(d%4%Hcx{SerLG<13L2E-ZGGgMDiMi(LD2FNL+nIO zcnrKZm`j^`ZrsGF`eu~GC!s7k4Jr>`be+E-=a!^q;Owc>7^c5yB6dR?7KPJCjw0UM zm;2Et=jgEH&De+F@=pI9sqe*e=P^pY%s%)GKE~#_-P0p+HJ*NO{L2?G*PDlxis!KE zk#YD*F%CvgO@;N#e}>bS-=ZKYPD*TTY{JS{=V4z)w!A;zdJ^h@pa(q2hx`z>-4zbU zkx4&p=R7e61_x1FUXJJ;u28#pLizf8Fq`lioIhF$ukZeiDCI9marZ;gHaB=I`w7Zf z3t{~DG#EWS9ro{hg8ax>WQIgwkaBe6)X`(eh>erCIu1t1;-jIW3VEsNxY*Hw_LHY@ zx&0ja$wzJJK7_6{MYxF-lD+&;m6L>MQd2O`-g0Li`q$cv6gps5u$zw;?f$Gw8} zkLh9U_*p1O)Zk=eGpcg;;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w(=%Z9!mHBH ztmtdDoMS%z6`Aic{l;X3vqvEB!p>r1wA3Dyvc>sA3|%jjtxm)l)}qtLPauS~sGL2< z@W?QZSJqU}c!^#uF*p<#&YojU=!V_b-@(Je3f)(_<+MunJ1+lN0oykg z!H|8P$nl26TlW-e&760!W9bU)V?Qj$rLIeGv$TTaS|gl0a|RuZ(^&fXAbnd{E$|*5 zIu7pi^&_5rT`Oyt=#_k}?P0m>d&K$pqN$;tK5|cK`ncV8lJ(6sY3JA#w!iG6MC z;7)sD-Mx^;UNM_>T=Yw=F(?!%?3Jt72Z}TL$XH$zTuZxu2UGWdfdAL`e*kQ0=!F0P literal 0 HcmV?d00001 diff --git a/src/App.js b/src/App.js index 041e63c..c40341e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,21 +1,40 @@ import React from "react"; import Login from "./Login"; -import Register from "./register"; +import ProgramType from "./ProgramType"; +import Male from "./Male"; +import Female from "./Female"; +import Team from "./Team"; import {HashRouter, Switch, Route} from 'react-router-dom'; -function App() { - return ( - - - - - - - - - - - ); +class App extends React.Component { + componentDidMount() { + document.location.hash = ''; + } + + + render() { + return ( + + + + + + + + + + + + + + + + + + + + ); + } } export default App; diff --git a/src/Female.js b/src/Female.js new file mode 100644 index 0000000..57a5d1d --- /dev/null +++ b/src/Female.js @@ -0,0 +1,152 @@ +import React from "react"; +import {withStyles} from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import Typography from "@material-ui/core/Typography"; +import Backdrop from "@material-ui/core/Backdrop"; +import Fade from "@material-ui/core/Fade"; +import Modal from "@material-ui/core/Modal"; +import CssBaseline from "@material-ui/core/CssBaseline"; +import Container from "@material-ui/core/Container"; +import {Link} from "react-router-dom"; + +const useStyles = theme => ({ + buttonPaper: { + display: 'flex', + flexDirection: 'column', + textAlign: 'center', + '& > *': { + marginTop: theme.spacing(2), + }, + }, + modalPaper: { + backgroundColor: theme.palette.background.paper, + border: '2px solid #000', + boxShadow: theme.shadows[5], + padding: theme.spacing(2, 4, 3), + }, + modal: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, +}); + +class Female extends React.Component { + constructor(props) { + super(props); + this.state = { + open: false, + modalTitle: '', + modalContent: '', + programs: [{ + program: '100', + handler: () => this.handleClick('100') + }, { + program: '200', + handler: () => this.handleClick('200') + }, { + program: '400', + handler: () => this.handleClick('400') + }, { + program: '800', + handler: () => this.handleClick('800') + }, { + program: '跳高', + handler: () => this.handleClick('跳高') + }, { + program: '跳远', + handler: () => this.handleClick('跳远') + }, { + program: '三级跳', + handler: () => this.handleClick('三级跳') + }, { + program: '铅球', + handler: () => this.handleClick('铅球') + }], + }; + this.handleClick = this.handleClick.bind(this); + this.openModal = this.openModal.bind(this); + this.handleCloseModal = this.handleCloseModal.bind(this); + } + + openModal(modalTitle, modalContent) { + this.setState({ + modalTitle, + modalContent, + }); + this.setState({'open': true}); + } + + handleCloseModal() { + this.setState({'open': false}); + } + + handleClick(program_name) { + const program_type = '女子'; + fetch('/register', { + method: 'Post', + body: JSON.stringify({ + program_type, + program_name, + }) + }) + .then(response => response.json()) + .then(json => { + if (json.result === 'success') { + this.openModal('成功', '成功报名女子项目' + program_name); + } else { + this.openModal('失败', '报名女子项目' + program_name + '时失败'); + } + }); + } + + render() { + return ( + + +
+ + 请选择项目 + + { + this.state.programs.map(item => + ) + } + +
+ + +
+

{this.state.modalTitle}

+

{this.state.modalContent}

+
+
+
+
+ ); + } +} + +export default withStyles(useStyles)(Female); \ No newline at end of file diff --git a/src/Login.js b/src/Login.js index 36d65b9..553e557 100644 --- a/src/Login.js +++ b/src/Login.js @@ -57,6 +57,22 @@ class Login extends React.Component { this.handleCloseModal = this.handleCloseModal.bind(this); } + componentDidMount() { + if (document.cookie.includes('jwt')) { + fetch('/login', { + method: 'Post' + }) + .then(response => response.json()) + .then(json => { + if (json.result === 'success') { + this.props.history.push('/type'); + } else { + this.handleOpenModal(); + } + }); + } + } + handleOpenModal() { this.setState({open: true}); } @@ -79,7 +95,7 @@ class Login extends React.Component { .then(response => response.json()) .then(json => { if (json.result === 'success') { - this.props.history.push('/register'); + this.props.history.push('/type'); } else { this.handleOpenModal(); } diff --git a/src/Male.js b/src/Male.js new file mode 100644 index 0000000..cfb7f62 --- /dev/null +++ b/src/Male.js @@ -0,0 +1,155 @@ +import React from "react"; +import {withStyles} from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import Typography from "@material-ui/core/Typography"; +import Backdrop from "@material-ui/core/Backdrop"; +import Fade from "@material-ui/core/Fade"; +import Modal from "@material-ui/core/Modal"; +import CssBaseline from "@material-ui/core/CssBaseline"; +import Container from "@material-ui/core/Container"; +import {Link} from "react-router-dom"; + +const useStyles = theme => ({ + buttonPaper: { + display: 'flex', + flexDirection: 'column', + textAlign: 'center', + '& > *': { + marginTop: theme.spacing(2), + }, + }, + modalPaper: { + backgroundColor: theme.palette.background.paper, + border: '2px solid #000', + boxShadow: theme.shadows[5], + padding: theme.spacing(2, 4, 3), + }, + modal: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, +}); + +class Male extends React.Component { + constructor(props) { + super(props); + this.state = { + open: false, + modalTitle: '', + modalContent: '', + programs: [{ + program: '100', + handler: () => this.handleClick('100') + }, { + program: '200', + handler: () => this.handleClick('200') + }, { + program: '400', + handler: () => this.handleClick('400') + }, { + program: '800', + handler: () => this.handleClick('800') + }, { + program: '1500', + handler: () => this.handleClick('1500') + }, { + program: '跳高', + handler: () => this.handleClick('跳高') + }, { + program: '跳远', + handler: () => this.handleClick('跳远') + }, { + program: '三级跳', + handler: () => this.handleClick('三级跳') + }, { + program: '铅球', + handler: () => this.handleClick('铅球') + }], + }; + this.handleClick = this.handleClick.bind(this); + this.openModal = this.openModal.bind(this); + this.handleCloseModal = this.handleCloseModal.bind(this); + } + + openModal(modalTitle, modalContent) { + this.setState({ + modalTitle, + modalContent, + }); + this.setState({'open': true}); + } + + handleCloseModal() { + this.setState({'open': false}); + } + + handleClick(program_name) { + const program_type = '男子'; + fetch('/register', { + method: 'Post', + body: JSON.stringify({ + program_type, + program_name, + }) + }) + .then(response => response.json()) + .then(json => { + if (json.result === 'success') { + this.openModal('成功', '成功报名男子项目' + program_name); + } else { + this.openModal('失败', '报名男子项目' + program_name + '时失败'); + } + }); + } + + render() { + return ( + + +
+ + 请选择项目 + + { + this.state.programs.map(item => + ) + } + +
+ + +
+

{this.state.modalTitle}

+

{this.state.modalContent}

+
+
+
+
+ ); + } +} + +export default withStyles(useStyles)(Male); \ No newline at end of file diff --git a/src/Team.js b/src/Team.js new file mode 100644 index 0000000..eb795fa --- /dev/null +++ b/src/Team.js @@ -0,0 +1,143 @@ +import React from "react"; +import {withStyles} from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import Typography from "@material-ui/core/Typography"; +import Backdrop from "@material-ui/core/Backdrop"; +import Fade from "@material-ui/core/Fade"; +import Modal from "@material-ui/core/Modal"; +import CssBaseline from "@material-ui/core/CssBaseline"; +import Container from "@material-ui/core/Container"; +import {Link} from "react-router-dom"; + +const useStyles = theme => ({ + buttonPaper: { + display: 'flex', + flexDirection: 'column', + textAlign: 'center', + '& > *': { + marginTop: theme.spacing(2), + }, + }, + modalPaper: { + backgroundColor: theme.palette.background.paper, + border: '2px solid #000', + boxShadow: theme.shadows[5], + padding: theme.spacing(2, 4, 3), + }, + modal: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, +}); + +class Team extends React.Component { + constructor(props) { + super(props); + this.state = { + open: false, + modalTitle: '', + modalContent: '', + programs: [{ + program: '男子4*100', + handler: () => this.handleClick('男子4*100') + }, { + program: '女子4*100', + handler: () => this.handleClick('女子4*100') + }, { + program: '男子引体向上', + handler: () => this.handleClick('男子引体向上') + }, { + program: '女子仰卧起坐', + handler: () => this.handleClick('女子仰卧起坐') + }, { + program: '长绳', + handler: () => this.handleClick('长绳') + }], + }; + this.handleClick = this.handleClick.bind(this); + this.openModal = this.openModal.bind(this); + this.handleCloseModal = this.handleCloseModal.bind(this); + } + + openModal(modalTitle, modalContent) { + this.setState({ + modalTitle, + modalContent, + }); + this.setState({'open': true}); + } + + handleCloseModal() { + this.setState({'open': false}); + } + + handleClick(program_name) { + const program_type = '团体'; + fetch('/register', { + method: 'Post', + body: JSON.stringify({ + program_type, + program_name, + }) + }) + .then(response => response.json()) + .then(json => { + if (json.result === 'success') { + this.openModal('成功', '成功报名团体项目' + program_name); + } else { + this.openModal('失败', '报名团体项目' + program_name + '时失败'); + } + }); + } + + render() { + return ( + + +
+ + 请选择项目 + + { + this.state.programs.map(item => + ) + } + +
+ + +
+

{this.state.modalTitle}

+

{this.state.modalContent}

+
+
+
+
+ ); + } +} + +export default withStyles(useStyles)(Team); \ No newline at end of file