chore: update style

This commit is contained in:
JustSong 2023-07-23 13:24:57 +08:00
parent fcd256a84b
commit 5d0b73b7bd
3 changed files with 45 additions and 68 deletions

View File

@ -1,38 +1,25 @@
import React, { useContext, useEffect, useState } from 'react';
import {
Button,
Divider,
Form,
Grid,
Header,
Image,
Message,
Modal,
Segment,
} from 'semantic-ui-react';
import { Button, Divider, Form, Grid, Header, Image, Message, Modal, Segment } from 'semantic-ui-react';
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import { UserContext } from '../context/User';
import { API, getLogo, showError, showSuccess, showInfo } from '../helpers';
import { API, getLogo, showError, showSuccess } from '../helpers';
const LoginForm = () => {
const [inputs, setInputs] = useState({
username: '',
password: '',
wechat_verification_code: '',
wechat_verification_code: ''
});
const [searchParams, setSearchParams] = useSearchParams();
const [submitted, setSubmitted] = useState(false);
const { username, password } = inputs;
const [userState, userDispatch] = useContext(UserContext);
let navigate = useNavigate();
function handleNavigateTo(url) {
navigate(url);
}
const [status, setStatus] = useState({});
const logo = getLogo();
useEffect(() => {
if (searchParams.get("expired")) {
if (searchParams.get('expired')) {
showError('未登录或登录已过期,请重新登录!');
}
let status = localStorage.getItem('status');
@ -80,7 +67,7 @@ const LoginForm = () => {
if (username && password) {
const res = await API.post(`/api/user/login`, {
username,
password,
password
});
const { success, message, data } = res.data;
if (success) {
@ -95,44 +82,46 @@ const LoginForm = () => {
}
return (
<Grid textAlign="center" style={{ marginTop: '48px' }}>
<Grid textAlign='center' style={{ marginTop: '48px' }}>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as="h2" color="" textAlign="center">
<Header as='h2' color='' textAlign='center'>
<Image src={logo} /> 用户登录
</Header>
<Form size="large">
<Form size='large'>
<Segment>
<Form.Input
fluid
icon="user"
iconPosition="left"
placeholder="用户名"
name="username"
icon='user'
iconPosition='left'
placeholder='用户名'
name='username'
value={username}
onChange={handleChange}
/>
<Form.Input
fluid
icon="lock"
iconPosition="left"
placeholder="密码"
name="password"
type="password"
icon='lock'
iconPosition='left'
placeholder='密码'
name='password'
type='password'
value={password}
onChange={handleChange}
/>
<Button color="green" fluid size="large" onClick={handleSubmit}>
<Button color='green' fluid size='large' onClick={handleSubmit}>
登录
</Button>
</Segment>
</Form>
<Message>
<Button onClick={() => handleNavigateTo('/reset')}>
忘记密码
</Button>
<Button onClick={() => handleNavigateTo('/register')}>
注册账户
</Button>
忘记密码
<Link to='/reset' className='btn btn-link'>
点击重置
</Link>
没有账户
<Link to='/register' className='btn btn-link'>
点击注册
</Link>
</Message>
{status.github_oauth || status.wechat_login ? (
<>
@ -140,8 +129,8 @@ const LoginForm = () => {
{status.github_oauth ? (
<Button
circular
color="black"
icon="github"
color='black'
icon='github'
onClick={onGitHubOAuthClicked}
/>
) : (
@ -150,8 +139,8 @@ const LoginForm = () => {
{status.wechat_login ? (
<Button
circular
color="green"
icon="wechat"
color='green'
icon='wechat'
onClick={onWeChatLoginClicked}
/>
) : (
@ -175,18 +164,18 @@ const LoginForm = () => {
微信扫码关注公众号输入验证码获取验证码三分钟内有效
</p>
</div>
<Form size="large">
<Form size='large'>
<Form.Input
fluid
placeholder="验证码"
name="wechat_verification_code"
placeholder='验证码'
name='wechat_verification_code'
value={inputs.wechat_verification_code}
onChange={handleChange}
/>
<Button
color=""
color=''
fluid
size="large"
size='large'
onClick={onSubmitWeChatVerificationCode}
>
登录

View File

@ -5,7 +5,7 @@ import Turnstile from 'react-turnstile';
const PasswordResetForm = () => {
const [inputs, setInputs] = useState({
email: '',
email: ''
});
const { email } = inputs;

View File

@ -1,13 +1,5 @@
import React, { useEffect, useState } from 'react';
import {
Button,
Form,
Grid,
Header,
Image,
Message,
Segment,
} from 'semantic-ui-react';
import { Button, Form, Grid, Header, Image, Message, Segment } from 'semantic-ui-react';
import { Link, useNavigate } from 'react-router-dom';
import { API, getLogo, showError, showInfo, showSuccess } from '../helpers';
import Turnstile from 'react-turnstile';
@ -18,7 +10,7 @@ const RegisterForm = () => {
password: '',
password2: '',
email: '',
verification_code: '',
verification_code: ''
});
const { username, password, password2 } = inputs;
const [showEmailVerification, setShowEmailVerification] = useState(false);
@ -45,9 +37,7 @@ const RegisterForm = () => {
});
let navigate = useNavigate();
function handleNavigateTo(url) {
navigate(url);
}
function handleChange(e) {
const { name, value } = e.target;
console.log(name, value);
@ -186,17 +176,15 @@ const RegisterForm = () => {
onClick={handleSubmit}
loading={loading}
>
确认注册
注册
</Button>
</Segment>
</Form>
<Message>
<Button onClick={() => handleNavigateTo('/reset')}>
忘记密码
</Button>
<Button onClick={() => handleNavigateTo('/login')}>
已有帐户
</Button>
已有账户
<Link to='/login' className='btn btn-link'>
点击登录
</Link>
</Message>
</Grid.Column>
</Grid>