diff --git a/src/utils/request.ts b/src/utils/request.ts index 197db378..6d538e31 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -131,7 +131,7 @@ export const postStream = function(url: string, data = {}, params = {}) { }) } -const showNotification = (message: string, description: string, key?: string, show: boolean = true) => { +export const showNotification = (message: string, description: string, key?: string, show: boolean = true) => { if (show) { Notification.error({ style: { @@ -144,13 +144,17 @@ const showNotification = (message: string, description: string, key?: string, sh } } +export const TokenLose = () => { + showNotification('Unauthorized', '用户未登录', '401') +} + /** * 异常拦截处理器 * @param {Object} error * @returns {Promise} */ const errorHandler = (error: any) => { - + if (error.response) { const data = error.response.data const status = error.response.status @@ -182,7 +186,7 @@ const errorHandler = (error: any) => { } else if (status === 400) { showNotification('Request Error', (data.message + '').substr(0, 90), '400') } else if (status === 401) { - showNotification('Unauthorized', '用户未登录', '401') + TokenLose() setTimeout(() => { cleanToken() router.replace({ @@ -257,4 +261,4 @@ export default { remove, getStream, postStream -} \ No newline at end of file +} diff --git a/src/views/iframe/index.vue b/src/views/iframe/index.vue index 42231f0f..ad644363 100644 --- a/src/views/iframe/index.vue +++ b/src/views/iframe/index.vue @@ -14,10 +14,14 @@