From 233cb66ef2e4dabcb3042f54da6f211f2ec1f6c5 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Mon, 1 Jun 2020 05:42:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E6=80=A7=E5=88=AB=EF=BC=8C=E5=B9=B4?= =?UTF-8?q?=E9=BE=84=E7=AD=89=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=A1=B9=202.=E6=B4=BB=E5=8A=A8=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8F=AF=E4=BF=AE=E6=94=B9=E6=B4=BB=E5=8A=A8=E6=A0=87=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/Active.tsx | 107 ++++++++++++++++++++++++++++++++--- src/Main.tsx | 3 +- src/User.tsx | 135 ++++++++++++++++++++++++++++++++++++++++---- src/api.ts | 6 +- src/entity.ts | 15 ++++- src/ui/Address.tsx | 56 ++++++++++++++++++ src/ui/MyDialog.tsx | 8 ++- yarn.lock | 5 ++ 9 files changed, 313 insertions(+), 25 deletions(-) create mode 100644 src/ui/Address.tsx diff --git a/package.json b/package.json index 1990f14..40bef2b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@types/react-dom": "^16.9.0", "bootstrap": "^4.5.0", "http-proxy-middleware": "^1.0.4", + "moment": "^2.26.0", "react": "^16.13.1", "react-bootstrap": "^1.0.1", "react-cookie": "^4.0.3", @@ -22,7 +23,7 @@ "typescript": "~3.7.2" }, "scripts": { - "start": "react-scripts start", + "start": "set PORT=3000&&react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/src/Active.tsx b/src/Active.tsx index 28c0324..827ab77 100644 --- a/src/Active.tsx +++ b/src/Active.tsx @@ -1,10 +1,55 @@ import React from "react"; -import {Button, Tab, Table, Tabs} from "react-bootstrap"; -import {ActiveForm, ManagerActivity} from "./entity"; -import {Method, request} from "./interface"; +import {Button, Form, ListGroup, Tab, Table, Tabs} from "react-bootstrap"; +import {ManagerActivity} from "./entity"; +import {JSONResponse, Method, request} from "./interface"; import {API} from "./api"; -import {FindActivityRes, FindActivityTransform, PageDataMessage} from "./result"; +import {EmptyBodyTransform, FindActivityRes, FindActivityTransform, PageDataMessage, SimpleMessage} from "./result"; import {MyDialog} from "./ui/MyDialog"; +import moment from "moment"; +import {Input} from "./ui/InputGroup"; + +const contentMaxLength=50 + +class EditActive extends React.Component< + { + onClick:Function; + activity:ManagerActivity; + }, + { + activity:ManagerActivity; + }>{ + + + constructor(props: Readonly<{ onClick: Function; activity: ManagerActivity }>) { + super(props); + + this.state={ + activity:this.props.activity + } + } + + render() { + return ( +
+ + this.setState({ + activity:{...this.state.activity,...{title:value}} + })} valid={{check:this.isNotEmpty(this.state.activity.title)}}/> + + 0,valid:this.state.activity.content.length===0? + "验证失败":"您还可输入"+(contentMaxLength-this.state.activity.content.length+"个字符")}} + maxLength={contentMaxLength} onChange={(value:string)=>this.setState({activity:{...this.state.activity,...{content:value}}})}/> + + +
+ ); + } + + private isNotEmpty(name: any) { + return String(name).length>0; + } +} /** * 活动管理 @@ -12,6 +57,7 @@ import {MyDialog} from "./ui/MyDialog"; export class Active extends React.Component; tipContent:JSX.Element|null + dialog:JSX.Element|null }>{ @@ -19,7 +65,8 @@ export class Active extends React.Component# 活动标题 活动内容 + 开始时间 + 结束时间 + 求助用户id + 帮助用户id 操作 - {this.state.activeList?this.state.activeList.length>0?this.state.activeList.map((active:ActiveForm,index:number)=> + {this.state.activeList?this.state.activeList.length>0?this.state.activeList.map((active:ManagerActivity,index:number)=> {index+1} {active.title} {active.content} + {moment(active.activityStartTime).format("YYYY-MM-DD HH:mm:ss")} + {moment(active.activityEndTime).format("YYYY-MM-DD HH:mm:ss")} + {active.seekHelpUser} - {/**/} + {active.helpUser != null ? + + {active.helpUser.map((userId,index) => + {userId})} + :'无' + } + ):

没有活动信息

