diff --git a/ui/src/components/Icon/svg.tsx b/ui/src/components/Icon/svg.tsx new file mode 100644 index 00000000..86102ee9 --- /dev/null +++ b/ui/src/components/Icon/svg.tsx @@ -0,0 +1,18 @@ +import { FC } from 'react'; + +import { base64ToSvg } from '@/utils'; + +interface IProps { + base64: string; +} +const Icon: FC = ({ base64 = '' }) => { + return base64 ? ( + + ) : null; +}; + +export default Icon; diff --git a/ui/src/components/index.ts b/ui/src/components/index.ts index 30ab0ee5..b7db43ce 100644 --- a/ui/src/components/index.ts +++ b/ui/src/components/index.ts @@ -3,6 +3,7 @@ import Editor, { EditorRef, htmlRender } from './Editor'; import Header from './Header'; import Footer from './Footer'; import Icon from './Icon'; +import SvgIcon from './Icon/svg'; import Modal from './Modal'; import TagSelector from './TagSelector'; import Unactivate from './Unactivate'; @@ -42,6 +43,7 @@ export { Header, Footer, Icon, + SvgIcon, Modal, Unactivate, UploadImg, diff --git a/ui/src/pages/Users/Login/index.tsx b/ui/src/pages/Users/Login/index.tsx index 8834888e..68f1ea59 100644 --- a/ui/src/pages/Users/Login/index.tsx +++ b/ui/src/pages/Users/Login/index.tsx @@ -11,9 +11,13 @@ import type { ImgCodeRes, FormDataType, } from '@/common/interface'; -import { Unactivate, WelcomeTitle } from '@/components'; +import { SvgIcon, Unactivate, WelcomeTitle } from '@/components'; import { PluginOauth } from '@/plugins'; -import { loggedUserInfoStore, loginSettingStore } from '@/stores'; +import { + loggedUserInfoStore, + loginSettingStore, + userCenterStore, +} from '@/stores'; import { guard, floppyNavigation, handleFormError } from '@/utils'; import { login, checkImgCode } from '@/services'; import { PicAuthCodeModal } from '@/components/Modal'; @@ -26,6 +30,10 @@ const Index: React.FC = () => { const [refresh, setRefresh] = useState(0); const { user: storeUser, update: updateUser } = loggedUserInfoStore((_) => _); const loginSetting = loginSettingStore((state) => state.login); + const ucAgent = userCenterStore().agent; + const ucLoginRedirect = + ucAgent?.enabled && ucAgent?.agent_info?.login_redirect_url; + const [formData, setFormData] = useState({ e_mail: { value: '', @@ -56,6 +64,9 @@ const Index: React.FC = () => { }; const getImgCode = () => { + if (ucLoginRedirect) { + return; + } checkImgCode({ action: 'login', }).then((res) => { @@ -169,13 +180,26 @@ const Index: React.FC = () => { usePageTags({ title: t('login', { keyPrefix: 'page_title' }), }); - if (!guard.loginAgent().ok) { - return null; - } return ( - {step === 1 && ( + {ucLoginRedirect && step === 1 && ( + + + + )} + {step === 1 && !ucLoginRedirect && (
diff --git a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx index 2085e840..2e76b206 100644 --- a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx +++ b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx @@ -5,11 +5,10 @@ import { Link } from 'react-router-dom'; import classnames from 'classnames'; -import { Avatar, Icon } from '@/components'; +import { Avatar, Icon, SvgIcon } from '@/components'; import type { UserInfoRes } from '@/common/interface'; import { getUcBranding, UcBrandingEntry } from '@/services'; import { userCenterStore } from '@/stores'; -import { base64ToSvg } from '@/utils'; interface Props { data: UserInfoRes; @@ -124,13 +123,7 @@ const Index: FC = ({ data }) => { className={classnames('d-flex', 'align-items-center', { 'me-3': i < a.length - 1, })}> - {b.icon ? ( - - ) : null} + {b.icon ? : null} {b.url ? ( {b.label} diff --git a/ui/src/plugins/PluginOauth/index.tsx b/ui/src/plugins/PluginOauth/index.tsx index 62794181..40a28785 100644 --- a/ui/src/plugins/PluginOauth/index.tsx +++ b/ui/src/plugins/PluginOauth/index.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'; import classnames from 'classnames'; import { useGetStartUseOauthConnector } from '@/services'; -import { base64ToSvg } from '@/utils'; +import { SvgIcon } from '@/components'; interface Props { className?: string; @@ -20,12 +20,7 @@ const Index: FC = ({ className }) => { {data?.map((item) => { return ( ); diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index 208de097..195c5fe7 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -158,10 +158,6 @@ const routes: RouteNode[] = [ guard: () => { const notLogged = guard.notLogged(); if (notLogged.ok) { - const la = guard.loginAgent(); - if (!la.ok) { - return la; - } return notLogged; } diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts index 991209e9..2747890b 100644 --- a/ui/src/utils/common.ts +++ b/ui/src/utils/common.ts @@ -268,9 +268,10 @@ function base64ToSvg(base64: string) { // svg add class btnSvg const parser = new DOMParser(); const doc = parser.parseFromString(svgxml, 'image/svg+xml'); + const parseError = doc.querySelector('parsererror'); const svg = doc.querySelector('svg'); let str = ''; - if (svg) { + if (svg && !parseError) { svg.classList.add('btnSvg'); svg.classList.add('me-2'); diff --git a/ui/src/utils/floppyNavigation.ts b/ui/src/utils/floppyNavigation.ts index e62447bd..415ef724 100644 --- a/ui/src/utils/floppyNavigation.ts +++ b/ui/src/utils/floppyNavigation.ts @@ -60,9 +60,17 @@ const navigate = ( if (!differentCurrent(to)) { return; } + /** + * 1. Blocking redirection of two login pages + * 2. Auto storage login redirect + */ if (to === RouteAlias.login || to === getLoginUrl()) { + if (!differentCurrent(RouteAlias.login)) { + return; + } storageLoginRedirect(); } + if (!isRoutableLink(to) && handler !== 'href' && handler !== 'replace') { handler = 'href'; }