fix: loading error
This commit is contained in:
parent
8ba9313493
commit
df9b939071
@ -13,6 +13,7 @@
|
||||
|
||||
import projectConfig from './config';
|
||||
import $ from 'jquery';
|
||||
import { Message } from '@alifd/next';
|
||||
|
||||
const global = window;
|
||||
|
||||
@ -445,7 +446,7 @@ const request = (function(_global) {
|
||||
} catch (e) {}
|
||||
// 设置自动loading效果
|
||||
if (serviceObj.autoLoading) {
|
||||
nacosUtils.openLoading();
|
||||
// nacosUtils.openLoading();
|
||||
const prevComplete = config.complete;
|
||||
config.complete = function() {
|
||||
nacosUtils.closeLoading();
|
||||
@ -505,7 +506,13 @@ const request = (function(_global) {
|
||||
error => {
|
||||
// 处理403 forbidden
|
||||
const { status, responseJSON = {} } = error || {};
|
||||
if ([401, 403].includes(status) && responseJSON.message === 'token invalid!') {
|
||||
if (responseJSON.message) {
|
||||
Message.error(responseJSON.message);
|
||||
}
|
||||
if (
|
||||
[401, 403].includes(status) &&
|
||||
['unknown user!', 'token invalid'].includes(responseJSON.message)
|
||||
) {
|
||||
// 跳转至login页
|
||||
// TODO: 用 react-router 重写,改造成本比较高,这里先hack
|
||||
const url = window.location.href;
|
||||
@ -517,6 +524,7 @@ const request = (function(_global) {
|
||||
const base_url = url.split('#')[0];
|
||||
window.location = `${base_url}#/login`;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -536,9 +544,9 @@ export {
|
||||
nacosEvent,
|
||||
nacosUtils,
|
||||
aliwareGetCookieByKeyName,
|
||||
removeParams,
|
||||
getParams,
|
||||
setParam,
|
||||
setParams,
|
||||
removeParams,
|
||||
request,
|
||||
};
|
||||
|
@ -286,9 +286,6 @@ class ConfigurationManagement extends React.Component {
|
||||
}&config_tags=${this.state.config_tags || ''}&pageNo=${pageNo}&pageSize=${
|
||||
this.state.pageSize
|
||||
}`,
|
||||
beforeSend() {
|
||||
self.openLoading();
|
||||
},
|
||||
success(data) {
|
||||
if (data != null) {
|
||||
self.setState({
|
||||
@ -314,9 +311,6 @@ class ConfigurationManagement extends React.Component {
|
||||
currentPage: 0,
|
||||
});
|
||||
},
|
||||
complete() {
|
||||
self.closeLoading();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -335,15 +335,15 @@ class NewConfig extends React.Component {
|
||||
}
|
||||
self.successDialog.current.getInstance().openDialog(_payload);
|
||||
},
|
||||
complete() {
|
||||
self.closeLoading();
|
||||
complete: () => {
|
||||
this.closeLoading();
|
||||
},
|
||||
error(res) {
|
||||
error: res => {
|
||||
this.closeLoading();
|
||||
Dialog.alert({
|
||||
language: aliwareIntl.currentLanguageCode || 'zh-cn',
|
||||
content: locale.publishFailed,
|
||||
});
|
||||
self.closeLoading();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -93,7 +93,6 @@ class ServiceList extends React.Component {
|
||||
];
|
||||
request({
|
||||
url: `v1/ns/catalog/services?${parameter.join('&')}`,
|
||||
beforeSend: () => this.openLoading(),
|
||||
success: ({ count = 0, serviceList = [] } = {}) => {
|
||||
this.setState({
|
||||
dataSource: serviceList,
|
||||
@ -106,7 +105,6 @@ class ServiceList extends React.Component {
|
||||
total: 0,
|
||||
currentPage: 0,
|
||||
}),
|
||||
complete: () => this.closeLoading(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
function getValue(key) {
|
||||
if (!document.cookie) return null;
|
||||
const list = document.cookie.split(';') || [];
|
||||
for (const item of list) {
|
||||
const [k = '', v = ''] = item.split('=');
|
||||
if (k.trim() === key) return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function setValue(key, value) {
|
||||
document.cookie = `${key}=${value}`;
|
||||
}
|
||||
|
||||
export default { getValue, setValue };
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
set(key, value) {
|
||||
window.localStorage.setItem(key, value);
|
||||
},
|
||||
get(key) {
|
||||
return window.localStorage.getItem(key);
|
||||
},
|
||||
remove(key) {
|
||||
window.localStorage.removeItem(key);
|
||||
},
|
||||
};
|
@ -57,7 +57,11 @@ export const isJsonString = str => {
|
||||
};
|
||||
|
||||
export const generateUrl = (url, params) => {
|
||||
return [url, '?', Object.keys(params).map(key => [key, params[key].join('=')].join('&'))].join(
|
||||
''
|
||||
);
|
||||
return [
|
||||
url,
|
||||
'?',
|
||||
Object.keys(params)
|
||||
.map(key => [key, params[key]].join('='))
|
||||
.join('&'),
|
||||
].join('');
|
||||
};
|
||||
|
@ -43,17 +43,23 @@ const request = () => {
|
||||
error => {
|
||||
if (error.response) {
|
||||
const { data = {}, status } = error.response;
|
||||
if (status === 403 && data.message === 'token invalid!') {
|
||||
let message = `HTTP ERROR: ${status}`;
|
||||
if (typeof data === 'string') {
|
||||
message = data;
|
||||
} else if (typeof data === 'object') {
|
||||
message = data.message;
|
||||
}
|
||||
Message.error(message);
|
||||
|
||||
if ([401, 403].includes(status) && ['unknown user!', 'token invalid'].includes(message)) {
|
||||
localStorage.removeItem('token');
|
||||
const [baseUrl] = location.href.split('#');
|
||||
location.href = `${baseUrl}#/login`;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
Message.error(data && typeof data === 'string' ? data : `HTTP ERROR: ${status}`);
|
||||
return error.response;
|
||||
return Promise.reject(error.response);
|
||||
}
|
||||
Message.error(API_GENERAL_ERROR_MESSAGE);
|
||||
return error;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
|
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