From 73c98d35416bbbaec7af6ea5fcc40fcfab323d78 Mon Sep 17 00:00:00 2001 From: LoadChange Date: Fri, 18 Jan 2019 23:46:41 +0800 Subject: [PATCH] fix: closes #640, #648 --- .../console-fe/public/css/bootstrap.css | 3 +- .../static/console-fe/public/index.html | 1 + .../resources/static/console-fe/src/index.js | 1 - .../static/console-fe/src/layouts/Header.js | 3 +- .../console-fe/src/layouts/MainLayout.js | 10 +++- .../static/console-fe/src/locales/en-US.js | 3 ++ .../static/console-fe/src/locales/zh-CN.js | 3 ++ .../NewConfig/NewConfig.js | 5 +- .../console-fe/src/pages/Login/Login.jsx | 13 +++-- .../ServiceDetail/EditServiceDialog.js | 51 +++++++++++++++++-- 10 files changed, 76 insertions(+), 17 deletions(-) diff --git a/console/src/main/resources/static/console-fe/public/css/bootstrap.css b/console/src/main/resources/static/console-fe/public/css/bootstrap.css index 3bcd6346c..ce3ef2335 100644 --- a/console/src/main/resources/static/console-fe/public/css/bootstrap.css +++ b/console/src/main/resources/static/console-fe/public/css/bootstrap.css @@ -323,7 +323,6 @@ select, textarea { font-family: inherit; font-size: inherit; - line-height: inherit; } a { @@ -7122,4 +7121,4 @@ td.visible-print { td.hidden-print { display: none !important; } -} \ No newline at end of file +} diff --git a/console/src/main/resources/static/console-fe/public/index.html b/console/src/main/resources/static/console-fe/public/index.html index bbad4d378..5d4dbe01b 100644 --- a/console/src/main/resources/static/console-fe/public/index.html +++ b/console/src/main/resources/static/console-fe/public/index.html @@ -20,6 +20,7 @@ Nacos + diff --git a/console/src/main/resources/static/console-fe/src/index.js b/console/src/main/resources/static/console-fe/src/index.js index a4fd3c65e..2fd1f9988 100644 --- a/console/src/main/resources/static/console-fe/src/index.js +++ b/console/src/main/resources/static/console-fe/src/index.js @@ -114,7 +114,6 @@ class App extends React.Component { - {MENU.map(item => ( diff --git a/console/src/main/resources/static/console-fe/src/layouts/Header.js b/console/src/main/resources/static/console-fe/src/layouts/Header.js index 17ac95ec5..371d5f866 100644 --- a/console/src/main/resources/static/console-fe/src/layouts/Header.js +++ b/console/src/main/resources/static/console-fe/src/layouts/Header.js @@ -32,6 +32,8 @@ class Header extends React.Component { static propTypes = { locale: PropTypes.object, + history: PropTypes.object, + location: PropTypes.object, language: PropTypes.string, changeLanguage: PropTypes.func, }; @@ -53,7 +55,6 @@ class Header extends React.Component { const base64Url = token.split('.')[1]; const base64 = base64Url.replace('-', '+').replace('_', '/'); const parsedToken = JSON.parse(window.atob(base64)); - console.log(parsedToken); return parsedToken.sub; } return ''; diff --git a/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js b/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js index e2b88c34c..4209056b4 100644 --- a/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js +++ b/console/src/main/resources/static/console-fe/src/layouts/MainLayout.js @@ -31,6 +31,7 @@ class MainLayout extends React.Component { static propTypes = { navList: PropTypes.array, history: PropTypes.object, + location: PropTypes.object, locale: PropTypes.object, children: PropTypes.any, }; @@ -74,6 +75,11 @@ class MainLayout extends React.Component { iconClass.className = tmpClassName; } + /** + * Click the back button + * TODO: this.props.history.goBack(); ??? + * @param url + */ nacosGoBack(url) { const params = window.location.hash.split('?')[1]; const urlArr = params.split('&') || []; @@ -93,6 +99,9 @@ class MainLayout extends React.Component { } } } + if (localStorage.getItem('namespace')) { + queryParams.push(`namespace=${localStorage.getItem('namespace')}`); + } this.props.history.push(`/${url}?${queryParams.join('&')}`); } @@ -401,7 +410,6 @@ class MainLayout extends React.Component { {nacosVersion} )} -
{this.state.addonBefore}
diff --git a/console/src/main/resources/static/console-fe/src/pages/Login/Login.jsx b/console/src/main/resources/static/console-fe/src/pages/Login/Login.jsx index 53fdfa3a4..307a558ec 100644 --- a/console/src/main/resources/static/console-fe/src/pages/Login/Login.jsx +++ b/console/src/main/resources/static/console-fe/src/pages/Login/Login.jsx @@ -5,6 +5,7 @@ import { withRouter } from 'react-router-dom'; import './index.scss'; import Header from '../../layouts/Header'; import { request } from '../../globalLib'; +import PropTypes from 'prop-types'; const FormItem = Form.Item; @@ -13,6 +14,11 @@ const FormItem = Form.Item; class Login extends React.Component { static displayName = 'Login'; + static propTypes = { + locale: PropTypes.object, + history: PropTypes.object, + }; + constructor(props) { super(props); this.field = new Field(this); @@ -28,15 +34,14 @@ class Login extends React.Component { type: 'post', url: 'v1/auth/login', data: values, - success: res => { - if (res.code === 200) { - const data = res.data; + success: ({ code, data }) => { + if (code === 200) { // TODO: 封装一个方法存储、读取token localStorage.setItem('token', data); // TODO: 使用react router this.props.history.push('/'); } - if (res.code === 401) { + if (code === 401) { Message.error({ content: locale.invalidUsernameOrPassword, }); diff --git a/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js b/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js index 2b9f6e785..195a9e507 100644 --- a/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js +++ b/console/src/main/resources/static/console-fe/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js @@ -33,6 +33,7 @@ class EditServiceDialog extends React.Component { isCreate: false, editService: {}, editServiceDialogVisible: false, + errors: { name: {}, protectThreshold: {}, healthCheckMode: {} }, }; this.show = this.show.bind(this); } @@ -52,10 +53,29 @@ class EditServiceDialog extends React.Component { this.setState({ editServiceDialogVisible: false }); } + validator(field) { + const { locale = {} } = this.props; + const errors = Object.assign({}, this.state.errors); + const helpMap = { + name: locale.serviceNameRequired, + protectThreshold: locale.protectThresholdRequired, + healthCheckMode: locale.healthCheckModeRequired, + }; + for (const key in field) { + if (!field[key]) { + errors[key] = { validateState: 'error', help: helpMap[key] }; + this.setState({ errors }); + return false; + } + } + return true; + } + onConfirm() { const { isCreate } = this.state; const editService = Object.assign({}, this.state.editService); const { name, protectThreshold, healthCheckMode, metadataText, selector } = editService; + if (!this.validator({ name, protectThreshold, healthCheckMode })) return; request({ method: isCreate ? 'POST' : 'PUT', url: 'v1/ns/service', @@ -86,7 +106,15 @@ class EditServiceDialog extends React.Component { } onChangeCluster(changeVal) { + const resetKey = ['name', 'protectThreshold', 'healthCheckMode']; const { editService = {} } = this.state; + const errors = Object.assign({}, this.state.errors); + resetKey.forEach(key => { + if (changeVal[key]) { + errors[key] = {}; + this.setState({ errors }); + } + }); this.setState({ editService: Object.assign({}, editService, changeVal), }); @@ -99,7 +127,7 @@ class EditServiceDialog extends React.Component { render() { const { locale = {} } = this.props; - const { isCreate, editService, editServiceDialogVisible } = this.state; + const { isCreate, editService, editServiceDialogVisible, errors } = this.state; const { name, protectThreshold, @@ -118,20 +146,35 @@ class EditServiceDialog extends React.Component { onClose={() => this.hide()} >
- + {!isCreate ? (

{name}

) : ( this.onChangeCluster({ name })} /> )}
- + this.onChangeCluster({ protectThreshold })} /> - +