fix: edit configuration
This commit is contained in:
parent
1d81a6588d
commit
b6988b7516
@ -511,7 +511,7 @@ const request = (function(_global) {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
[401, 403].includes(status) &&
|
[401, 403].includes(status) &&
|
||||||
['unknown user!', 'token invalid'].includes(responseJSON.message)
|
['unknown user!', 'token invalid', 'token expired!'].includes(responseJSON.message)
|
||||||
) {
|
) {
|
||||||
// 跳转至login页
|
// 跳转至login页
|
||||||
// TODO: 用 react-router 重写,改造成本比较高,这里先hack
|
// TODO: 用 react-router 重写,改造成本比较高,这里先hack
|
||||||
|
@ -1405,6 +1405,7 @@ h6 {
|
|||||||
.right-panel {
|
.right-panel {
|
||||||
width: calc(100% - 180px);
|
width: calc(100% - 180px);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
.nav-title {
|
.nav-title {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@ -35,6 +35,10 @@ class NewPermissions extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
visible: PropTypes.bool,
|
visible: PropTypes.bool,
|
||||||
|
getNamespaces: PropTypes.func,
|
||||||
|
onOk: PropTypes.func,
|
||||||
|
onCancel: PropTypes.func,
|
||||||
|
namespaces: PropTypes.array,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -31,6 +31,8 @@ class NewRole extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
visible: PropTypes.bool,
|
visible: PropTypes.bool,
|
||||||
|
onOk: PropTypes.func,
|
||||||
|
onCancel: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
check() {
|
check() {
|
||||||
|
@ -32,6 +32,9 @@ class PasswordReset extends React.Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
visible: PropTypes.bool,
|
visible: PropTypes.bool,
|
||||||
|
username: PropTypes.string,
|
||||||
|
onCancel: PropTypes.func,
|
||||||
|
onOk: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
check() {
|
check() {
|
||||||
|
@ -175,7 +175,6 @@ class ConfigEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clickTab(tabActiveKey) {
|
clickTab(tabActiveKey) {
|
||||||
console.log('tabActiveKey', tabActiveKey, tabActiveKey === 'beta');
|
|
||||||
this.setState({ tabActiveKey }, () => this.getConfig(tabActiveKey === 'beta'));
|
this.setState({ tabActiveKey }, () => this.getConfig(tabActiveKey === 'beta'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,26 +216,20 @@ class ConfigEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_publishConfig(beta = false) {
|
_publishConfig(beta = false) {
|
||||||
const { locale } = this.props;
|
|
||||||
const { betaIps, isNewConfig } = this.state;
|
const { betaIps, isNewConfig } = this.state;
|
||||||
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
||||||
if (beta) {
|
if (beta) {
|
||||||
headers.betaIps = betaIps;
|
headers.betaIps = betaIps;
|
||||||
}
|
}
|
||||||
const data = { ...this.state.form, content: this.getCodeVal() };
|
const form = { ...this.state.form, content: this.getCodeVal() };
|
||||||
|
const data = new FormData();
|
||||||
|
Object.keys(form).forEach(key => {
|
||||||
|
data.append(key, form[key]);
|
||||||
|
});
|
||||||
return request({
|
return request({
|
||||||
url: 'v1/cs/configs',
|
url: 'v1/cs/configs',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data,
|
data,
|
||||||
transformRequest: [
|
|
||||||
function(data) {
|
|
||||||
let ret = '';
|
|
||||||
for (let it in data) {
|
|
||||||
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
],
|
|
||||||
headers,
|
headers,
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res) {
|
if (res) {
|
||||||
|
@ -65,3 +65,7 @@ export const generateUrl = (url, params) => {
|
|||||||
.join('&'),
|
.join('&'),
|
||||||
].join('');
|
].join('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isPlainObject = obj => {
|
||||||
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||||
|
};
|
||||||
|
@ -2,6 +2,7 @@ import axios from 'axios';
|
|||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { Message } from '@alifd/next';
|
import { Message } from '@alifd/next';
|
||||||
import { browserHistory } from 'react-router';
|
import { browserHistory } from 'react-router';
|
||||||
|
import { isPlainObject } from './nacosutil';
|
||||||
// import { SUCCESS_RESULT_CODE } from '../constants';
|
// import { SUCCESS_RESULT_CODE } from '../constants';
|
||||||
|
|
||||||
const API_GENERAL_ERROR_MESSAGE = 'Request error, please try again later!';
|
const API_GENERAL_ERROR_MESSAGE = 'Request error, please try again later!';
|
||||||
@ -11,17 +12,18 @@ const request = () => {
|
|||||||
|
|
||||||
instance.interceptors.request.use(
|
instance.interceptors.request.use(
|
||||||
config => {
|
config => {
|
||||||
if (!config.params) {
|
const { url, params, data, method, headers } = config;
|
||||||
|
if (!params) {
|
||||||
config.params = {};
|
config.params = {};
|
||||||
}
|
}
|
||||||
if (!config.url.includes('auth/users/login')) {
|
if (!url.includes('auth/users/login')) {
|
||||||
const { accessToken = '' } = JSON.parse(localStorage.token || '{}');
|
const { accessToken = '' } = JSON.parse(localStorage.token || '{}');
|
||||||
config.params.accessToken = accessToken;
|
config.params.accessToken = accessToken;
|
||||||
config.headers = Object.assign({}, config.headers, { accessToken });
|
config.headers = Object.assign({}, headers, { accessToken });
|
||||||
}
|
}
|
||||||
if (['post', 'put'].includes(config.method)) {
|
if (data && isPlainObject(data) && ['post', 'put'].includes(method)) {
|
||||||
config.data = qs.stringify(config.data);
|
config.data = qs.stringify(data);
|
||||||
if (!config.headers) {
|
if (!headers) {
|
||||||
config.headers = {};
|
config.headers = {};
|
||||||
}
|
}
|
||||||
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
@ -51,7 +53,10 @@ const request = () => {
|
|||||||
}
|
}
|
||||||
Message.error(message);
|
Message.error(message);
|
||||||
|
|
||||||
if ([401, 403].includes(status) && ['unknown user!', 'token invalid'].includes(message)) {
|
if (
|
||||||
|
[401, 403].includes(status) &&
|
||||||
|
['unknown user!', 'token invalid', 'token expired!'].includes(message)
|
||||||
|
) {
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
const [baseUrl] = location.href.split('#');
|
const [baseUrl] = location.href.split('#');
|
||||||
location.href = `${baseUrl}#/login`;
|
location.href = `${baseUrl}#/login`;
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user