Skip to content

Commit

Permalink
merge: merge 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
XieYongHong committed May 4, 2023
2 parents 90ee84c + 2db33e3 commit 7b3c703
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
77 changes: 57 additions & 20 deletions src/pages/oauth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import { catchError, filter, mergeMap } from 'rxjs/operators';
import Service from '@/pages/user/Login/service';
import * as ICONS from '@ant-design/icons';
import React from 'react';
import Token from "@/utils/token";

const Oauth = () => {
const intl = useIntl();
const logo = require('/public/logo.svg');
const bindPage = require('/public/images/bind/bindPage.png');
const headerImg = require('/public/logo.png');

const [isLogin, setIsLogin] = useState<boolean>(true);
const [captcha, setCaptcha] = useState<{ key?: string; base64?: string }>({});
const [userName, setUerName] = useState<string>('');
const [appName, setAppName] = useState<string>('');
const [params, setParams] = useState<any>({});
const [internal, setLinternal] = useState<any>();
const [headerImg, setHeaderImg] = useState(require('/public/logo.png'))
const [logo, setLogo] = useState('/public/logo.svg')
const [title, setTitle] = useState()
const loadingRef = useRef<boolean>(true);

const loginRef = useRef<Partial<LoginParam>>({});
Expand Down Expand Up @@ -80,6 +82,7 @@ const Oauth = () => {
properties: {
username: {
type: 'string',
title: '用户名',
'x-decorator': 'FormItem',
'x-validator': { required: true, message: '请输入用户名!' },
'x-component': 'Input',
Expand All @@ -93,6 +96,7 @@ const Oauth = () => {
},
password: {
type: 'string',
title: '密码',
'x-validator': { required: true, message: '请输入密码!' },
'x-decorator': 'FormItem',
'x-component': 'Password',
Expand All @@ -106,6 +110,7 @@ const Oauth = () => {
},
verifyCode: {
type: 'string',
title: '验证码',
'x-visible': !!captcha.key,
'x-decorator': 'FormItem',
'x-component': 'Input',
Expand All @@ -128,23 +133,35 @@ const Oauth = () => {
};

const getLoginUser = async (data?: any) => {
const res = await Service.queryCurrent();
if (res && res.status === 200) {
setUerName(res.result.user.name);
setIsLogin(true);
initApplication(data.client_id || params.client_id);
if (data.internal === 'true' || internal === 'true') {
goOAuth2(data);
const token = localStorage.getItem('X-Access-Token')
if (token) {
const res = await Service.queryCurrent();
if (res && res.status === 200) {
setUerName(res.result.user.name);
setIsLogin(true);
initApplication(data?.client_id || params.client_id);
setTimeout(() => {
loadingRef.current = false;
});
if (data?.internal === 'true' || internal === 'true') {
goOAuth2(data);
}
} else if (res.status === 401) {
setIsLogin(false);
getCode();
initApplication(data?.client_id || params.client_id);
setTimeout(() => {
loadingRef.current = false;
});
} else {
setIsLogin(false);
setTimeout(() => {
loadingRef.current = false;
});
}
} else if (res.status === 401) {
setIsLogin(false);
getCode();
initApplication(data.client_id || params.client_id);
setTimeout(() => {
loadingRef.current = false;
});
} else {
setIsLogin(false);
setIsLogin(false)
initApplication(data?.client_id || params.client_id);
setTimeout(() => {
loadingRef.current = false;
});
Expand Down Expand Up @@ -181,8 +198,25 @@ const Oauth = () => {
}
};

const getSettingDetail = () => {
Service.settingDetail('front').then((res: any) => {
if (res.status === 200) {
const ico: any = document.querySelector('link[rel="icon"]');
ico.href = res.result.ico;
setHeaderImg(res.result.logo)
setLogo(res.result.logo)
setTitle(res.result.title || 'JetLinks')
if (res.result.title) {
document.title = `OAuth授权-${res.result.title}`;
} else {
document.title = 'OAuth授权';
}
}
});
}

useEffect(() => {
document.title = 'OAuth授权-jetlinks';
getSettingDetail()
getCode();
}, []);

Expand Down Expand Up @@ -236,8 +270,9 @@ const Oauth = () => {
<div className="oauth-content-header">
<img src={headerImg} />
</div>
<h2>授权登录</h2>
<div className="oauth-content-login">
<Form form={loginForm} layout="horizontal" size="large" onAutoSubmit={doLogin}>
<Form form={loginForm} layout={"vertical"} size="large" onAutoSubmit={doLogin}>
<SchemaField schema={schema} />
<Submit block size="large">
{intl.formatMessage({
Expand Down Expand Up @@ -267,7 +302,8 @@ const Oauth = () => {
>
<div className="oauth-header">
<div className="oauth-header-left">
<img src={logo} />
<img style={{ height: 56 }} src={logo} />
<span style={{ fontSize: 22, fontWeight: 600 }}>{ title }</span>
</div>
{/* <div className="oauth-header-right">
<a style={{ color: 'rgb(0 0 0 / 70%)' }}>{userName || '-'}</a>
Expand All @@ -286,6 +322,7 @@ const Oauth = () => {
<div className="oauth-content-header">
<img src={headerImg} />
</div>
<h2>授权登录</h2>
<div className="oauth-content-content">
<div className="oauth-content-content-text">
{`您正在授权登录,${appName || '-'}将获得以下权限:`}
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16589,12 +16589,7 @@ reserved-words@^0.1.2:
resolved "https://registry.yarnpkg.com/reserved-words/-/reserved-words-0.1.2.tgz#00a0940f98cd501aeaaac316411d9adc52b31ab1"
integrity sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE=

resize-observer-polyfill@^1.5.0:
version "1.5.1"
resolved "https://registry.npmmirror.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==

resize-observer-polyfill@^1.5.1:
resize-observer-polyfill@^1.5.0, resize-observer-polyfill@^1.5.1:
version "1.5.1"
resolved "https://registry.npmmirror.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
Expand Down

0 comments on commit 7b3c703

Please sign in to comment.