比較提交

...

3 次程式碼提交

作者 SHA1 備註 日期
b0f33d0bf4 输入框选中的边框改成透明 2021-10-10 23:18:46 +08:00
5910b2f560 完成主页的微博化改造 2021-10-10 23:16:19 +08:00
cfa6734461 加入了返回,改进了用户控制 2021-10-04 21:02:20 +08:00
共有 12 個檔案被更改,包括 202 行新增97 行删除

查看文件

@ -101,6 +101,21 @@ a.btn {
height: 30px;
margin-left: 10px;
}
.nav {
display: flex;
margin-left: 20px;
}
.nav-item {
padding: 12px 16px;
}
.nav-link {
text-decoration: none;
color: white;
font-size: 18px;
}
.nav-link:active {
color: white;
}
b {
color: #9E0004;

查看文件

@ -7,6 +7,7 @@ import { apis } from '../../helper/apis';
import { alert, confirmWithClose } from '../../helper/alert';
import { UserContext } from '../../helper/Context';
import Spinner from '../../components/Spinner/Spinner';
import { Link } from '../../components/SingleRouter/SingleRouter';
export class ReviewContainer extends Component {
static contextType = UserContext;
@ -66,6 +67,11 @@ export class ReviewContainer extends Component {
<div className="sdu">
<img src={images.icon} className="sdu-logo" alt="logo" />
<img src={images.name} className="sdu-name" alt="" />
<div className="nav">
<div className="nav-item">
<Link to="/" className="nav-link">首页</Link>
</div>
</div>
</div>
<UserControl pageAuthLevel={2} />
</div>

查看文件

@ -0,0 +1,8 @@
.preview {
width: 200px;
height: 200px;
}
.preview > img {
height: 200px;
cursor: zoom-in;
}

查看文件

@ -0,0 +1,69 @@
import './ImagePreview.css';
import { useCallback, useRef, useState, useEffect, Fragment } from 'react';
import Spinner from '../Spinner/Spinner';
export default function ImagePreview({ image }) {
const [isScaled, setIsScaled] = useState(false);
const [transform, setTransform] = useState('');
const imgRef = useRef(null);
const [loading, setLoading] = useState(false);
const imgWidth = useRef(0), imgHeight = useRef(0);
useEffect(() => {
setLoading(true);
let img = new Image();
img.onload = () => {
setLoading(false);
imgWidth.current = img.width;
imgHeight.current = img.height;
};
img.src = image;
}, [image]);
const scale = useCallback(() => {
if (isScaled) return;
let el = imgRef.current;
let { x, y } = el.getBoundingClientRect();
let { innerWidth, innerHeight } = window;
let initialScale = 200 / imgHeight.current,
terminalScale = Math.min(1, Math.min((innerWidth - 10) / imgWidth.current, (innerHeight - 10) / imgHeight.current));
setTransform(`translate(${x + (imgWidth.current * initialScale - innerWidth) / 2}px, ${y + (200 - innerHeight) / 2}px) scale(${initialScale})`);
setIsScaled(true);
setTimeout(() => {
setTransform(`translate(0, 0) scale(${terminalScale})`);
}, 0);
}, [isScaled]);
const unscale = useCallback(() => {
if (!isScaled) return;
let el = imgRef.current;
let { x, y } = el.getBoundingClientRect();
let { innerWidth, innerHeight } = window;
let initialScale = 200 / imgHeight.current;
setTransform(`translate(${x + (imgWidth.current * initialScale - innerWidth) / 2}px, ${y + (200 - innerHeight) / 2}px) scale(${initialScale})`);
setIsScaled(true);
setTimeout(() => {
setIsScaled(false);
}, 300);
}, [isScaled]);
return (
<div className="preview">
{
loading ? (
<div className="spinner-wrap">
<Spinner isGray />
</div>
) : (
<Fragment>
<img src={image} alt="图片" onClick={scale} ref={imgRef} />
<div className={isScaled ? 'scaled-wrap open' : 'scaled-wrap'} onClick={unscale}>
<img className="scaled-image" src={image} alt="图片" style={{ transform }} />
</div>
</Fragment>
)
}
</div>
);
}

查看文件

@ -9,6 +9,14 @@
animation: spin 1s steps(8, start) infinite;
}
.spinner-wrap {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
@keyframes spin {
from {
transform: rotate(0deg);

查看文件

@ -10,7 +10,6 @@ import { alert } from '../../helper/alert';
import History from '../../helper/history';
import AvatarUnit from '../AvatarUnit/AvatarUnit';
const exitContent = ['登录', '退出', '退出审核'];
// page level: 0: everyone, 1: login needed, 2: admin only
export default function UserControl({ pageAuthLevel, buttonOnly }) {
const { userData, setUserData } = useContext(UserContext);
@ -69,9 +68,6 @@ export default function UserControl({ pageAuthLevel, buttonOnly }) {
}
</Fragment>
)}
{
userData.role === pageAuthLevel
? (
<button
className="btn btn-hollow btn-straight"
onClick={() => {
@ -79,11 +75,11 @@ export default function UserControl({ pageAuthLevel, buttonOnly }) {
setUserData({ role: 0, name: '' });
History.force('/login');
}}
>{exitContent[pageAuthLevel]}</button>
)
: userData.role === 2 && (
>{userData.role > 0 ? '退出账号' : '登录'}</button>
{
userData.role === 2 && pageAuthLevel !== 2 && (
<button
className="btn btn-hollow btn-straight"
className="btn btn-light btn-straight"
onClick={() => {
History.push('/admin/review');
}}

查看文件

@ -6,3 +6,6 @@
color: white;
margin: 0 10px;
}
.user > :not(:first-child) {
margin-left: 10px;
}

查看文件

@ -84,8 +84,9 @@ async function send(xhr, retryConf) {
return failData;
}
if (!waitToSend.length) return failData;
if (waitToSend.length) return failData;
waitToSend.push(retryConf);
console.log(err);
// 等待列表不为空时弹框要么出现了要么就是在消失的路上,没有办法给予用户点击重试的机会,所以交由外部逻辑处理
// 注意,理论上带有时间戳的请求是不可以重试的,但是这里不做那方面考虑,如果未来有需要,可以自己实现一个刷新时间戳重试的逻辑

查看文件

@ -1,15 +1,20 @@
.index-container {
background-color: #F4F4F4;
min-height: 100vh;
}
.poster {
width: 100%;
height: 400px;
background-color: #84000B;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.img-poster {
height: 100%;
}
.index-btns {
position: absolute;
right: 40px;
@ -20,7 +25,6 @@
.index-btns > .user {
margin-right: 10px;
}
/* 这里的卡片和分栏结构就比较接近bootstrap了,可惜视觉做的太古板,如果愿意的话改成Material Design就更好了 */
.split-lg > .card {
width: 440px;
flex-shrink: 0;
@ -29,7 +33,7 @@
.card-header {
padding: .5em;
font-size: 20px;
border-bottom: 1px solid #e6e6e6;
font-weight: bold;
}
.card-body {
padding: 10px 5px;
@ -41,42 +45,47 @@
flex-wrap: wrap;
}
.img-list {
width: 100%;
display: flex;
flex-wrap: wrap;
margin: -3px -5px;
align-items: flex-start;
}
.img-list > img {
width: 200px;
margin: 3px 5px;
}
.message-list {
margin: 0;
padding-left: 0;
list-style: none;
}
.message-list > li {
line-height: 20px;
padding: 8px 0;
position: relative;
}
/* list disk */
.message-list > li::before {
content: "";
width: 8px;
height: 8px;
background-color: #DADADA;
margin-right: 10px;
border-radius: 50%;
display: inline-block;
}
@media (max-width: 980px) {
.split-lg > .card {
width: 100%;
margin-bottom: 20px;
}
}
.posts {
}
.post {
padding: 10px;
border-radius: 12px;
background-color: white;
margin-bottom: 10px;
box-shadow: 2px 2px 4px #0001;
}
.post > p {
padding-left: 40px;
}
.post-header {
padding: 5px;
display: flex;
align-items: center;
border-bottom: 1px solid #eee;
}
.post-body {
padding: 5px;
}
.post-avatar {
width: 40px;
height: 40px;
border-radius: 20px;
margin-right: 10px;
}
.post-username {
}
.post-time {
color: #888;
}
.post-image {
width: 200px;
height: 200px;
}

查看文件

@ -1,4 +1,5 @@
import { Component } from 'react';
import ImagePreview from '../components/ImagePreview/ImagePreview';
import { Link } from '../components/SingleRouter/SingleRouter';
import Spinner from '../components/Spinner/Spinner';
import UserControl from '../components/UserControl/UserControl';
@ -12,8 +13,7 @@ export class AppContainer extends Component {
constructor(props) {
super(props);
this.state = {
essentialMessages: [],
essentialImages: [],
posts: [],
fetchingEssential: false,
};
}
@ -25,26 +25,20 @@ export class AppContainer extends Component {
this.setState({ fetchingEssential: false });
if (networkStatus !== 200) return;
if (!status) return alert('获取精选列表失败:' + data + ',请刷新重试');
let messages = [], images = [];
data.forEach(post => {
if (post.content) messages.push(post.content);
if (post.image) images.push(post.image);
});
this.setState({ essentialMessages: messages, essentialImages: images });
this.setState({ posts: data });
});
}
render() {
return (
<div className="index-container">
<div className="poster">
<img src={images.poster} className="img-poster" alt="海报" />
<div className="poster" style={{ backgroundImage: `url(${images.poster})` }}>
<div className='index-btns'>
<UserControl pageAuthLevel={1} buttonOnly />
<Link to="/upload" className="btn btn-light btn-straight btn-partIn">点击参加</Link>
</div>
</div>
<div className="content split-lg">
<div className="content">
<div className="card">
<div className="card-header">
精选留言
@ -56,43 +50,33 @@ export class AppContainer extends Component {
<div className="col-center"><Spinner isGray /></div>
)
: (
this.state.essentialMessages.length === 0
this.state.posts.length === 0
? (
<div className="col-center">暂时没有精选留言</div>
)
: (
<ul className="message-list">
<div className="posts">
{
this.state.essentialMessages.map((msg, i) => (
<li dangerouslySetInnerHTML={{ __html: msg }} key={i}></li>
))
}
</ul>
)
this.state.posts.map((post, i) => (
<div className="post" key={i}>
<div className="post-header">
<img class="post-avatar" src={post.avatar} alt="头像" />
<div>
<div class="post-username">{post.realName}</div>
<div class="post-time">{new Date(post.time * 1000).toLocaleString()}发布</div>
</div>
</div>
<div className="post-body">
<p dangerouslySetInnerHTML={{ __html: post.content }}></p>
{
post.image && (
<div className="post-image">
<ImagePreview image={post.image} />
</div>
)
}
</div>
</div>
<div className="card">
<div className="card-header">
精选图片
</div>
<div className="card-body">
{
this.state.fetchingEssential
? (
<div className="col-center"><Spinner isGray /></div>
)
: (
this.state.essentialImages.length === 0
? (
<div className="col-center">暂时没有精选图片</div>
)
: (
<div className="img-list">
{
this.state.essentialImages.map((src, i) => (
<img src={src} key={i} alt="精选图片" />
))
}
</div>

查看文件

@ -21,7 +21,7 @@
}
.form-group > input:focus {
outline: none;
border-color: #FDFDFD;
border-color: transparent;
background-color: #FDFDFD;
box-shadow: 1px 3px 6px #0001;
transform: translate(-2px, -2px);

查看文件

@ -8,6 +8,7 @@ import { images } from '../resources.json';
import './upload.css';
import UserControl from '../components/UserControl/UserControl';
import { Link } from '../components/SingleRouter/SingleRouter';
export class UploadContainer extends Component {
constructor(props) {
@ -67,6 +68,11 @@ export class UploadContainer extends Component {
<div className="sdu">
<img src={images.icon} className="sdu-logo" alt="logo" />
<img src={images.name} className="sdu-name" alt="" />
<div className="nav">
<div className="nav-item">
<Link to="/" className="nav-link">首页</Link>
</div>
</div>
</div>
<UserControl pageAuthLevel={1} />
</div>