Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](ui) fix database cannot be chosen bug #32091

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 66 additions & 42 deletions ui/src/pages/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* @file test cron
* @author lpx
* @since 2020/08/19
*/
import React, {useState} from 'react';
import {Layout, Menu, Dropdown, notification, Button} from 'antd';
import { CaretDownOutlined, LogoutOutlined} from '@ant-design/icons';
import {renderRoutes} from 'react-router-config';
import {useHistory} from 'react-router-dom';
import {useTranslation} from 'react-i18next';
import React, { useState } from 'react';
import { Layout, Menu, Dropdown, notification, Button } from 'antd';
import { CaretDownOutlined, LogoutOutlined } from '@ant-design/icons';
import { renderRoutes } from 'react-router-config';
import { useHistory } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import routes from 'Src/router';
import {logOut} from 'Src/api/api';
import { logOut } from 'Src/api/api';
import './index.css';
import styles from './index.less';
const {Header, Content, Footer} = Layout;
const { Header, Content, Footer } = Layout;
function Layouts(props: any) {
let { t } = useTranslation();
const [route, setRoute] = useState(props.route.routes);
Expand All @@ -48,7 +48,7 @@ function Layouts(props: any) {
if (location.pathname === e.key) {
location.reload();
}
if(location.pathname.includes('Playground')){
if (location.pathname.includes('Playground')) {
history.push(e.key);
location.reload();
}
Expand All @@ -59,52 +59,74 @@ function Layouts(props: any) {
}
function clearAllCookie() {
var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
if(keys) {
for(var i = keys.length; i--;)
document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
if (keys) {
for (var i = keys.length; i--; )
document.cookie =
keys[i] + '=0;expires=' + new Date(0).toUTCString();
}
}
function onLogout(){
logOut().then((res)=>{
localStorage.setItem('username','');
function onLogout() {
logOut().then((res) => {
localStorage.removeItem('username');
clearAllCookie();
notification.success({message: t('exitSuccessfully')})
notification.success({ message: t('exitSuccessfully') });
history.push('/login');
})
});
}
function changeLanguage(){
if (localStorage.getItem('I18N_LANGUAGE') === 'zh-CN'){
localStorage.setItem('I18N_LANGUAGE','en');
location.reload()
function changeLanguage() {
if (localStorage.getItem('I18N_LANGUAGE') === 'zh-CN') {
localStorage.setItem('I18N_LANGUAGE', 'en');
location.reload();
} else {
localStorage.setItem('I18N_LANGUAGE','zh-CN');
location.reload()
localStorage.setItem('I18N_LANGUAGE', 'zh-CN');
location.reload();
}
}
const menu = (
<Menu>
<Menu.Item onClick={onLogout}>
<LogoutOutlined style={{marginRight: 8}}/>
<LogoutOutlined style={{ marginRight: 8 }} />
{t('signOut')}
</Menu.Item>
</Menu>
);
return (
<Layout>
<Header style={{position: 'fixed', zIndex: 99, width: '100%'}}>
<div className={styles['logo']} onClick={()=>{history.replace('/home');setCurrent('')}}></div>
<span className='userSet'>
<Button style={{'color':'#000'}} type="text" size='small' onClick={changeLanguage}>{localStorage.getItem('I18N_LANGUAGE') === 'zh-CN' ? 'English' : '中文'}</Button>
<Header style={{ position: 'fixed', zIndex: 99, width: '100%' }}>
<div
className={styles['logo']}
onClick={() => {
history.replace('/home');
setCurrent('');
}}
></div>
<span className="userSet">
<Button
style={{ color: '#000' }}
type="text"
size="small"
onClick={changeLanguage}
>
{localStorage.getItem('I18N_LANGUAGE') === 'zh-CN'
? 'English'
: '中文'}
</Button>
<Dropdown overlay={menu}>
<span className="ant-dropdown-link">
{/* <img alt="" className='avatar' src=''/> */}
{localStorage.getItem('username')} <CaretDownOutlined/>
{localStorage.getItem('username')}{' '}
<CaretDownOutlined />
</span>
</Dropdown>
</span>
<Menu theme="light" onClick={handleClick} selectedKeys={[current]} mode="horizontal">
{routes?.routes[1]?.routes?.map(item => {
if (item.title !== 'Login'&&item.title !== 'Home') {
<Menu
theme="light"
onClick={handleClick}
selectedKeys={[current]}
mode="horizontal"
>
{routes?.routes[1]?.routes?.map((item) => {
if (item.title !== 'Login' && item.title !== 'Home') {
return (
<Menu.Item key={item.path}>
{item.title}
Expand All @@ -115,34 +137,36 @@ function Layouts(props: any) {
</Menu>
</Header>

<Content className="site-layout" style={{marginTop: 64}}>
<div className="site-layout-background" style={{minHeight: 380}}>
<Content className="site-layout" style={{ marginTop: 64 }}>
<div
className="site-layout-background"
style={{ minHeight: 380 }}
>
{renderRoutes(route)}
</div>
</Content>

{/* <Footer style={{textAlign: 'center'}}>xxx</Footer> */}
</Layout>

);
}

export default Layouts;/**
export default Layouts;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

Loading
Loading