|
|
|
@@ -1,11 +1,12 @@ |
|
|
|
import { clearSessionToken, setSessionToken } from '@/access'; |
|
|
|
import { getClientInfoReq } from '@/services/auth'; |
|
|
|
import { getCaptchaImg, login } from '@/services/system/auth'; |
|
|
|
import { parseJsonText } from '@/utils'; |
|
|
|
import { safeInvoke } from '@/utils/functional'; |
|
|
|
import LocalStorage from '@/utils/localStorage'; |
|
|
|
import { to } from '@/utils/promise'; |
|
|
|
import SessionStorage from '@/utils/sessionStorage'; |
|
|
|
import { gotoOAuth2 } from '@/utils/ui'; |
|
|
|
import { history, useModel } from '@umijs/max'; |
|
|
|
import { Button, Checkbox, Flex, Form, Image, Input, message, type InputRef } from 'antd'; |
|
|
|
import { Form, message, type InputRef } from 'antd'; |
|
|
|
import CryptoJS from 'crypto-js'; |
|
|
|
import { useEffect, useRef, useState } from 'react'; |
|
|
|
import { flushSync } from 'react-dom'; |
|
|
|
@@ -31,25 +32,35 @@ const Login = () => { |
|
|
|
const captchaInputRef = useRef<InputRef>(null); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
getCaptchaCode(); |
|
|
|
const autoLogin = LocalStorage.getItem(LocalStorage.rememberPasswordKey) ?? 'false'; |
|
|
|
if (autoLogin === 'true') { |
|
|
|
const userStorage = LocalStorage.getItem(LocalStorage.loginUserKey); |
|
|
|
const userJson = safeInvoke((text: string) => |
|
|
|
CryptoJS.AES.decrypt(text, AESKEY).toString(CryptoJS.enc.Utf8), |
|
|
|
)(userStorage); |
|
|
|
const user = safeInvoke(parseJsonText)(userJson); |
|
|
|
if (user && typeof user === 'object' && user.version === VERSION) { |
|
|
|
const { username, password } = user; |
|
|
|
form.setFieldsValue({ username: username, password: password, autoLogin: true }); |
|
|
|
} else { |
|
|
|
form.setFieldsValue({ username: '', password: '', autoLogin: true }); |
|
|
|
LocalStorage.removeItem(LocalStorage.loginUserKey); |
|
|
|
} |
|
|
|
} else { |
|
|
|
form.setFieldsValue({ username: '', password: '', autoLogin: false }); |
|
|
|
} |
|
|
|
// getCaptchaCode(); |
|
|
|
// const autoLogin = LocalStorage.getItem(LocalStorage.rememberPasswordKey) ?? 'false'; |
|
|
|
// if (autoLogin === 'true') { |
|
|
|
// const userStorage = LocalStorage.getItem(LocalStorage.loginUserKey); |
|
|
|
// const userJson = safeInvoke((text: string) => |
|
|
|
// CryptoJS.AES.decrypt(text, AESKEY).toString(CryptoJS.enc.Utf8), |
|
|
|
// )(userStorage); |
|
|
|
// const user = safeInvoke(parseJsonText)(userJson); |
|
|
|
// if (user && typeof user === 'object' && user.version === VERSION) { |
|
|
|
// const { username, password } = user; |
|
|
|
// form.setFieldsValue({ username: username, password: password, autoLogin: true }); |
|
|
|
// } else { |
|
|
|
// form.setFieldsValue({ username: '', password: '', autoLogin: true }); |
|
|
|
// LocalStorage.removeItem(LocalStorage.loginUserKey); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// form.setFieldsValue({ username: '', password: '', autoLogin: false }); |
|
|
|
// } |
|
|
|
getClientInfo(); |
|
|
|
}, []); |
|
|
|
const getClientInfo = async () => { |
|
|
|
const [res] = await to(getClientInfoReq()); |
|
|
|
if (res && res.data) { |
|
|
|
const clientInfo = res.data; |
|
|
|
SessionStorage.setItem(SessionStorage.clientInfoKey, clientInfo, true); |
|
|
|
gotoOAuth2(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const getCaptchaCode = async () => { |
|
|
|
const [res] = await to(getCaptchaImg()); |
|
|
|
if (res) { |
|
|
|
@@ -71,6 +82,12 @@ const Login = () => { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const handleSubmit2 = async (values: API.LoginParams) => { |
|
|
|
const url = |
|
|
|
'http://172.20.32.106:8080/oauth/authorize?client_id=ci4s&response_type=code&grant_type=authorization_code'; |
|
|
|
window.location.href = url; |
|
|
|
}; |
|
|
|
|
|
|
|
// 登录 |
|
|
|
const handleSubmit = async (values: API.LoginParams) => { |
|
|
|
const [res, error] = await to(login({ ...values, uuid })); |
|
|
|
@@ -109,113 +126,115 @@ const Login = () => { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className={styles['user-login']}> |
|
|
|
<div className={styles['user-login__left']}> |
|
|
|
<div className={styles['user-login__left__top']}> |
|
|
|
<img |
|
|
|
src={require('@/assets/img/logo.png')} |
|
|
|
style={{ width: '32px', marginRight: '12px' }} |
|
|
|
draggable={false} |
|
|
|
alt="" |
|
|
|
/> |
|
|
|
智能材料科研平台 |
|
|
|
</div> |
|
|
|
<div className={styles['user-login__left__title']}> |
|
|
|
<span>智能材料科研平台</span> |
|
|
|
<img |
|
|
|
src={require('@/assets/img/login-ai-logo.png')} |
|
|
|
className={styles['user-login__left__title__img']} |
|
|
|
draggable={false} |
|
|
|
alt="" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div className={styles['user-login__left__message']}> |
|
|
|
<span>大语言模型运维 统一管理平台</span> |
|
|
|
</div> |
|
|
|
<img |
|
|
|
className={styles['user-login__left__bottom-img']} |
|
|
|
src={require('@/assets/img/login-left-image.png')} |
|
|
|
draggable={false} |
|
|
|
alt="" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div className={styles['user-login__right']}> |
|
|
|
<div> |
|
|
|
<div className={styles['user-login__right__title']}> |
|
|
|
<span style={{ color: '#111111' }}>欢迎登录</span> |
|
|
|
<span>智能材料科研平台</span> |
|
|
|
</div> |
|
|
|
<div className={styles['user-login__right__content']}> |
|
|
|
<div className={styles['user-login__right__content__title']}>账号登录</div> |
|
|
|
<div className={styles['user-login__right__content__form']}> |
|
|
|
<Form |
|
|
|
labelCol={{ span: 0 }} |
|
|
|
wrapperCol={{ span: 24 }} |
|
|
|
initialValues={{ autoLogin: true }} |
|
|
|
onFinish={handleSubmit} |
|
|
|
autoComplete="off" |
|
|
|
form={form} |
|
|
|
> |
|
|
|
<Form.Item name="username" rules={[{ required: true, message: '请输入用户名' }]}> |
|
|
|
<Input |
|
|
|
placeholder="请输入用户名" |
|
|
|
prefix={<LoginInputPrefix icon={require('@/assets/img/login-user.png')} />} |
|
|
|
allowClear |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item name="password" rules={[{ required: true, message: '请输入密码' }]}> |
|
|
|
<Input.Password |
|
|
|
placeholder="请输入密码" |
|
|
|
prefix={<LoginInputPrefix icon={require('@/assets/img/login-password.png')} />} |
|
|
|
allowClear |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Flex align="start" style={{ height: '98px' }}> |
|
|
|
<div style={{ flex: 1 }}> |
|
|
|
<Form.Item name="code" rules={[{ required: true, message: '请输入验证码' }]}> |
|
|
|
<Input |
|
|
|
placeholder="请输入验证码" |
|
|
|
prefix={ |
|
|
|
<LoginInputPrefix icon={require('@/assets/img/login-captcha.png')} /> |
|
|
|
} |
|
|
|
ref={captchaInputRef} |
|
|
|
allowClear |
|
|
|
/> |
|
|
|
</Form.Item> |
|
|
|
</div> |
|
|
|
<Image |
|
|
|
className={styles['user-login__right__content__form__captcha']} |
|
|
|
src={captchaCode} |
|
|
|
alt="验证码" |
|
|
|
preview={false} |
|
|
|
onClick={() => getCaptchaCode()} |
|
|
|
/> |
|
|
|
</Flex> |
|
|
|
|
|
|
|
<Form.Item |
|
|
|
name="autoLogin" |
|
|
|
valuePropName="checked" |
|
|
|
labelCol={{ span: 0 }} |
|
|
|
wrapperCol={{ span: 16 }} |
|
|
|
> |
|
|
|
<Checkbox>记住密码</Checkbox> |
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
<Form.Item labelCol={{ span: 0 }} wrapperCol={{ span: 24 }}> |
|
|
|
<Button type="primary" htmlType="submit"> |
|
|
|
登录 |
|
|
|
</Button> |
|
|
|
</Form.Item> |
|
|
|
</Form> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
return <div className={styles['user-login']}></div>; |
|
|
|
|
|
|
|
// return ( |
|
|
|
// <div className={styles['user-login']}> |
|
|
|
// <div className={styles['user-login__left']}> |
|
|
|
// <div className={styles['user-login__left__top']}> |
|
|
|
// <img |
|
|
|
// src={require('@/assets/img/logo.png')} |
|
|
|
// style={{ width: '32px', marginRight: '12px' }} |
|
|
|
// draggable={false} |
|
|
|
// alt="" |
|
|
|
// /> |
|
|
|
// 智能材料科研平台 |
|
|
|
// </div> |
|
|
|
// <div className={styles['user-login__left__title']}> |
|
|
|
// <span>智能材料科研平台</span> |
|
|
|
// <img |
|
|
|
// src={require('@/assets/img/login-ai-logo.png')} |
|
|
|
// className={styles['user-login__left__title__img']} |
|
|
|
// draggable={false} |
|
|
|
// alt="" |
|
|
|
// /> |
|
|
|
// </div> |
|
|
|
// <div className={styles['user-login__left__message']}> |
|
|
|
// <span>大语言模型运维 统一管理平台</span> |
|
|
|
// </div> |
|
|
|
// <img |
|
|
|
// className={styles['user-login__left__bottom-img']} |
|
|
|
// src={require('@/assets/img/login-left-image.png')} |
|
|
|
// draggable={false} |
|
|
|
// alt="" |
|
|
|
// /> |
|
|
|
// </div> |
|
|
|
// <div className={styles['user-login__right']}> |
|
|
|
// <div> |
|
|
|
// <div className={styles['user-login__right__title']}> |
|
|
|
// <span style={{ color: '#111111' }}>欢迎登录</span> |
|
|
|
// <span>智能材料科研平台</span> |
|
|
|
// </div> |
|
|
|
// <div className={styles['user-login__right__content']}> |
|
|
|
// <div className={styles['user-login__right__content__title']}>账号登录</div> |
|
|
|
// <div className={styles['user-login__right__content__form']}> |
|
|
|
// <Form |
|
|
|
// labelCol={{ span: 0 }} |
|
|
|
// wrapperCol={{ span: 24 }} |
|
|
|
// initialValues={{ autoLogin: true }} |
|
|
|
// onFinish={handleSubmit2} |
|
|
|
// autoComplete="off" |
|
|
|
// form={form} |
|
|
|
// > |
|
|
|
// <Form.Item name="username" rules={[{ required: false, message: '请输入用户名' }]}> |
|
|
|
// <Input |
|
|
|
// placeholder="请输入用户名" |
|
|
|
// prefix={<LoginInputPrefix icon={require('@/assets/img/login-user.png')} />} |
|
|
|
// allowClear |
|
|
|
// /> |
|
|
|
// </Form.Item> |
|
|
|
|
|
|
|
// <Form.Item name="password" rules={[{ required: false, message: '请输入密码' }]}> |
|
|
|
// <Input.Password |
|
|
|
// placeholder="请输入密码" |
|
|
|
// prefix={<LoginInputPrefix icon={require('@/assets/img/login-password.png')} />} |
|
|
|
// allowClear |
|
|
|
// /> |
|
|
|
// </Form.Item> |
|
|
|
|
|
|
|
// <Flex align="start" style={{ height: '98px' }}> |
|
|
|
// <div style={{ flex: 1 }}> |
|
|
|
// <Form.Item name="code" rules={[{ required: false, message: '请输入验证码' }]}> |
|
|
|
// <Input |
|
|
|
// placeholder="请输入验证码" |
|
|
|
// prefix={ |
|
|
|
// <LoginInputPrefix icon={require('@/assets/img/login-captcha.png')} /> |
|
|
|
// } |
|
|
|
// ref={captchaInputRef} |
|
|
|
// allowClear |
|
|
|
// /> |
|
|
|
// </Form.Item> |
|
|
|
// </div> |
|
|
|
// <Image |
|
|
|
// className={styles['user-login__right__content__form__captcha']} |
|
|
|
// src={captchaCode} |
|
|
|
// alt="验证码" |
|
|
|
// preview={false} |
|
|
|
// onClick={() => getCaptchaCode()} |
|
|
|
// /> |
|
|
|
// </Flex> |
|
|
|
|
|
|
|
// <Form.Item |
|
|
|
// name="autoLogin" |
|
|
|
// valuePropName="checked" |
|
|
|
// labelCol={{ span: 0 }} |
|
|
|
// wrapperCol={{ span: 16 }} |
|
|
|
// > |
|
|
|
// <Checkbox>记住密码</Checkbox> |
|
|
|
// </Form.Item> |
|
|
|
|
|
|
|
// <Form.Item labelCol={{ span: 0 }} wrapperCol={{ span: 24 }}> |
|
|
|
// <Button type="primary" htmlType="submit"> |
|
|
|
// 登录 |
|
|
|
// </Button> |
|
|
|
// </Form.Item> |
|
|
|
// </Form> |
|
|
|
// </div> |
|
|
|
// </div> |
|
|
|
// </div> |
|
|
|
// </div> |
|
|
|
// </div> |
|
|
|
// ); |
|
|
|
}; |
|
|
|
|
|
|
|
export default Login; |