fix: edit configuration

This commit is contained in:
LoadChange 2020-02-06 11:08:28 +08:00 committed by Asa
parent 1d81a6588d
commit b6988b7516
10 changed files with 37 additions and 25 deletions

View File

@ -511,7 +511,7 @@ const request = (function(_global) {
}
if (
[401, 403].includes(status) &&
['unknown user!', 'token invalid'].includes(responseJSON.message)
['unknown user!', 'token invalid', 'token expired!'].includes(responseJSON.message)
) {
// 跳转至login页
// TODO: react-router 重写改造成本比较高这里先hack

View File

@ -1405,6 +1405,7 @@ h6 {
.right-panel {
width: calc(100% - 180px);
padding: 10px;
overflow: scroll;
}
.nav-title {
margin: 0;

View File

@ -35,6 +35,10 @@ class NewPermissions extends React.Component {
static propTypes = {
locale: PropTypes.object,
visible: PropTypes.bool,
getNamespaces: PropTypes.func,
onOk: PropTypes.func,
onCancel: PropTypes.func,
namespaces: PropTypes.array,
};
componentDidMount() {

View File

@ -31,6 +31,8 @@ class NewRole extends React.Component {
static propTypes = {
locale: PropTypes.object,
visible: PropTypes.bool,
onOk: PropTypes.func,
onCancel: PropTypes.func,
};
check() {

View File

@ -32,6 +32,9 @@ class PasswordReset extends React.Component {
static propTypes = {
locale: PropTypes.object,
visible: PropTypes.bool,
username: PropTypes.string,
onCancel: PropTypes.func,
onOk: PropTypes.func,
};
check() {

View File

@ -175,7 +175,6 @@ class ConfigEditor extends React.Component {
}
clickTab(tabActiveKey) {
console.log('tabActiveKey', tabActiveKey, tabActiveKey === 'beta');
this.setState({ tabActiveKey }, () => this.getConfig(tabActiveKey === 'beta'));
}
@ -217,26 +216,20 @@ class ConfigEditor extends React.Component {
}
_publishConfig(beta = false) {
const { locale } = this.props;
const { betaIps, isNewConfig } = this.state;
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
if (beta) {
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({
url: 'v1/cs/configs',
method: 'post',
data,
transformRequest: [
function(data) {
let ret = '';
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
}
return ret;
},
],
headers,
}).then(res => {
if (res) {

View File

@ -65,3 +65,7 @@ export const generateUrl = (url, params) => {
.join('&'),
].join('');
};
export const isPlainObject = obj => {
return Object.prototype.toString.call(obj) === '[object Object]';
};

View File

@ -2,6 +2,7 @@ import axios from 'axios';
import qs from 'qs';
import { Message } from '@alifd/next';
import { browserHistory } from 'react-router';
import { isPlainObject } from './nacosutil';
// import { SUCCESS_RESULT_CODE } from '../constants';
const API_GENERAL_ERROR_MESSAGE = 'Request error, please try again later!';
@ -11,17 +12,18 @@ const request = () => {
instance.interceptors.request.use(
config => {
if (!config.params) {
const { url, params, data, method, headers } = config;
if (!params) {
config.params = {};
}
if (!config.url.includes('auth/users/login')) {
if (!url.includes('auth/users/login')) {
const { accessToken = '' } = JSON.parse(localStorage.token || '{}');
config.params.accessToken = accessToken;
config.headers = Object.assign({}, config.headers, { accessToken });
config.headers = Object.assign({}, headers, { accessToken });
}
if (['post', 'put'].includes(config.method)) {
config.data = qs.stringify(config.data);
if (!config.headers) {
if (data && isPlainObject(data) && ['post', 'put'].includes(method)) {
config.data = qs.stringify(data);
if (!headers) {
config.headers = {};
}
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
@ -51,7 +53,10 @@ const request = () => {
}
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');
const [baseUrl] = location.href.split('#');
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