mirror of
https://github.com/Funkoala14/CreatorCenter_OOIN.git
synced 2025-06-07 22:58:14 +08:00
[dev]login
This commit is contained in:
parent
45d7a7de1a
commit
8820124bf9
@ -1,7 +1,9 @@
|
||||
import { Spinner } from 'react-bootstrap';
|
||||
|
||||
export default function LoadingOverlay({ status }) {
|
||||
if (status !== 'loading') return null;
|
||||
export default function LoadingOverlay({ loading }) {
|
||||
if (!loading) return null;
|
||||
|
||||
|
||||
return (
|
||||
<div style={styles.overlay}>
|
||||
<Spinner animation='border' role='status' variant='primary' style={{ width: '3rem', height: '3rem' }}>
|
||||
@ -12,12 +14,12 @@ export default function LoadingOverlay({ status }) {
|
||||
}
|
||||
const styles = {
|
||||
overlay: {
|
||||
position: 'absolute', // 可改为 fixed 实现全屏
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.6)', // 半透明背景
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.6)',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
|
@ -5,6 +5,7 @@ import { useDispatch, useSelector } from 'react-redux';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { loginThunk } from '../store/slices/authSlice';
|
||||
import LoadingOverlay from '../components/LoadingOverlay';
|
||||
|
||||
export default function Login() {
|
||||
const [formData, setFormData] = useState({
|
||||
@ -39,9 +40,9 @@ export default function Login() {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='login-container'>
|
||||
<LoadingOverlay loading={isLoading} />
|
||||
<div className='title'>Creator Center</div>
|
||||
<Form className='login-form' onSubmit={handleSubmit}>
|
||||
{/* <Form.Group>
|
||||
|
@ -1,16 +1,19 @@
|
||||
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
||||
import api from '@/services/api';
|
||||
import { setNotificationBarMessage } from './notificationBarSlice';
|
||||
|
||||
export const loginThunk = createAsyncThunk('auth/login', async (credentials, { rejectWithValue }) => {
|
||||
|
||||
export const loginThunk = createAsyncThunk('auth/login', async (credentials, { rejectWithValue, dispatch }) => {
|
||||
try {
|
||||
const response = await api.post('/user/login/', credentials);
|
||||
if (response.code === 200) {
|
||||
sessionStorage.setItem('token', response.data.token);
|
||||
return response.data;
|
||||
} else {
|
||||
return rejectWithValue(response.message);
|
||||
throw new Error(response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch(setNotificationBarMessage({ message: error.message, type: 'error' }));
|
||||
return rejectWithValue(error.message);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user