From 372531e0c3b113d6ec0cab3bb98c04d40127355a Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Thu, 28 May 2020 05:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=201.=E8=8E=B7=E5=8F=96=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=202.=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 1 + src/Main.tsx | 4 +- src/account/Register.tsx | 35 ++++++-- src/entity.ts | 29 ++++++- src/interface.ts | 6 +- src/my/MyFriend.tsx | 13 ++- src/my/MyInfo.tsx | 176 +++++++++++++++++++++++++++------------ src/my/MyLeaveWord.tsx | 2 +- src/my/MyMessage.tsx | 4 +- src/my/SeekHelp.tsx | 2 +- src/result.ts | 29 ++++++- src/ui/Address.tsx | 7 +- src/ui/TestData.ts | 4 +- 13 files changed, 230 insertions(+), 82 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bffcfd5..cd2c05b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -44,6 +44,7 @@ class App extends React.Component< logout(){ this.props.cookies.remove(user_cookie) this.props.cookies.remove(user_type_cookie) + this.props.cookies.remove(time_score) this.toLogin() } diff --git a/src/Main.tsx b/src/Main.tsx index 272b591..d66b5eb 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -7,7 +7,7 @@ import {MyFriend} from "./my/MyFriend"; import {MyDialog} from "./ui/MyDialog"; import {MyLeaveWord} from "./my/MyLeaveWord"; import {MyMessage} from "./my/MyMessage"; -import {User, UserEdit, UserType} from "./entity"; +import {User, UserType} from "./entity"; import {Cookies} from "react-cookie"; import {time_score, user_cookie, user_type_cookie, welcome_cookie} from "./account/PropCookie"; @@ -147,7 +147,7 @@ export class Main extends React.Component< break; case DialogType.message: this.setState({ - my:{menuName:dialogType,content:{ + my:{menuName:dialogType,content:{ this.setState({userType:user.userType}) this.props.cookies.set(user_type_cookie,user.userType) }} diff --git a/src/account/Register.tsx b/src/account/Register.tsx index 9b10368..5530fbe 100644 --- a/src/account/Register.tsx +++ b/src/account/Register.tsx @@ -21,17 +21,22 @@ const maxImageSize={ */ export class Register extends React.Component{ + private ages:Array + constructor(props: Readonly) { super(props) + + this.ages=this.createAge() + this.state={ result: null, sex: "", address:"", serviceAddress: "", - age: 0, + age: this.ages[0], email: "", info: "", - mobile: 0, + mobile: "", name: "", userId: "", password:"", @@ -55,8 +60,8 @@ export class Register extends React.Component{ userType:this.state.userType, mobile:String(this.state.mobile), email:this.state.email, - info:this.state.info - + info:this.state.info, + age:this.state.age+"" },new RegisterTransform(),function(res:JSONResponse){ let message switch (res.customResult) { @@ -114,7 +119,13 @@ export class Register extends React.Component{ return /[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}/g.test(this.state.email) } - + createAge(){ + let age=[] + for(let i=18;i<100;i++){ + age.push(i) + } + return age + } render() { return ( @@ -134,7 +145,15 @@ export class Register extends React.Component{ this.setState({name:value})} valid={{check:this.isNotEmpty(this.state.name)}}/> - this.setState({sex:value})} + { + this.setState({age:+value}) + console.debug(this.state.age+"==="+value) + }} + as={"select"} options={this.ages.map(value=>)}/> + + { + this.setState({sex:value}) + }} options={[,,]}/> @@ -144,12 +163,12 @@ export class Register extends React.Component{ this.setState({address:value})}/> -
this.setState({serviceAddress:value})}/> +
this.setState({serviceAddress:value})}/> this.setState({userType:value})} options={[,,]}/> - this.setState({mobile:+value})} valid={{check:this.checkMobile()}}/> + this.setState({mobile:value})} valid={{check:this.checkMobile()}}/> this.setState({email:value})} valid={{check:this.checkEmail()}}/> diff --git a/src/entity.ts b/src/entity.ts index 55e216f..eb9c277 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -13,6 +13,8 @@ export interface AddressProps { export interface OnChangeAddress { onChange:Function; + col?:number; + value?:string; } /** @@ -184,7 +186,7 @@ export interface User{ //用户年龄 age:number; //用户电话 - mobile:number; + mobile:string; //用户邮箱 email:string; //住址 @@ -206,7 +208,29 @@ export interface User{ /** * 个人信息编辑修改密码 */ -export interface UserEdit extends User{ +export interface UserEdit{ + //用户id + userId?:string; + //用户姓名 + name?:string; + //用户年龄 + age?:number; + //用户性别 + sex?:string; + //用户电话 + mobile?:number; + //用户邮箱 + email?:string; + //住址 + address?:string; + //服务地点 + serviceAddress?:string; + //个人简介 + info?:string; + //头像 + headImg?:string; + //身份 + userType?:string; //编辑模式 contentEditable:boolean; //修改时间 @@ -217,6 +241,7 @@ export interface UserEdit extends User{ newPassword:string; //确认新密码 confirmNewPwd:string; + result:JSX.Element|null } diff --git a/src/interface.ts b/src/interface.ts index 2755bcc..4c8d531 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -15,7 +15,11 @@ export const API={ //登录 login:prefix.user+"/login", //查找用户 - find:prefix.user+"/find" + find:prefix.user+"/find", + //更新 + update:prefix.user+"/update", + //更新密码 + updatePwd:prefix.user+"/updatePwd" }, main:{ activity: { diff --git a/src/my/MyFriend.tsx b/src/my/MyFriend.tsx index e42d86e..04ea33e 100644 --- a/src/my/MyFriend.tsx +++ b/src/my/MyFriend.tsx @@ -26,10 +26,8 @@ export class MyFriend extends React.Component<{ user:string }, friendIndex:number|null; //发送内容 sendContent:String; - //查看用户信息 - openUserInfo:boolean; //查看用户ID - userId?:string; + userId:string|null; } >{ @@ -50,8 +48,7 @@ export class MyFriend extends React.Component<{ user:string }, friendIndex:null, //发送内容 sendContent:'', - //查看用户信息 - openUserInfo:false + userId:null } } @@ -119,7 +116,7 @@ export class MyFriend extends React.Component<{ user:string }, {user.name} - 查看用户信息this.setState({openUserInfo:true,userId:user.userId})}/> + 查看用户信息this.setState({userId:user.userId})}/> )} @@ -178,8 +175,8 @@ export class MyFriend extends React.Component<{ user:string }, } - open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/> + content={} + open={this.state.userId!==null} onClose={()=>this.setState({userId:null})}/> ); } diff --git a/src/my/MyInfo.tsx b/src/my/MyInfo.tsx index 6d92916..205ed9f 100644 --- a/src/my/MyInfo.tsx +++ b/src/my/MyInfo.tsx @@ -2,69 +2,84 @@ import React from "react"; import {Button, Col, Container, Form, FormControl, Image, Row} from "react-bootstrap"; import {UserEdit, UserType} from "../entity"; import {Input} from "../ui/InputGroup"; - +import {API, JSONResponse, Method, prefix, request} from "../interface"; +import { + EmptyBodyTransform, + FindUserInfo, + FindUserInfoTransform, + ModifyPwdMessage, + ModifyPwdTransform, + SimpleMessage +} from "../result"; +import {MyDialog} from "../ui/MyDialog"; +import {Address} from "../ui/Address"; /** * 个人信息 */ export class MyInfo extends React.Component< { + userId:string; isOwn:boolean; - ownUserId:string; - userId?:string; isMyFriend:boolean; isAdd:boolean; - //更新用户信息回调 onUserUpdate?:Function; }, UserEdit>{ + private ages:Array constructor(props: Readonly) { super(props); + this.ages=this.createAge() + this.state={ - userType: "", - //用户ID - userId:"", - //用户姓名 - name:"", - //用户年龄 - age:0, - //用户电话 - mobile:0, - //用户邮箱 - email:"", - address:"", - //地点 - serviceAddress:"", - //个人简介 - info:"", - //性别 - sex:"男", - //头像 - headImg:"", contentEditable:false, modifyPassword:false, oldPassword:"", newPassword:"", - confirmNewPwd:"" + confirmNewPwd:"", + result:null } } + + createAge(){ + let age=[] + for(let i=18;i<100;i++){ + age.push(i) + } + return age + } + /** * 加载用户信息 */ loadInfo(){ - this.setState({ - headImg:"logo512.png", - userId:"admin", - name:"张三", - age:Math.ceil(Math.random()*100)+1, - mobile:1234567879, - email:"admin@qq.com", - serviceAddress:"上海高新区", - info:"个人简介", - userType:UserType.help.toString() + + let that=this + + request(API.account.find+"/"+this.props.userId,Method.GET, {},new FindUserInfoTransform(),function(res:FindUserInfo){ + switch (res.customResult) { + case SimpleMessage.fail: + that.setState({ + result:

获取用户信息失败,请联系管理员

+ });break + case SimpleMessage.ok: + that.setState({ + headImg:res.info?.headImg, + userId:res.info?.userId, + name:res.info?.name, + age:res.info?.age, + mobile:res.info?.mobile, + email:res.info?.email, + serviceAddress:res.info?.serviceAddress, + info:res.info?.info, + userType:res.info?.userType, + sex:res.info?.sex + });break + + } }) } @@ -97,6 +112,28 @@ export class MyInfo extends React.Component< this.setState({ modifyPassword:false }) + + let that=this + + request(API.account.updatePwd,Method.POST, { + newPassword:this.state.newPassword, + oldPassword:this.state.oldPassword + },new ModifyPwdTransform(),function (res:JSONResponse) { + switch (res.customResult) { + case ModifyPwdMessage.fail: + that.setState({ + result:

修改密码失败,请联系管理员

+ });break + case ModifyPwdMessage.pwd_fail: + that.setState({ + result:

修改密码失败,原密码错误

+ });break + case ModifyPwdMessage.ok: + that.setState({ + result:

修改密码成功

+ });break + } + }) } /** @@ -107,10 +144,34 @@ export class MyInfo extends React.Component< contentEditable:false }) - if(this.props.onUserUpdate) { - this.props.onUserUpdate({userType: this.state.userType}) - } - console.debug(this.state) + let that=this + + request(API.account.update,Method.POST, { + headImg:this.state.headImg||"", + name:this.state.name||"", + age:this.state.age+""||"", + mobile:this.state.mobile+""||"", + email:this.state.email||"", + serviceAddress:this.state.serviceAddress||"", + info:this.state.info||"", + userType:this.state.userType||"", + sex:this.state.sex||"" + },new EmptyBodyTransform(),function (res:JSONResponse) { + switch (res.customResult) { + case SimpleMessage.fail: + that.setState({ + result:

更新信息失败,请联系管理员

+ });break + case SimpleMessage.ok: + that.loadInfo(); + //TODO 更新用户身份 + that.setState({ + result:

更新信息成功

+ }) + break + } + }) + } @@ -132,22 +193,26 @@ export class MyInfo extends React.Component< render() { return ( - + - - + + {/*TODO 表单校验*/} - {this.state.userId} + + {this.state.userId} + {this.state.contentEditable? this.setState({name:e.target.value})}/> :this.state.name} {this.state.contentEditable? - this.setState({age:+e.target.value})}/> + this.setState({age:+e.target.value})}> + {this.ages.map(value=>)} + :this.state.age} @@ -163,18 +228,24 @@ export class MyInfo extends React.Component< {this.state.contentEditable? - this.setState({userType:e.target.value})}> - - - : - this.state.userType===UserType.help?"等待接受帮助":"等待前往帮助"} + this.setState({sex:event.target.value})}> + + + :this.state.sex==='man'?"男":"女"} {this.state.contentEditable? - this.setState({serviceAddress:e.target.value})}/> - :this.state.serviceAddress} +
this.setState({serviceAddress:value})}/>:this.state.serviceAddress} + + + {this.state.contentEditable? + this.setState({userType:e.target.value})}> + + + : + this.state.userType===UserType.help?"等待前往帮助":"等待接受帮助"} @@ -223,6 +294,9 @@ export class MyInfo extends React.Component< } + this.setState({ + result:null + })}/> ) } diff --git a/src/my/MyLeaveWord.tsx b/src/my/MyLeaveWord.tsx index 0fa0de3..953252c 100644 --- a/src/my/MyLeaveWord.tsx +++ b/src/my/MyLeaveWord.tsx @@ -162,7 +162,7 @@ export class MyLeaveWord extends React.Component<{ user:string },
{this.state.data.map((data,index) =>this.getData(data,index))} } + content={} open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/> {this.state.activity?} diff --git a/src/my/MyMessage.tsx b/src/my/MyMessage.tsx index f366264..98970b3 100644 --- a/src/my/MyMessage.tsx +++ b/src/my/MyMessage.tsx @@ -22,7 +22,7 @@ export class MyMessage extends React.Component<{ user:string,onUserUpdate:Functi this.state={ subMenu:Menu.info, - page:this.props.onUserUpdate(user)} ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/> + page:this.props.onUserUpdate(user)} userId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/> } } @@ -31,7 +31,7 @@ export class MyMessage extends React.Component<{ user:string,onUserUpdate:Functi this.setState({subMenu:menu}) switch (menu) { case Menu.info: - this.setState({page:this.props.onUserUpdate(user)} ownUserId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>}) + this.setState({page:this.props.onUserUpdate(user)} userId={this.props.user} isMyFriend={false} isOwn={true} isAdd={false}/>}) break case Menu.help: this.setState({page:}) diff --git a/src/my/SeekHelp.tsx b/src/my/SeekHelp.tsx index 3cd7842..8ba2925 100644 --- a/src/my/SeekHelp.tsx +++ b/src/my/SeekHelp.tsx @@ -144,7 +144,7 @@ export class SeekHelp extends React.Component<{ user:string }, } + content={} open={this.state.openUserInfo} onClose={()=>this.setState({openUserInfo:false})}/>
) diff --git a/src/result.ts b/src/result.ts index 99f6559..b5463f7 100644 --- a/src/result.ts +++ b/src/result.ts @@ -2,7 +2,7 @@ * 返回信息 */ import {JSONResponse, Result, TransformData} from "./interface"; -import {ActivityDetail, PageProps, User, UserType} from "./entity"; +import {ActivityDetail, PageProps, User, UserEdit, UserType} from "./entity"; /** * 空body响应 @@ -171,6 +171,33 @@ export class ActivityDetailTransform extends TransformData{ + info?:UserEdit +} + +export class FindUserInfoTransform extends TransformData{ + protected newObject(): FindUserInfo { + return new FindUserInfo(); + } + + + protected transformBody(data: any) { + this.target.info=data.body + } +} + +export enum ModifyPwdMessage { + ok='ok', + pwd_fail='pwd_fail', + fail='fail' +} + +export class ModifyPwdTransform extends EmptyBodyDiffMsg{ + protected newObject(): JSONResponse { + return new JSONResponse(); + } + +} diff --git a/src/ui/Address.tsx b/src/ui/Address.tsx index fec031b..af3dfc2 100644 --- a/src/ui/Address.tsx +++ b/src/ui/Address.tsx @@ -12,7 +12,8 @@ export class Address extends React.Component + 服务地点 - this.props.onChange(e.target.value)}> + this.props.onChange(e.target.value)}> {this.state.addressList.map((address:AddressProps, index:number)=> diff --git a/src/ui/TestData.ts b/src/ui/TestData.ts index 6c32070..85fbe91 100644 --- a/src/ui/TestData.ts +++ b/src/ui/TestData.ts @@ -10,8 +10,8 @@ export const userObj={ //发送时间 time:new Date().getTime(), userId:"admin", - age:Math.ceil(Math.random()*100)+1, - mobile:1234567879, + age:22, + mobile:"1234567879", email:"admin@qq.com", address:"上海高新区", serviceAddress:"上海",