diff --git a/src/Active.tsx b/src/Active.tsx new file mode 100644 index 0000000..f65b649 --- /dev/null +++ b/src/Active.tsx @@ -0,0 +1,67 @@ + +import React from "react"; +import {Tabs,Tab,Table,Button} from "react-bootstrap"; +import {ActiveForm} from "./entity"; +/** + * 活动管理 + */ +export class Active extends React.Component{ + + + constructor(props: Readonly) { + super(props); + + this.state={ + activeList:[] + } + } + + //加载活动信息 + loadActive(){ + this.setState({ + activeList:[ + { + title:"fuck", + content:"fuck" + } + ] + }) + } + + componentDidMount() { + this.loadActive() + } + + render() { + + //构建活动信息 + const activeTr=this.state.activeList.map((active:ActiveForm,index:number)=> + + {index+1} + {active.title} + {active.content} + + + ) + + return ( + + + + + + + + + + + + + {activeTr} + +
#活动标题活动内容操作
+
+
+ ); + } +} diff --git a/src/App.tsx b/src/App.tsx index d9a7335..e6d81e8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,19 +1,82 @@ import React from 'react'; import './App.css'; import 'bootstrap/dist/css/bootstrap.min.css'; -import {Login} from "./Login"; +import {Login} from './account/Login'; +import { instanceOf } from 'prop-types'; +import { withCookies, Cookies } from 'react-cookie'; +import {Main} from "./Main"; +import {Register} from "./account/Register"; +import {manager_cookie} from "./account/PropCookie"; -class App extends React.Component{ - render() { +class App extends React.Component { + static propTypes = { + cookies: instanceOf(Cookies).isRequired + }; + + + constructor(props: Readonly) { + super(props); + + this.state={} + } + + componentDidMount() { + const { cookies } = this.props + if((cookies.get(manager_cookie)||"").length>0){ + this.setState({ + page:
+ }) + }else{ + this.toLogin() + } + } - const login= + //注销登录 + logout(){ + const { cookies } = this.props + cookies.remove(manager_cookie) + this.toLogin() + } + + /** + * 跳转注册 + */ + toRegister(){ + this.setState({ + page:this.toLogin()}/> + }) + } + + //登录 + login(manager:string,password:string){ + + const { cookies } = this.props + console.debug("manager_cookie="+manager) + cookies.set(manager_cookie,manager) + + this.setState({ + page:
this.logout()}/> + }) + } + + /** + * 跳转登录 + */ + toLogin(){ + this.setState({ + page:this.toRegister()} login={(manager:string,password:string)=>this.login(manager,password)}/> + }) + } + + + render() { return (
- {login} + {this.state.page}
); } } -export default App; +export default withCookies(App); diff --git a/src/InputGroup.tsx b/src/InputGroup.tsx deleted file mode 100644 index a18ff8c..0000000 --- a/src/InputGroup.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from "react"; -import {InputGroup,FormControl} from 'react-bootstrap' -import {LoginFormDesc} from "./LoginForm"; -export class Input extends React.Component{ - - render() { - return ( - - - {this.props.desc} - - this.props.onChange(e.target.value)}/> - - ); - } -} diff --git a/src/Login.tsx b/src/Login.tsx deleted file mode 100644 index 9cad5ce..0000000 --- a/src/Login.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from "react"; -import {Button} from 'react-bootstrap' -import {LoginForm} from "./LoginForm"; -import "./login_form.css" -import {Input} from "./InputGroup"; -export class Login extends React.Component{ - - constructor(props: Readonly) { - super(props) - this.state={ - username:props.username, - password:props.password - } - } - - login(){ - alert("您输入的用户名是"+this.state.username+",您输入的密码是:"+this.state.password); - } - - render() { - return ( -
-
- {this.setState({username:value})}}/> - - {this.setState({password:value})}}/> - - -
-
- ); - } -} diff --git a/src/LoginForm.ts b/src/LoginForm.ts deleted file mode 100644 index 3ec0339..0000000 --- a/src/LoginForm.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface LoginForm { - username:string; - password:string; -} - -export interface LoginFormDesc { - name:string - desc:string - value:string - onChange:Function -} - diff --git a/src/Main.tsx b/src/Main.tsx index 25d46b7..c282df0 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -1,10 +1,78 @@ import React from "react"; +import {Navbar,Nav,Button} from "react-bootstrap"; +import {Manager} from "./Manager"; +import {User} from "./User"; +import {Active} from "./Active"; +/** + * 菜单标记 + */ +enum Menu { + manager, + user, + active +} + +/** + * 主菜单 + */ export class Main extends React.Component{ + constructor(props: Readonly) { + super(props); + //默认菜单 + this.state={ + menu:Menu.manager, + subMenu: + } + } + + //获取菜单名颜色 + getMenuColor(menu:Menu){ + return this.state.menu===menu?"black":"blue" + } + + //切换菜单 + changeMenu(menu:Menu){ + this.setState({ + menu:menu + }) + + switch (menu) { + case Menu.manager: + this.setState({ + subMenu: + });break; + case Menu.user: + this.setState({ + subMenu: + });break; + case Menu.active: + this.setState({ + subMenu: + });break; + } + } + render() { + return ( -

fff

+
+ + + + 欢迎管理员{this.props.manager}登录 + + + + + {this.state.subMenu} +
+ ) } } diff --git a/src/Manager.tsx b/src/Manager.tsx new file mode 100644 index 0000000..e130013 --- /dev/null +++ b/src/Manager.tsx @@ -0,0 +1,166 @@ +import React from "react"; +import {Tabs,Tab,Button,Table,Modal} from "react-bootstrap"; +import {ManagerForm} from "./entity"; +import {Input} from "./bootstrap/InputGroup"; +/** + * 管理员管理 + */ +export class Manager extends React.Component{ + + constructor(props: Readonly) { + super(props); + + this.state={ + managerList:[], + //修改密码模态框状态位 + showModifyPwd:false, + //修改密码表单 + modify:{ + password:"", + confirmPwd:"" + }, + //添加管理员模态框状态位 + showAddManager:false, + //添加管理员表单 + addManager:{ + manager:"", + password:"", + confirmPwd:"" + } + } + + } + + /** + * 加载管理员数据 + */ + loadManager(){ + this.setState({ + managerList:[ + { + manager:"admin123" + } + ] + }) + } + + /** + * 检查密码 + */ + checkPwd(modify:any){ + if(modify.password.length>0&&modify.confirmPwd.length>0&&modify.password===modify.confirmPwd){ + return { + check:true + } + }else if(modify.confirmPwd.length>0&&modify.confirmPwd.length>0){ + return { + check:false, + invalid:'两次密码输入不一致' + } + }else if(modify.password.length>0&&modify.confirmPwd.length===0){ + return { + check:false, + invalid: '确认密码为空' + } + }else{ + return { + check:undefined + } + } + } + + componentDidMount() { + this.loadManager() + } + + /** + * 获取模态框表单 + */ + getForm(){ + let key: string + let form:any + let manager; + if(this.state.showAddManager){ + key='addManager' + form=this.state.addManager + manager={this.setState({[key]:{ + manager:value, + password:form.password, + confirmPwd:form.confirmPwd + }})}}/> + }else{ + key='modify' + form=this.state.modify + } + return + {manager} + {this.setState({[key]:{ + manager:form.manager, + password:value, + confirmPwd:form.confirmPwd + }})}}/> + {this.setState({[key]:{ + manager:form.manager, + password:form.password, + confirmPwd:value + }})}} + valid={this.checkPwd(form)} + /> + + } + + render() { + + + //构造表格行数据 + const managerTr=this.state.managerList.map((manager:ManagerForm,index:number)=> + + {index+1} + {manager.manager} + + + + + + ) + + const modalTitle=this.state.showModifyPwd?'修改密码':'添加管理员' + + return ( + + + + + + + + + + + + + {managerTr} + +
#管理员名操作
+ + + + + + {modalTitle} + + + {this.getForm()} + + + + + + +
+
+ ); + } +} diff --git a/src/User.tsx b/src/User.tsx new file mode 100644 index 0000000..0dc58da --- /dev/null +++ b/src/User.tsx @@ -0,0 +1,139 @@ +import React from "react"; +import {Tabs,Tab,Table,Button,Modal} from "react-bootstrap"; +import {UserForm} from "./entity"; +import {Input} from "./bootstrap/InputGroup"; +/** + * 用户管理 + */ +export class User extends React.Component{ + + + constructor(props: Readonly) { + super(props); + + this.state={ + userList:[], + showUser:false + } + } + + /** + * 加载用户信息 + */ + loadUser(){ + this.setState({userList:[ + { + username:"ffff", + name:"ffff", + sex:"男", + age:12, + headImg:"https://www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg", + phone:1234567890, + mail:"abc@qq.com", + address:"广州", + timeMoney:22, + desc:"自我介绍" + }, + { + username:"ffff", + name:"草", + sex:"男", + age:12, + headImg:"https://www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg", + phone:1234567890, + mail:"abc@qq.com", + address:"广州", + timeMoney:22, + desc:"自我介绍" + } + ]}) + } + + //修改个人信息 + modifyUser(){ + alert("您修改的用户是"+this.state.user.name) + this.setState({showUser:false}) + } + + componentDidMount() { + this.loadUser() + } + + render() { + + //构造表格行数据 + const userTr=this.state.userList.map((user:UserForm,index:number)=> + + {index+1} + {user.username} + {user.name} + {user.sex} + {user.age} + 头像this.setState({headImg:user.headImg})}/> + {user.phone} + {user.mail} + {user.address} + {user.timeMoney} + {user.desc} + + + + + + + ) + + return ( + + + + + + + + + + + + + + + + + + + + + {userTr} + +
#用户账号姓名性别年龄头像电话邮箱地点时间币个人描述操作
+ + 0} centered onClick={()=>this.setState({headImg:""})} onHide={()=>{}}> + + + 头像 + + + + {}}> + this.setState({showUser:false})}> + + 修改个人信息 + + + + this.setState({ + user:{ + name:value + } + })}/> + + + + + +
+
+ ); + } +} diff --git a/src/login_form.css b/src/account/Login.css similarity index 100% rename from src/login_form.css rename to src/account/Login.css diff --git a/src/account/Login.tsx b/src/account/Login.tsx new file mode 100644 index 0000000..e2cfaba --- /dev/null +++ b/src/account/Login.tsx @@ -0,0 +1,38 @@ +import React from "react"; +import {Button} from 'react-bootstrap' +import {LoginForm} from "./LoginForm"; +import {Input} from "../bootstrap/InputGroup"; + +/** + * 登陆表单组件 + */ +export class Login extends React.Component{ + + + constructor(props: Readonly) { + super(props) + this.state={ + manager:"", + password:"", + toRegister:props.toRegister, + cookies:props.cookies, + login:props.login + } + } + + render() { + return ( +
+
+ {this.setState({manager:value})}}/> + + {this.setState({password:value})}}/> + + + + +
+
+ ); + } +} diff --git a/src/account/LoginForm.ts b/src/account/LoginForm.ts new file mode 100644 index 0000000..3c9eac0 --- /dev/null +++ b/src/account/LoginForm.ts @@ -0,0 +1,15 @@ +/** + * 登陆表单 + */ +import {PropCookie} from "./PropCookie"; + +export interface LoginForm extends PropCookie{ + //管理员名 + manager?:string; + //密码 + password?:string; + //跳转注册 + toRegister:Function; + //登录 + login:Function; +} diff --git a/src/account/PropCookie.ts b/src/account/PropCookie.ts new file mode 100644 index 0000000..7323f25 --- /dev/null +++ b/src/account/PropCookie.ts @@ -0,0 +1,10 @@ +import {Cookies } from 'react-cookie'; + +/** + * cookie信息,组件间传递 + */ +export interface PropCookie { + cookies:Cookies; +} + +export const manager_cookie="manager_cookie" diff --git a/src/account/Register.tsx b/src/account/Register.tsx new file mode 100644 index 0000000..d322031 --- /dev/null +++ b/src/account/Register.tsx @@ -0,0 +1,39 @@ +import React from "react"; +import {RegisterForm} from "./RegisterForm"; +import {Input} from "../bootstrap/InputGroup"; +import {Button} from 'react-bootstrap' +/** + * 注册 + */ +export class Register extends React.Component{ + + constructor(props: Readonly) { + super(props) + this.state={ + manager:"", + password:"", + toLogin:props.toLogin + } + } + + //注册 + register(){ + alert("您输入的用户名是"+this.state.manager+",您输入的密码是:"+this.state.password); + } + + render() { + return ( +
+
+ {this.setState({manager:value})}}/> + + {this.setState({password:value})}}/> + + + + +
+
+ ); + } +} diff --git a/src/account/RegisterForm.tsx b/src/account/RegisterForm.tsx new file mode 100644 index 0000000..60fb798 --- /dev/null +++ b/src/account/RegisterForm.tsx @@ -0,0 +1,11 @@ +/** + * 注册表单 + */ +export interface RegisterForm { + //管理员名 + manager?:string; + //密码 + password?:string; + //跳转登录 + toLogin:Function; +} diff --git a/src/bootstrap/InputGroup.tsx b/src/bootstrap/InputGroup.tsx new file mode 100644 index 0000000..e732857 --- /dev/null +++ b/src/bootstrap/InputGroup.tsx @@ -0,0 +1,45 @@ +import React from "react"; +import {InputGroup,FormControl} from 'react-bootstrap' +import {InputFormDesc} from "./LoginFormDesc"; + + +const defaultValid={ + check:false, + valid:'验证成功', + invalid:'验证失败' +} +/** + * bootstrap InputGroup组件封装 + */ +export class Input extends React.Component{ + + merge(){ + return {...defaultValid,...this.props.valid} + } + + valid(){ + if(this.props.valid===undefined||this.props.valid.check===undefined){ + return "" + }else{ + return this.props.valid.check?'is-valid':'is-invalid' + } + } + + render() { + return ( + + + {this.props.desc} + + this.props.onChange(e.target.value)}/> +
+ {this.merge().valid} +
+
+ {this.merge().invalid} +
+
+ ); + } +} diff --git a/src/bootstrap/LoginFormDesc.ts b/src/bootstrap/LoginFormDesc.ts new file mode 100644 index 0000000..811a15f --- /dev/null +++ b/src/bootstrap/LoginFormDesc.ts @@ -0,0 +1,23 @@ +/** + * 文本输入框组件封装 + */ +export interface InputFormDesc { + //表单名 + name: string + //描述信息 + desc: string + //表单值 + value?: string + //数据类型 + type?: + |"text" + |"password" + //值改变事件 + onChange: Function + //验证信息 + valid?:{ + check?:Boolean; + valid?:String; + invalid?:String; + } +} diff --git a/src/entity.ts b/src/entity.ts new file mode 100644 index 0000000..86d773b --- /dev/null +++ b/src/entity.ts @@ -0,0 +1,25 @@ +//管理员 +export interface ManagerForm { + manager:string; +} + +//用户 +export interface UserForm { + username:string; + name:string; + sex:string; + age:number; + headImg:string; + phone:number; + mail:string; + address:string; + timeMoney:string; + desc:string; +} + +//活动 +export interface ActiveForm { + title:string; + content:string; +} + diff --git a/src/index.css b/src/index.css index 352ce44..7e7bb08 100644 --- a/src/index.css +++ b/src/index.css @@ -12,4 +12,7 @@ code { monospace; } - +.head-img{ + width: 100px; + height: 100px; +} diff --git a/src/index.tsx b/src/index.tsx index f5185c1..a4e0dd0 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -3,10 +3,13 @@ import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; +import { CookiesProvider } from 'react-cookie'; ReactDOM.render( - + + + , document.getElementById('root') );