开发: 登录等功能
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Footer from '@/components/Footer';
|
||||
import { login } from '@/services/ant-design-pro/api';
|
||||
import { IAjaxReturn, post } from '@/services/ajax';
|
||||
import { getFakeCaptcha } from '@/services/ant-design-pro/login';
|
||||
import {
|
||||
AlipayCircleOutlined,
|
||||
@@ -16,11 +16,12 @@ import {
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { useEmotionCss } from '@ant-design/use-emotion-css';
|
||||
import { FormattedMessage, history, SelectLang, useIntl, useModel, Helmet } from '@umijs/max';
|
||||
import { Alert, message, Tabs } from 'antd';
|
||||
import Settings from '../../../../config/defaultSettings';
|
||||
import { FormattedMessage, Helmet, history, SelectLang, useIntl, useModel } from '@umijs/max';
|
||||
import { Alert, App, message, Tabs } from 'antd';
|
||||
import { stringify as qsStringify } from 'qs';
|
||||
import React, { useState } from 'react';
|
||||
import { flushSync } from 'react-dom';
|
||||
import Settings from '../../../../config/defaultSettings';
|
||||
|
||||
const ActionIcons = () => {
|
||||
const langClassName = useEmotionCss(({ token }) => {
|
||||
@@ -113,33 +114,34 @@ const Login: React.FC = () => {
|
||||
});
|
||||
}
|
||||
};
|
||||
const { notification } = App.useApp();
|
||||
|
||||
window.NotificationCF = notification;
|
||||
|
||||
const handleSubmit = async (values: API.LoginParams) => {
|
||||
try {
|
||||
// 登录
|
||||
const msg = await login({ ...values, type });
|
||||
if (msg.status === 'ok') {
|
||||
const defaultLoginSuccessMessage = intl.formatMessage({
|
||||
id: 'pages.login.success',
|
||||
defaultMessage: '登录成功!',
|
||||
const data = {
|
||||
user: values.username,
|
||||
password: values.password,
|
||||
};
|
||||
|
||||
post({ url: '/User/Login', data: qsStringify(data) }).then((res: IAjaxReturn) => {
|
||||
if (res && res.err_code == 0) {
|
||||
notification.success({
|
||||
message: '登录成功',
|
||||
description: '登录成功',
|
||||
});
|
||||
flushSync(() => {
|
||||
// 登录成功!
|
||||
setInitialState((s) => ({
|
||||
...s,
|
||||
currentUser: res.data,
|
||||
currentAuthority: 'admin',
|
||||
}));
|
||||
});
|
||||
message.success(defaultLoginSuccessMessage);
|
||||
await fetchUserInfo();
|
||||
const urlParams = new URL(window.location.href).searchParams;
|
||||
history.push(urlParams.get('redirect') || '/');
|
||||
return;
|
||||
}
|
||||
console.log(msg);
|
||||
// 如果失败去设置用户错误信息
|
||||
setUserLoginState(msg);
|
||||
} catch (error) {
|
||||
const defaultLoginFailureMessage = intl.formatMessage({
|
||||
id: 'pages.login.failure',
|
||||
defaultMessage: '登录失败,请重试!',
|
||||
});
|
||||
console.log(error);
|
||||
message.error(defaultLoginFailureMessage);
|
||||
}
|
||||
});
|
||||
};
|
||||
const { status, type: loginType } = userLoginState;
|
||||
|
||||
@@ -154,32 +156,50 @@ const Login: React.FC = () => {
|
||||
- {Settings.title}
|
||||
</title>
|
||||
</Helmet>
|
||||
<Lang />
|
||||
{/* <Lang /> */}
|
||||
<div
|
||||
style={{
|
||||
flex: '1',
|
||||
padding: '32px 0',
|
||||
}}
|
||||
>
|
||||
{/* <ChatTime msgtime={1680713999000}></ChatTime>
|
||||
<ChatTime msgtime={1680763041000}></ChatTime>
|
||||
<ChatTime msgtime={1680710399000}></ChatTime>
|
||||
<ChatTime msgtime={1680623999000}></ChatTime>
|
||||
<ChatTime msgtime={1680537599000}></ChatTime>
|
||||
<ChatTime msgtime={1680451199000}></ChatTime>
|
||||
<ChatTime msgtime={1680331041000}></ChatTime>
|
||||
<ChatTime msgtime={1680195599000}></ChatTime>
|
||||
<ChatTime msgtime={1680244641000}></ChatTime>
|
||||
<ChatTime msgtime={1680191999000}></ChatTime>
|
||||
<ChatTime msgtime={1680158241000}></ChatTime>
|
||||
<ChatRevoke></ChatRevoke>
|
||||
<ChatAgreeOrNot />
|
||||
<ChatVoice></ChatVoice>
|
||||
<ChatVideo></ChatVideo>
|
||||
<ChatCard></ChatCard>
|
||||
<ChatEmotion></ChatEmotion>
|
||||
<ChatBar></ChatBar> */}
|
||||
<LoginForm
|
||||
contentStyle={{
|
||||
minWidth: 280,
|
||||
maxWidth: '75vw',
|
||||
}}
|
||||
logo={<img alt="logo" src="/logo.svg" />}
|
||||
title="Ant Design"
|
||||
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })}
|
||||
title="scrm.antd"
|
||||
subTitle={<div style={{ height: 30 }}></div>}
|
||||
initialValues={{
|
||||
autoLogin: true,
|
||||
}}
|
||||
actions={[
|
||||
<FormattedMessage
|
||||
key="loginWith"
|
||||
id="pages.login.loginWith"
|
||||
defaultMessage="其他登录方式"
|
||||
/>,
|
||||
<ActionIcons key="icons" />,
|
||||
]}
|
||||
// actions={[
|
||||
// <FormattedMessage
|
||||
// key="loginWith"
|
||||
// id="pages.login.loginWith"
|
||||
// defaultMessage="其他登录方式"
|
||||
// />,
|
||||
// <ActionIcons key="icons" />,
|
||||
// ]}
|
||||
onFinish={async (values) => {
|
||||
await handleSubmit(values as API.LoginParams);
|
||||
}}
|
||||
@@ -196,13 +216,13 @@ const Login: React.FC = () => {
|
||||
defaultMessage: '账户密码登录',
|
||||
}),
|
||||
},
|
||||
{
|
||||
key: 'mobile',
|
||||
label: intl.formatMessage({
|
||||
id: 'pages.login.phoneLogin.tab',
|
||||
defaultMessage: '手机号登录',
|
||||
}),
|
||||
},
|
||||
// {
|
||||
// key: 'mobile',
|
||||
// label: intl.formatMessage({
|
||||
// id: 'pages.login.phoneLogin.tab',
|
||||
// defaultMessage: '手机号登录',
|
||||
// }),
|
||||
// },
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -246,7 +266,7 @@ const Login: React.FC = () => {
|
||||
}}
|
||||
placeholder={intl.formatMessage({
|
||||
id: 'pages.login.password.placeholder',
|
||||
defaultMessage: '密码: ant.design',
|
||||
defaultMessage: '请输入密码',
|
||||
})}
|
||||
rules={[
|
||||
{
|
||||
@@ -364,6 +384,7 @@ const Login: React.FC = () => {
|
||||
</LoginForm>
|
||||
</div>
|
||||
<Footer />
|
||||
<div style={{ height: 12 }}></div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user