:null } + {this.state.dialog} + this.setState({ tipContent:null @@ -87,4 +152,32 @@ export class Active extends React.Component ); } + + /** + * 修改活动信息 + * @param activity + */ + private modifyActivity(activity: ManagerActivity) { + let that=this + request(API.account.updateActivity+activity.activityId,Method.POST, { + title:activity.title, + content:activity.content + }, + new EmptyBodyTransform(),function (res:JSONResponse) { + switch (res.customResult) { + case SimpleMessage.ok: + that.setState({ + tipContent:

修改成功

, + dialog:null + }) + that.loadActive(1) + break + case SimpleMessage.fail: + that.setState({ + tipContent:

修改失败,请联系管理员

+ }) + break + } + }) + } } diff --git a/src/Main.tsx b/src/Main.tsx index 3108fe8..50f2ee9 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -5,6 +5,7 @@ import {User} from "./User"; import {Active} from "./Active"; import {Cookies} from "react-cookie"; import {manager_cookie} from "./account/PropCookie"; +import {fontEnd} from "./api"; /** * 菜单标记 @@ -78,7 +79,7 @@ export class Main extends React.Component< 欢迎管理员{this.props.cookies.get(manager_cookie)}登录 - + {this.state.subMenu} diff --git a/src/User.tsx b/src/User.tsx index 4181d88..06220da 100644 --- a/src/User.tsx +++ b/src/User.tsx @@ -6,39 +6,136 @@ import {JSONResponse, Method, request} from "./interface"; import {API, prefix} from "./api"; import {EmptyBodyTransform, FindUserRes, FindUserTransform, PageDataMessage, SimpleMessage} from "./result"; import {MyDialog} from "./ui/MyDialog"; +import {Address} from "./ui/Address"; class EditUser extends React.Component<{ user:UserEntity; modifyUser:Function; }, { user:UserEntity; - tipContent:JSX.Element|null; }>{ + private ages:Array constructor(props: Readonly<{ user: UserEntity ,modifyUser:Function;}>) { super(props); + this.ages=this.createAge() + this.state={ - user:this.props.user, - tipContent:null + user:this.props.user } } render() { return (
- this.setState({ + + this.setState({ user:{...this.state.user,...{name:value}} - })}/> + })} valid={{check:this.isNotEmpty(this.state.user.name)}}/> + + + this.setState({ + user:{...this.state.user,...{age:+value}} + }) + } as={"select"} options={this.ages.map(value=>)}/> + { + this.setState({ + user:{...this.state.user,...{sex:value}} + }) + }} + options={[ + , + , + ]}/> + this.setState({ + user:{...this.state.user,...{address:value}} + })} valid={{check:this.isNotEmpty(this.state.user.address)}}/> - +
+
+ this.setState({ + user:{...this.state.user,...{serviceAddress:value}} + }) + }/> +
+ + + this.setState({ + user:{...this.state.user,...{userType:value}} + }) + } + options={[, + , + ]}/> + + + this.setState({ + user:{...this.state.user,...{mobile:value}} + }) + } valid={{check:this.checkMobile()}}/> + + + this.setState({ + user:{...this.state.user,...{email:value}} + }) + } valid={{check:this.checkEmail()}}/> + + + this.setState({ + user:{...this.state.user,...{info:value}} + }) + } + valid={{check:this.isNotEmpty(this.state.user.info)}}/> + + + +
); } + + private createAge(){ + let age=[] + for(let i=18;i<100;i++){ + age.push(i) + } + return age + } + + /** + * 检查手机号 + */ + checkMobile(){ + return /1[3456789]\d{9}/g.test(this.state.user.mobile.toString()) + } + + /** + * 检查邮箱 + */ + private checkEmail() { + return /[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}/g.test(this.state.user.email) + } + + //检查是否为空 + isNotEmpty(...value:(string | number)[]){ + for(let index in value){ + if(value[index].toString().length===0){ + return false + } + } + return true + } + + private check() { + return this.isNotEmpty(this.state.user.userId,this.state.user.name,this.state.user.sex, + this.state.user.serviceAddress,this.state.user.userType,this.state.user.info) + &&this.checkMobile()&&this.checkEmail() + } } /** @@ -107,14 +204,16 @@ export class User extends React.Component< # 用户账号 姓名 - 性别 年龄 + 性别 + 住址 头像 + 服务地点 + 用户身份 电话 邮箱 - 地点 时间币 - 个人描述 + 简介 操作 @@ -124,8 +223,9 @@ export class User extends React.Component< {index+1} {user.userId} {user.name} - {user.sex} {user.age} + {user.sex==='man'?'男':'女'} + {user.address} {this.setState({ dialog:} @@ -135,9 +235,11 @@ export class User extends React.Component< })}/> })}/>} + {user.serviceAddress} + {user.userType===UserType.seekHelp?'服务发起者':'服务接受者'} {user.mobile} {user.email} - {user.address} + {user.timeScore} {user.info} @@ -173,7 +275,16 @@ export class User extends React.Component< let that=this request(API.account.updateUser,Method.POST, { userId:user.userId, - name:user.name + name:user.name, + age:String(user.age), + sex:String(user.sex), + address:user.address, + serviceAddress:user.serviceAddress, + userType:user.userType, + mobile:user.mobile, + email:user.email, + info:user.info + },new EmptyBodyTransform(),function (res:JSONResponse) { switch (res.customResult) { case SimpleMessage.ok: diff --git a/src/api.ts b/src/api.ts index bbf0f46..0716d33 100644 --- a/src/api.ts +++ b/src/api.ts @@ -6,6 +6,8 @@ export const prefix={ user:'/api/user', image: "/image/" } +//用户前台地址 +export const fontEnd="http://localhost:3001" //接口地址 export const API={ @@ -25,7 +27,9 @@ export const API={ // 更新用户信息 updateUser:prefix.manager+'/userUpdate', //查询活动信息 - findActivity:prefix.manager+'/find/activity' + findActivity:prefix.manager+'/find/activity', + //修改活动信息 + updateActivity:prefix.manager+'/update/' }, user:{ diff --git a/src/entity.ts b/src/entity.ts index acd9f5c..4e040d2 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -172,7 +172,7 @@ export enum UserType { seekHelp="seekHelp", help="help" } - +//活动列表 export interface ManagerActivity { activityId:number; content:string; @@ -184,3 +184,16 @@ export interface ManagerActivity { helpUser:Array; } +/** + * 地点信息 + */ +export interface AddressProps { + address:string; +} + +export interface OnChangeAddress { + onChange:Function; + col?:number; + value?:string; +} + diff --git a/src/ui/Address.tsx b/src/ui/Address.tsx new file mode 100644 index 0000000..d7c8bd9 --- /dev/null +++ b/src/ui/Address.tsx @@ -0,0 +1,56 @@ +import {Form, InputGroup} from "react-bootstrap"; +import {AddressProps, OnChangeAddress} from "../entity"; +import React from "react"; + +/** + * 加载服务地点信息 + */ +export class Address extends React.Component }>{ + + + constructor(props: Readonly) { + super(props); + + this.state={ + addressList:[], + + } + } + + componentDidMount() { + this.loadAddress() + } + + /** + * 加载服务地点 + */ + loadAddress(){ + this.setState({ + addressList:[{ + address:"北京", + }, + { + address:"广州", + }, + { + address:"上海", + }] + }) + } + + render() { + return ( + + + 服务地点 + + this.props.onChange(e.target.value)}> + + {this.state.addressList.map((address:AddressProps, index:number)=> + + )} + + + ) + } +} diff --git a/src/ui/MyDialog.tsx b/src/ui/MyDialog.tsx index 121b946..5793437 100644 --- a/src/ui/MyDialog.tsx +++ b/src/ui/MyDialog.tsx @@ -1,10 +1,14 @@ import React from "react"; import Dialog from "@material-ui/core/Dialog"; import Draggable from "react-draggable"; -import {Paper} from "@material-ui/core"; +import {Paper, styled, withWidth} from "@material-ui/core"; import {MyDialogProps} from "../entity"; import {CloseDialog} from "./CloseDialog"; + +const EditDialogPaper=styled(Paper)({ + maxWidth:1000 +}) /** * 我的弹窗 */ @@ -18,7 +22,7 @@ export class MyDialog extends React.Component - + } aria-labelledby={this.props.titleId} classes={{paper:"w-100"}} diff --git a/yarn.lock b/yarn.lock index 7f9ae12..668818f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7101,6 +7101,11 @@ mkdirp@^0.5.1, mkdirp@^0.5.3, mkdirp@~0.5.1: dependencies: minimist "^1.2.5" +moment@^2.26.0: + version "2.26.0" + resolved "https://registry.npm.taobao.org/moment/download/moment-2.26.0.tgz#5e1f82c6bafca6e83e808b30c8705eed0dcbd39a" + integrity sha1-Xh+Cxrr8pug+gIswyHBe7Q3L05o= + move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.npm.taobao.org/move-concurrently/download/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"