You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
help_user/src/ui/Activity.tsx

87 lines
3.1 KiB

import React from "react";
import {Button, Image} from "react-bootstrap";
import {ActivityDetail} from "../entity";
import moment from "moment";
import {Method, request} from "../interface";
import {ActivityDetailRes, ActivityDetailTransform, SimpleMessage} from "../result";
import {showActivityTip} from "../public";
import {Cookies} from "react-cookie";
import {Api, prefix} from "../api";
/**
* 活动信息
*/
export class Activity extends React.Component<
{
activityId:number|null;
/**
* 隐藏帮助按钮
*/
hideButton:boolean;
/**
* 报名方法
*/
applyFunction?:Function;
cookies:Cookies;
},
{
activity?:ActivityDetail ,
result:JSX.Element
}>{
constructor(props: Readonly<{ activityId: number | null; hideButton: boolean; applyFunction?: Function; cookies:Cookies }>) {
super(props);
this.state={
result:<h3 className="text-info text-center"></h3>
}
}
componentDidMount() {
if(this.props.activityId) {
this.loadActivityWithId()
}
}
/**
* 查找活动
*/
loadActivityWithId(){
let that=this
request(Api.main.activity.find+"/"+this.props.activityId,Method.GET,{},new ActivityDetailTransform(),function(res:ActivityDetailRes){
switch (res.customResult) {
case SimpleMessage.fail:
that.setState({
result:<h3 className="text-danger text-center"></h3>
});break;
case SimpleMessage.ok:
that.setState({
activity:res.activity
});break;
}
})
}
render() {
return (
<div className="overflow-auto activity-detail-height">
{this.state.activity?
<div>
<div className="text-center">
<Image className="mb-3 activityImage" src={prefix.image+this.state.activity.activityImg}/>
</div>
<h3 className="text-center">{this.state.activity.title}</h3>
<p className="p-2">{this.state.activity.content}</p>
<h5 className="text-center">{"活动开始时间:"+moment(this.state.activity.activityStartTime).format("YYYY-MM-DD HH:mm:ss")}</h5>
<h5 className="text-center mb-3">{"活动结束时间:"+moment(this.state.activity.activityEndTime).format("YYYY-MM-DD HH:mm:ss")}</h5>
{<div className="text-center ml-auto mr-auto">{showActivityTip(this.state.activity,this,
<Button onClick={()=>this.props.applyFunction?this.props.applyFunction(this.props.activityId):null}></Button>)}</div>}
</div>
:this.state.result}
</div>
);
}
}