mirror of https://github.com/fantasticit/think.git
client: add loading
This commit is contained in:
parent
812f85ddfd
commit
71d3a6342e
|
@ -18,7 +18,7 @@ export const useUser = () => {
|
||||||
|
|
||||||
const login = useCallback(
|
const login = useCallback(
|
||||||
(data) => {
|
(data) => {
|
||||||
HttpClient.post<IUser>('/user/login', data).then((res) => {
|
return HttpClient.post<IUser>('/user/login', data).then((res) => {
|
||||||
const user = res as unknown as ILoginUser;
|
const user = res as unknown as ILoginUser;
|
||||||
mutate(user);
|
mutate(user);
|
||||||
setStorage('user', JSON.stringify(user));
|
setStorage('user', JSON.stringify(user));
|
||||||
|
|
|
@ -3,8 +3,9 @@ import { Author } from 'components/author';
|
||||||
import { LogoImage, LogoText } from 'components/logo';
|
import { LogoImage, LogoText } from 'components/logo';
|
||||||
import { Seo } from 'components/seo';
|
import { Seo } from 'components/seo';
|
||||||
import { useUser } from 'data/user';
|
import { useUser } from 'data/user';
|
||||||
|
import { useToggle } from 'hooks/use-toggle';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import React from 'react';
|
import React, { useCallback } from 'react';
|
||||||
|
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
|
@ -13,6 +14,21 @@ const { Title, Text } = Typography;
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const { login } = useUser();
|
const { login } = useUser();
|
||||||
|
const [loading, toggleLoading] = useToggle(false);
|
||||||
|
|
||||||
|
const toLogin = useCallback(
|
||||||
|
(data) => {
|
||||||
|
toggleLoading(true);
|
||||||
|
login(data)
|
||||||
|
.then(() => {
|
||||||
|
toggleLoading(false);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
toggleLoading(false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[login, toggleLoading]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout className={styles.wrap}>
|
<Layout className={styles.wrap}>
|
||||||
|
@ -24,7 +40,7 @@ const Page = () => {
|
||||||
<LogoText></LogoText>
|
<LogoText></LogoText>
|
||||||
</Space>
|
</Space>
|
||||||
</Title>
|
</Title>
|
||||||
<Form className={styles.form} initValues={{ name: '', password: '' }} onSubmit={login}>
|
<Form className={styles.form} initValues={{ name: '', password: '' }} onSubmit={toLogin}>
|
||||||
<Title type="tertiary" heading={5} style={{ marginBottom: 16, textAlign: 'center' }}>
|
<Title type="tertiary" heading={5} style={{ marginBottom: 16, textAlign: 'center' }}>
|
||||||
账户登录
|
账户登录
|
||||||
</Title>
|
</Title>
|
||||||
|
@ -45,7 +61,7 @@ const Page = () => {
|
||||||
placeholder="输入用户密码"
|
placeholder="输入用户密码"
|
||||||
rules={[{ required: true, message: '请输入密码' }]}
|
rules={[{ required: true, message: '请输入密码' }]}
|
||||||
></Form.Input>
|
></Form.Input>
|
||||||
<Button htmlType="submit" type="primary" theme="solid" block style={{ margin: '16px 0' }}>
|
<Button htmlType="submit" type="primary" theme="solid" block loading={loading} style={{ margin: '16px 0' }}>
|
||||||
登录
|
登录
|
||||||
</Button>
|
</Button>
|
||||||
<footer>
|
<footer>
|
||||||
|
|
|
@ -70,7 +70,7 @@ const Page = () => {
|
||||||
placeholder="确认用户密码"
|
placeholder="确认用户密码"
|
||||||
rules={[{ required: true, message: '请再次输入密码' }]}
|
rules={[{ required: true, message: '请再次输入密码' }]}
|
||||||
></Form.Input>
|
></Form.Input>
|
||||||
<Button htmlType="submit" type="primary" theme="solid" block style={{ margin: '16px 0' }}>
|
<Button htmlType="submit" type="primary" theme="solid" block loading={loading} style={{ margin: '16px 0' }}>
|
||||||
注册
|
注册
|
||||||
</Button>
|
</Button>
|
||||||
<footer>
|
<footer>
|
||||||
|
|
Loading…
Reference in New Issue