From c7ec9e17f6e48335912bad1c07df56ba8eb8f662 Mon Sep 17 00:00:00 2001 From: heyujie <516346543@qq.com> Date: 星期四, 05 五月 2022 13:35:21 +0800 Subject: [PATCH] page subuser --- src/scripts/httpRequest.ts | 74 ++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/scripts/httpRequest.ts b/src/scripts/httpRequest.ts index 8ac414b..848eba0 100644 --- a/src/scripts/httpRequest.ts +++ b/src/scripts/httpRequest.ts @@ -2,7 +2,7 @@ import axios from 'axios' import qs from 'qs' import { Notification } from 'element-ui' -// import router from '@/router' + import router from '@/router' const Axios = axios.create({ responseType: 'json', @@ -12,27 +12,24 @@ /* //POST浼犲弬搴忓垪鍖�(娣诲姞璇锋眰鎷︽埅鍣�) */ Axios.interceptors.request.use( config => { - // config.data = JSON.stringify(config.data) - // let Public = {}; - // if ( - // config.method === "post" || - // config.method === "put" || - // config.method === "delete" - // ) { - // // 搴忓垪鍖� - // // config.data = qs.stringify(config.data); - // // config.data = qs.stringify(Object.assign(Public, config.data)); - // } else { - // config.method = "get"; - // config.params = Object.assign(Public, config.data); - // } - // config.headers = { - // "X-Requested-With": "XMLHttpRequest", - // Accept: "application/json", - // "Content-Type": "application/json; charset=UTF-8" - // }; + if ( + config.method === "post" && + sessionStorage.getItem('clusterId') || + sessionStorage.getItem('devId') + ) { + if( !config.data ) { + config.data = {} + } + + if(typeof config.data == 'object' ) { + config.data.clusterId = sessionStorage.getItem('clusterId') + config.data.devId = sessionStorage.getItem('devId') + } + + } // 鑻ユ槸鏈夊仛閴存潈token , 灏辩粰澶撮儴甯︿笂token + let token = sessionStorage.getItem('loginedInfo') && JSON.parse(sessionStorage.getItem('loginedInfo')).access_token @@ -42,6 +39,10 @@ return config }, error => { + console.log('璇锋眰閿欒'); + console.log(error); + + /* Message({ showClose: true, message: "鎻愪氦鍑洪敊锛岃鑱旂郴绠$悊鍛橈紒", @@ -78,13 +79,21 @@ // window.sessionStorage.setItem('policeCameravideoIsLoginTimeout', JSON.stringify(true)) // } + return res.data ? res.data : {} + + /* //return res.data ? res.data : {}; */ }, error => { + console.log('鍝嶅簲閿欒'); + console.log(error); let errJson: any = { success: false + } + if(error && error.response&&error.response.status == 404) { + return } // 涓嬮潰鏄帴鍙e洖璋冪殑satus ,鍥犱负鎴戝仛浜嗕竴浜涢敊璇〉闈�,鎵�浠ラ兘浼氭寚鍚戝搴旂殑鎶ラ敊椤甸潰 if (error && error.response) { @@ -96,10 +105,9 @@ case 401: errJson.status = error.response.status errJson.message = '鏈巿鏉冿紝璇烽噸鏂扮櫥褰�(401)' - window.parent.postMessage({ - msg: "logout" - }, '*') - // console.log("鏍囧織浣嶏細",AuthData.isLoginout) + router.push({ + path: '/login' + }) // if (!AuthData.isLoginout) { // Notification({ // title:"", @@ -157,16 +165,22 @@ } else { errJson.message = '杩炴帴鏈嶅姟鍣ㄥけ璐�!' - Notification({ - title: '', - showClose: true, - message: '杩炴帴鏈嶅姟鍣ㄥけ璐�!', - type: 'error' - }) + // router.push({ // path: '/login' // }); } + + if(error.response&&error.response.data&&!error.response.data.success ) { + errJson.message =error.response.data.msg + } + + Notification({ + title: '閿欒', + showClose: true, + message:errJson.message, + type: 'error' + }) // 杩斿洖 response 閲岀殑閿欒淇℃伅 return Promise.reject(errJson) } -- Gitblit v1.8.0