完成审核页面,对样式做大量微调(视觉的按钮好怪啊),但是目前发现了请求处理等待流程的bug

此提交包含在:
2021-08-01 00:11:33 +08:00
父節點 a1386d8870
當前提交 b8f99f4e4c
共有 16 個檔案被更改,包括 249 行新增118 行删除

40
src/admin/review/review.css 一般檔案
查看文件

@@ -0,0 +1,40 @@
.review-content {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.review-content > p {
width: calc(100% - 300px);
}
.review-img {
margin: 40px 0;
display: block;
cursor: zoom-in;
}
.review-img > img {
/* max-height: 300px; */
max-width: 800px;
}
.review-btns {
display: flex;
width: 100%;
justify-content: space-between;
border-top: 1px solid #DDD;
box-sizing: border-box;
padding: 40px 150px;
}
@media (max-width: 840px) {
.review-img > img {
max-width: 500px;
}
.review-content > p {
width: calc(100% - 100px);
}
.review-btns {
padding: 30px 50px;
}
}

108
src/admin/review/review.js 一般檔案
查看文件

@@ -0,0 +1,108 @@
import './review.css';
import { Component } from 'react';
import UserControl from '../../components/UserControl/UserControl';
import { images } from '../../resources.json';
import { get, post } from '../../helper/axios';
import { apis } from '../../helper/apis';
import { alert, confirmWithClose } from '../../helper/alert';
import { UserContext } from '../../helper/Context';
import Spinner from '../../components/Spinner/Spinner';
export class ReviewContainer extends Component {
static contextType = UserContext;
fetched = false;
constructor(props) {
super(props);
this.state = {
posts: [],
fetchingPosts: false,
reviewingNow: 0,
actionPerforming: 0
};
}
componentDidMount() {
if (this.context.userData?.role === 2) this.fetchPosts();
}
componentDidUpdate() {
if (this.context.userData?.role === 2 && !this.fetched) this.fetchPosts();
}
fetchPosts() {
this.fetched = true;
this.setState({ fetchingPosts: true });
get(apis.listNotReviewed).then(({ data, status, networkStatus }) => {
this.setState({ fetchingPosts: false });
if (networkStatus !== 200) return;
if (!status) return alert('拉取审核列表失败:' + data + ',请刷新重试');
this.setState({ posts: data });
});
}
async review(accepted) {
// 哇提示语怎么这么生硬啊
if (!await confirmWithClose(`<div class="expanded-msg">确认<b>${accepted ? '发布' : '不通过'}</b>此条信息?</div>`)) return;
const { posts, reviewingNow } = this.state;
const { id } = posts[reviewingNow];
this.setState({ actionPerforming: accepted ? 1 : 2 });
post(apis.setStatus, { id, status: accepted ? 2 : 3 }).then(({ data, status, networkStatus }) => {
this.setState({ actionPerforming: 0 });
if (networkStatus !== 200) return;
if (!status) return alert('提交审核失败:' + data + ',请稍后重试');
if (this.state.reviewingNow === this.state.posts.length - 1)
this.fetchPosts();
else
this.setState({ reviewingNow: this.state.reviewingNow + 1 });
});
}
render() {
return (
<div className="review-container">
<div className="banner">
<div className="sdu">
<img src={images.icon} className="sdu-logo" alt="logo" />
<img src={images.name} className="sdu-name" alt="" />
</div>
<UserControl />
</div>
<div className="content">
{
this.state.fetchingPosts
? (
<div className="col-center">
<Spinner isGray />
<div style={{ marginLeft: '10px' }}>正在加载审核列表...</div>
</div>
)
: (
this.state.posts.length === 0
? (
<div className="col-center">暂时没有待审核的内容哦</div>
)
: (
<div className="review-content">
<p>{this.state.posts[this.state.reviewingNow].content}</p>
<a className="review-img" href={this.state.posts[this.state.reviewingNow].image} target="_blank" rel="noreferrer">
<img src={this.state.posts[this.state.reviewingNow].image} alt="待审核的配图" />
</a>
<div className="review-btns">
<button className="btn btn-primary" onClick={() => this.review(true)} disabled={this.state.actionPerforming !== 0}>
{this.state.actionPerforming === 1 ? (<Spinner />) : '发布'}
</button>
<button className="btn btn-gray" onClick={() => this.review(false)} disabled={this.state.actionPerforming !== 0}>
{this.state.actionPerforming === 2 ? (<Spinner />) : '不通过'}
</button>
</div>
</div>
)
)
}
</div>
</div>
);
}
}