From 1b6cbd59ebc7c94b68f4b729386979374d3775e8 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Mon, 1 Jun 2020 06:51:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B4=BB=E5=8A=A8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8F=AF=E6=9B=B4=E6=96=B0=E6=B4=BB=E5=8A=A8=E5=9B=BE?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Active.tsx | 24 +++++++++++---- src/User.tsx | 18 +++++++++-- src/entity.ts | 3 ++ src/ui/UploadImg.tsx | 71 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 src/ui/UploadImg.tsx diff --git a/src/Active.tsx b/src/Active.tsx index 827ab77..a26a652 100644 --- a/src/Active.tsx +++ b/src/Active.tsx @@ -1,15 +1,22 @@ import React from "react"; -import {Button, Form, ListGroup, Tab, Table, Tabs} from "react-bootstrap"; +import {Button, Form, Image, ListGroup, Tab, Table, Tabs} from "react-bootstrap"; import {ManagerActivity} from "./entity"; import {JSONResponse, Method, request} from "./interface"; -import {API} from "./api"; +import {API, prefix} from "./api"; import {EmptyBodyTransform, FindActivityRes, FindActivityTransform, PageDataMessage, SimpleMessage} from "./result"; import {MyDialog} from "./ui/MyDialog"; import moment from "moment"; import {Input} from "./ui/InputGroup"; +import {UploadImg} from "./ui/UploadImg"; const contentMaxLength=50 - +/** + * 图片尺寸限制 + */ +const maxImageSize={ + width:100, + height:100 +} class EditActive extends React.Component< { onClick:Function; @@ -31,6 +38,10 @@ class EditActive extends React.Component< render() { return (
+
+ + this.setState({activity:{...this.state.activity,...{activityImgFile:value}}})} /> +
this.setState({ activity:{...this.state.activity,...{title:value}} @@ -108,6 +119,7 @@ export class Active extends React.Component# 活动标题 活动内容 + 活动图片 开始时间 结束时间 求助用户id @@ -121,6 +133,7 @@ export class Active extends React.Component{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} @@ -159,9 +172,10 @@ export class Active extends React.Component) { switch (res.customResult) { diff --git a/src/User.tsx b/src/User.tsx index 06220da..6625657 100644 --- a/src/User.tsx +++ b/src/User.tsx @@ -7,7 +7,14 @@ import {API, prefix} from "./api"; import {EmptyBodyTransform, FindUserRes, FindUserTransform, PageDataMessage, SimpleMessage} from "./result"; import {MyDialog} from "./ui/MyDialog"; import {Address} from "./ui/Address"; - +import {UploadImg} from "./ui/UploadImg"; +/** + * 图片尺寸限制 + */ +const maxImageSize={ + width:100, + height:100 +} class EditUser extends React.Component<{ user:UserEntity; modifyUser:Function; @@ -30,6 +37,10 @@ class EditUser extends React.Component<{ render() { return ( +
+ + this.setState({ user:{...this.state.user,...{activityImgFile:value}}})} /> +
this.setState({ user:{...this.state.user,...{name:value}} @@ -273,7 +284,7 @@ export class User extends React.Component< */ private modifyUser(user: UserEntity) { let that=this - request(API.account.updateUser,Method.POST, { + request(API.account.updateUser,Method.PUT, { userId:user.userId, name:user.name, age:String(user.age), @@ -283,7 +294,8 @@ export class User extends React.Component< userType:user.userType, mobile:user.mobile, email:user.email, - info:user.info + info:user.info, + activityImgFile:user.activityImgFile?user.activityImgFile:null },new EmptyBodyTransform(),function (res:JSONResponse) { switch (res.customResult) { diff --git a/src/entity.ts b/src/entity.ts index 4e040d2..6bae0be 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -40,6 +40,8 @@ export interface UserEntity{ isMyFriend?:boolean; //时间币 timeScore?:boolean; + //头像文件 + activityImgFile?:any; } //活动 @@ -182,6 +184,7 @@ export interface ManagerActivity { activityEndTime:number; seekHelpUser:number; helpUser:Array; + activityImgFile?:any; } /** diff --git a/src/ui/UploadImg.tsx b/src/ui/UploadImg.tsx new file mode 100644 index 0000000..b37e879 --- /dev/null +++ b/src/ui/UploadImg.tsx @@ -0,0 +1,71 @@ +import React from "react"; +import {Form, Image} from "react-bootstrap"; +import path from "path"; + +/** + * 上传图片 + */ +export class UploadImg extends React.Component< + { + //tip + tip:string, + //图片尺寸限制 + maxImageSize:{ + width:number, + height:number + }; + //上传事件 + onChange:Function; +}, { + //imgObj + imgObj?:any; + //图片文件名 + imageName?:string; +}>{ + + + constructor(props: Readonly<{ tip: string; maxImageSize: { width: number; height: number }; onChange: Function }>) { + super(props); + + this.state={} + } + + render() { + return ( +
+ {/* + 预览背景图 + */} + { + if (s.target instanceof HTMLImageElement) { + //限制图片显示大小 + s.target.width = s.target.width > this.props.maxImageSize.width ? this.props.maxImageSize.width : s.target.width + s.target.height = s.target.height > this.props.maxImageSize.height ? this.props.maxImageSize.height : s.target.height + s.target.classList.remove('d-none') + } + } + }/> + + {/*上传背景图*/} +
+ { + const file=e.target.files[0] + if(!file){ + return + } + this.setState({ + imgObj:URL.createObjectURL(file), + imageName:e.target.value + }) + this.props.onChange(file) + }} + /> +
+
+ ) + } +}