From 897bd9ce1f134cf4bb6e092a1c6d4f4a330e7d6f Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Sat, 14 Dec 2024 10:26:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A0=87=E6=B3=A8url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/src/components/IFramePage/index.tsx | 4 +- react-ui/src/pages/User/Login/index.tsx | 219 +------------------ 2 files changed, 4 insertions(+), 219 deletions(-) diff --git a/react-ui/src/components/IFramePage/index.tsx b/react-ui/src/components/IFramePage/index.tsx index fab32ab2..75eecd43 100644 --- a/react-ui/src/components/IFramePage/index.tsx +++ b/react-ui/src/components/IFramePage/index.tsx @@ -1,6 +1,6 @@ import FullScreenFrame from '@/components/FullScreenFrame'; import KFSpin from '@/components/KFSpin'; -import { getLabelStudioUrl } from '@/services/developmentEnvironment'; +// import { getLabelStudioUrl } from '@/services/developmentEnvironment'; import { to } from '@/utils/promise'; import SessionStorage from '@/utils/sessionStorage'; import classNames from 'classnames'; @@ -18,7 +18,7 @@ export enum IframePageType { const getRequestAPI = (type: IframePageType): (() => Promise) => { switch (type) { case IframePageType.DatasetAnnotation: - return getLabelStudioUrl; + return () => Promise.resolve({ code: 200, data: 'http://172.20.32.83:8080/oauth/login' }); //getLabelStudioUrl; case IframePageType.AppDevelopment: return () => Promise.resolve({ code: 200, data: 'http://172.20.32.185:30080/' }); case IframePageType.DevEnv: diff --git a/react-ui/src/pages/User/Login/index.tsx b/react-ui/src/pages/User/Login/index.tsx index 86d56ff6..e2df0693 100644 --- a/react-ui/src/pages/User/Login/index.tsx +++ b/react-ui/src/pages/User/Login/index.tsx @@ -1,57 +1,15 @@ -import { clearSessionToken, setSessionToken } from '@/access'; import { getClientInfoReq } from '@/services/auth'; -import { getCaptchaImg, login } from '@/services/system/auth'; -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 { Form, message, type InputRef } from 'antd'; -import CryptoJS from 'crypto-js'; -import { useEffect, useRef, useState } from 'react'; -import { flushSync } from 'react-dom'; +import { useEffect } from 'react'; import styles from './login.less'; -const VERSION = 1; -const AESKEY = 'OPENSOURCETECHNOLOGYCENTER'; - -const LoginInputPrefix = ({ icon }: { icon: string }) => { - return ( -
- -
-
- ); -}; - const Login = () => { - const { initialState, setInitialState } = useModel('@@initialState'); - const [captchaCode, setCaptchaCode] = useState(''); - const [uuid, setUuid] = useState(''); - const [form] = Form.useForm(); - const captchaInputRef = useRef(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 }); - // } getClientInfo(); }, []); + const getClientInfo = async () => { const [res] = await to(getClientInfoReq()); if (res && res.data) { @@ -61,180 +19,7 @@ const Login = () => { } }; - const getCaptchaCode = async () => { - const [res] = await to(getCaptchaImg()); - if (res) { - const imgdata = `data:image/png;base64,${res.img}`; - setCaptchaCode(imgdata); - setUuid(res.uuid); - } - }; - - const fetchUserInfo = async () => { - const userInfo = await initialState?.fetchUserInfo?.(); - if (userInfo) { - flushSync(() => { - setInitialState((s) => ({ - ...s, - currentUser: userInfo, - })); - }); - } - }; - - 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 })); - if (res && res.data) { - const current = new Date(); - const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60); - const { access_token } = res.data; - setSessionToken(access_token, access_token, expireTime); - message.success('登录成功!'); - - LocalStorage.setItem(LocalStorage.rememberPasswordKey, values.autoLogin ? 'true' : 'false'); - if (values.autoLogin) { - const user = { - username: values.username, - password: values.password, - version: VERSION, - }; - const encrypted = CryptoJS.AES.encrypt(JSON.stringify(user), AESKEY).toString(); - LocalStorage.setItem(LocalStorage.loginUserKey, encrypted); - } else { - LocalStorage.removeItem(LocalStorage.loginUserKey); - } - - await fetchUserInfo(); - const urlParams = new URL(window.location.href).searchParams; - history.push(urlParams.get('redirect') || '/'); - } else { - if (error?.data?.code === 500 && error?.data?.msg === '验证码错误') { - captchaInputRef.current?.focus({ - cursor: 'all', - }); - } - - clearSessionToken(); - getCaptchaCode(); - } - }; - return
; - - // return ( - //
- //
- //
- // - // 智能材料科研平台 - //
- //
- // 智能材料科研平台 - // - //
- //
- // 大语言模型运维 统一管理平台 - //
- // - //
- //
- //
- //
- // 欢迎登录 - // 智能材料科研平台 - //
- //
- //
账号登录
- //
- //
- // - // } - // allowClear - // /> - // - - // - // } - // allowClear - // /> - // - - // - //
- // - // - // } - // ref={captchaInputRef} - // allowClear - // /> - // - //
- // 验证码 getCaptchaCode()} - // /> - //
- - // - // 记住密码 - // - - // - // - // - //
- //
- //
- //
- //
- //
- // ); }; export default Login;