[fix]🐛nacos login page && notice config (#10262)

This commit is contained in:
abuexclusive 2023-04-03 15:38:50 +08:00 committed by GitHub
parent 5fffde5bde
commit da6863ccc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 21 deletions

View File

@ -24,6 +24,8 @@ export const REDUX_DEVTOOLS = '__REDUX_DEVTOOLS_EXTENSION__';
export const GET_STATE = 'GET_STATE'; export const GET_STATE = 'GET_STATE';
export const GET_NOTICE = 'GET_NOTICE';
export const GET_SUBSCRIBERS = 'GET_SUBSCRIBERS'; export const GET_SUBSCRIBERS = 'GET_SUBSCRIBERS';
export const REMOVE_SUBSCRIBERS = 'REMOVE_SUBSCRIBERS'; export const REMOVE_SUBSCRIBERS = 'REMOVE_SUBSCRIBERS';
@ -40,3 +42,5 @@ export const GET_NAMESPACES = 'GET_NAMESPACES';
export const GET_CONFIGURATION = 'GET_CONFIGURATION'; export const GET_CONFIGURATION = 'GET_CONFIGURATION';
export const GLOBAL_PAGE_SIZE_LIST = [10, 20, 30, 50, 100]; export const GLOBAL_PAGE_SIZE_LIST = [10, 20, 30, 50, 100];
export const LOGINPAGE_ENABLED = 'docsite_loginpage';

View File

@ -17,6 +17,7 @@
import projectConfig from './config'; import projectConfig from './config';
import $ from 'jquery'; import $ from 'jquery';
import { Message } from '@alifd/next'; import { Message } from '@alifd/next';
import { LOGINPAGE_ENABLED } from './constants';
function goLogin() { function goLogin() {
const url = window.location.href; const url = window.location.href;
@ -493,6 +494,13 @@ const request = (function(_global) {
// 处理后置中间件 // 处理后置中间件
config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]); config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]);
const [url, paramsStr] = config.url.split('?');
const params = paramsStr ? paramsStr.split('&') : [];
const _LOGINPAGE_ENABLED = localStorage.getItem(LOGINPAGE_ENABLED);
if (_LOGINPAGE_ENABLED !== 'false') {
let token = {}; let token = {};
try { try {
token = JSON.parse(localStorage.token); token = JSON.parse(localStorage.token);
@ -501,9 +509,8 @@ const request = (function(_global) {
goLogin(); goLogin();
} }
const { accessToken = '' } = token; const { accessToken = '' } = token;
const [url, paramsStr] = config.url.split('?');
const params = paramsStr ? paramsStr.split('&') : [];
params.push(`accessToken=${accessToken}`); params.push(`accessToken=${accessToken}`);
}
return $.ajax( return $.ajax(
Object.assign({}, config, { Object.assign({}, config, {

View File

@ -53,6 +53,7 @@ import Welcome from './pages/Welcome/Welcome';
import reducers from './reducers'; import reducers from './reducers';
import { changeLanguage } from './reducers/locale'; import { changeLanguage } from './reducers/locale';
import { getState } from './reducers/base';
import './index.scss'; import './index.scss';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
@ -95,11 +96,13 @@ const MENU = [
{ path: '/permissionsManagement', component: PermissionsManagement }, { path: '/permissionsManagement', component: PermissionsManagement },
]; ];
@connect(state => ({ ...state.locale }), { changeLanguage }) @connect(state => ({ ...state.locale, ...state.base }), { changeLanguage, getState })
class App extends React.Component { class App extends React.Component {
static propTypes = { static propTypes = {
locale: PropTypes.object, locale: PropTypes.object,
changeLanguage: PropTypes.func, changeLanguage: PropTypes.func,
getState: PropTypes.func,
loginPageEnabled: PropTypes.string,
}; };
constructor(props) { constructor(props) {
@ -112,15 +115,20 @@ class App extends React.Component {
} }
componentDidMount() { componentDidMount() {
this.props.getState();
const language = localStorage.getItem(LANGUAGE_KEY); const language = localStorage.getItem(LANGUAGE_KEY);
this.props.changeLanguage(language); this.props.changeLanguage(language);
} }
get router() { get router() {
const { loginPageEnabled } = this.props;
return ( return (
<HashRouter> <HashRouter>
<Switch> <Switch>
{loginPageEnabled && loginPageEnabled === 'false' ? null : (
<Route path="/login" component={Login} /> <Route path="/login" component={Login} />
)}
{/* <Route path="/login" component={Login} /> */}
<Layout> <Layout>
{MENU.map(item => ( {MENU.map(item => (
<Route key={item.path} {...item} /> <Route key={item.path} {...item} />
@ -132,13 +140,13 @@ class App extends React.Component {
} }
render() { render() {
const { locale } = this.props; const { locale, loginPageEnabled } = this.props;
return ( return (
<Loading <Loading
className="nacos-loading" className="nacos-loading"
shape="flower" shape="flower"
tip="loading..." tip="loading..."
visible={false} visible={!loginPageEnabled}
fullScreen fullScreen
{...this.state.nacosLoading} {...this.state.nacosLoading}
> >

View File

@ -18,15 +18,15 @@ import React from 'react';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { ConfigProvider, Icon, Menu } from '@alifd/next'; import { ConfigProvider, Icon, Menu, Message } from '@alifd/next';
import Header from './Header'; import Header from './Header';
import { getState } from '../reducers/base'; import { getState, getNotice } from '../reducers/base';
import getMenuData from './menu'; import getMenuData from './menu';
const { SubMenu, Item } = Menu; const { SubMenu, Item } = Menu;
@withRouter @withRouter
@connect(state => ({ ...state.locale, ...state.base }), { getState }) @connect(state => ({ ...state.locale, ...state.base }), { getState, getNotice })
@ConfigProvider.config @ConfigProvider.config
class MainLayout extends React.Component { class MainLayout extends React.Component {
static displayName = 'MainLayout'; static displayName = 'MainLayout';
@ -38,11 +38,15 @@ class MainLayout extends React.Component {
version: PropTypes.any, version: PropTypes.any,
getState: PropTypes.func, getState: PropTypes.func,
functionMode: PropTypes.string, functionMode: PropTypes.string,
authEnabled: PropTypes.string,
children: PropTypes.object, children: PropTypes.object,
getNotice: PropTypes.func,
notice: PropTypes.string,
}; };
componentDidMount() { componentDidMount() {
this.props.getState(); this.props.getState();
this.props.getNotice();
} }
goBack() { goBack() {
@ -83,7 +87,7 @@ class MainLayout extends React.Component {
} }
render() { render() {
const { locale = {}, version, functionMode } = this.props; const { locale = {}, version, functionMode, authEnabled } = this.props;
const MenuData = getMenuData(functionMode); const MenuData = getMenuData(functionMode);
return ( return (
<section <section
@ -146,7 +150,12 @@ class MainLayout extends React.Component {
)} )}
</div> </div>
</div> </div>
<div className="right-panel next-shell-sub-main">{this.props.children}</div> <div className="right-panel next-shell-sub-main">
{authEnabled === 'false' ? (
<Message type="notice">{this.props.notice}</Message>
) : null}
{this.props.children}
</div>
</div> </div>
</section> </section>
</section> </section>

View File

@ -15,12 +15,15 @@
*/ */
import request from '../utils/request'; import request from '../utils/request';
import { GET_STATE } from '../constants'; import { GET_STATE, LOGINPAGE_ENABLED, GET_NOTICE } from '../constants';
const initialState = { const initialState = {
version: null, version: null,
standaloneMode: '', standaloneMode: '',
functionMode: '', functionMode: '',
loginPageEnabled: '',
authEnabled: '',
notice: '',
}; };
/** /**
@ -33,21 +36,47 @@ const getState = () => dispatch =>
request request
.get('v1/console/server/state') .get('v1/console/server/state')
.then(res => { .then(res => {
localStorage.setItem(LOGINPAGE_ENABLED, res.login_page_enabled);
dispatch({ dispatch({
type: GET_STATE, type: GET_STATE,
data: { data: {
version: res.version, version: res.version,
standaloneMode: res.standalone_mode, standaloneMode: res.standalone_mode,
functionMode: res.function_mode, functionMode: res.function_mode,
loginPageEnabled: res.login_page_enabled,
authEnabled: res.auth_enabled,
}, },
}); });
}) })
.catch(() => { .catch(() => {
localStorage.setItem(LOGINPAGE_ENABLED, null);
dispatch({ dispatch({
type: GET_STATE, type: GET_STATE,
data: { data: {
version: null, version: null,
functionMode: null, functionMode: null,
loginPageEnabled: null,
authEnabled: null,
},
});
});
const getNotice = () => dispatch =>
request
.get('v1/console/server/announcement')
.then(res => {
dispatch({
type: GET_NOTICE,
data: {
notice: res.data,
},
});
})
.catch(() => {
dispatch({
type: GET_NOTICE,
data: {
notice: '',
}, },
}); });
}); });
@ -56,9 +85,11 @@ export default (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case GET_STATE: case GET_STATE:
return { ...state, ...action.data }; return { ...state, ...action.data };
case GET_NOTICE:
return { ...state, ...action.data };
default: default:
return state; return state;
} }
}; };
export { getState, login }; export { getState, login, getNotice };

View File

@ -39,7 +39,7 @@ const request = () => {
if (!params) { if (!params) {
config.params = {}; config.params = {};
} }
if (!url.includes('auth/users/login')) { if (!url.includes('auth/users/login') && localStorage.token) {
let token = {}; let token = {};
try { try {
token = JSON.parse(localStorage.token); token = JSON.parse(localStorage.token);