| | |
| | | /* eslint-disable */ |
| | | import axios from 'axios' |
| | | import qs from 'qs' |
| | | import { Notification } from 'element-ui' |
| | | import router from '@/router' |
| | | import axios from "axios" |
| | | import qs from "qs" |
| | | import { Notification } from "element-ui" |
| | | import router from "@/router" |
| | | |
| | | const Axios = axios.create({ |
| | | responseType: 'json', |
| | | responseType: "json", |
| | | withCredentials: true // 是否允许带cookie这些 |
| | | }) |
| | | |
| | | /* //POST传参序列化(添加请求拦截器) */ |
| | | Axios.interceptors.request.use( |
| | | config => { |
| | | console.log(9898); |
| | | console.log(config); |
| | | |
| | | |
| | | if ( |
| | | config.method === "post" && |
| | | sessionStorage.getItem('clusterId') || |
| | | sessionStorage.getItem('devId') |
| | | ) { |
| | | if( !config.data ) { |
| | | (config) => { |
| | | console.log(9898) |
| | | console.log(config) |
| | | |
| | | 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') |
| | | if (typeof config.data == "object") { |
| | | config.data.clusterId = sessionStorage.getItem("clusterId") |
| | | config.data.devId = sessionStorage.getItem("devId") |
| | | } |
| | | |
| | | if(config.url === '/saas/api-s/camera/rule/getLinkRulesByCameraIds') { |
| | | config.data.devId = sessionStorage.getItem('cameraDevId') |
| | | if (config.url === "/saas/api-s/camera/rule/getLinkRulesByCameraIds") { |
| | | config.data.devId = sessionStorage.getItem("cameraDevId") |
| | | } |
| | | |
| | | //后门 |
| | | if(config.url === '/saas/api-d/device/userClusterInfo') { |
| | | config.data.clusterId = '' |
| | | if (config.url === "/saas/api-d/device/userClusterInfo") { |
| | | config.data.clusterId = "" |
| | | } |
| | | |
| | | if(config.url === '/saas/api-s/es/saveEsConfig') { |
| | | if (config.url === "/saas/api-s/es/saveEsConfig") { |
| | | delete config.data.clusterId |
| | | delete config.data.devId |
| | | } |
| | | |
| | | } |
| | | |
| | | // 若是有做鉴权token , 就给头部带上token |
| | | |
| | | let token = |
| | | sessionStorage.getItem('loginedInfo') && |
| | | JSON.parse(sessionStorage.getItem('loginedInfo')).access_token |
| | | |
| | | let token = sessionStorage.getItem("loginedInfo") && JSON.parse(sessionStorage.getItem("loginedInfo")).access_token |
| | | if (token != undefined) { |
| | | config.headers.Authorization = token |
| | | } |
| | | return config |
| | | }, |
| | | error => { |
| | | console.log('请求错误'); |
| | | console.log(error); |
| | | |
| | | |
| | | (error) => { |
| | | console.log("请求错误") |
| | | console.log(error) |
| | | |
| | | /* Message({ |
| | | showClose: true, |
| | | message: "提交出错,请联系管理员!", |
| | |
| | | |
| | | /* //返回状态判断(添加响应拦截器) */ |
| | | Axios.interceptors.response.use( |
| | | res => { |
| | | (res) => { |
| | | /* //对响应数据做些事 */ |
| | | if (res.data && res.statusText !== 'OK' && res.status !== 200) { |
| | | if (res.data && res.statusText !== "OK" && res.status !== 200) { |
| | | Notification({ |
| | | title: '', |
| | | title: "", |
| | | message: res.data.message, |
| | | type: 'error' |
| | | type: "error" |
| | | }) |
| | | return Promise.reject(res.data) |
| | | } |
| | |
| | | // window.sessionStorage.setItem('policeCameravideoIsLoginTimeout', JSON.stringify(true)) |
| | | // } |
| | | |
| | | var disposition = res.headers["content-disposition"]; |
| | | if(disposition) { |
| | | var fileName = disposition.substring(disposition.indexOf("=") + 1); |
| | | console.log(res); |
| | | |
| | | return { |
| | | fileName:fileName, |
| | | body:res |
| | | } |
| | | } |
| | | var disposition = res.headers["content-disposition"] |
| | | if (disposition) { |
| | | var fileName = disposition.substring(disposition.indexOf("=") + 1) |
| | | console.log(res) |
| | | |
| | | return { |
| | | fileName: fileName, |
| | | body: res |
| | | } |
| | | } |
| | | |
| | | return res.data ? res.data : {} |
| | | |
| | | |
| | | |
| | | /* //return res.data ? res.data : {}; */ |
| | | }, |
| | | error => { |
| | | console.log('响应错误'); |
| | | console.log(error); |
| | | (error) => { |
| | | console.log("响应错误") |
| | | console.log(error) |
| | | let errJson: any = { |
| | | success: false |
| | | } |
| | | if(error && error.response&&error.response.status == 404) { |
| | | if (error && error.response && error.response.status == 404) { |
| | | return |
| | | } |
| | | // 下面是接口回调的satus ,因为我做了一些错误页面,所以都会指向对应的报错页面 |
| | |
| | | switch (error.response.status) { |
| | | case 400: |
| | | errJson.status = error.response.status |
| | | errJson.message = '请求错误(400)' |
| | | errJson.message = "请求错误(400)" |
| | | break |
| | | case 401: |
| | | errJson.status = error.response.status |
| | | errJson.message = '未授权,请重新登录(401)' |
| | | errJson.message = "未授权,请重新登录(401)" |
| | | router.push({ |
| | | path: '/login' |
| | | }) |
| | | path: "/login" |
| | | }) |
| | | // if (!AuthData.isLoginout) { |
| | | // Notification({ |
| | | // title:"", |
| | |
| | | break |
| | | case 403: |
| | | errJson.status = error.response.status |
| | | errJson.message = '拒绝访问(403)' |
| | | errJson.message = "拒绝访问(403)" |
| | | break |
| | | case 404: |
| | | errJson.status = error.response.status |
| | | errJson.message = '找不到请求路径(404)' |
| | | errJson.message = "找不到请求路径(404)" |
| | | break |
| | | case 408: |
| | | errJson.status = error.response.status |
| | | errJson.message = '请求超时(408)' |
| | | errJson.message = "请求超时(408)" |
| | | break |
| | | case 500: |
| | | errJson = error.response.data |
| | | break |
| | | |
| | | |
| | | default: |
| | | errJson.status = error.response.status |
| | | errJson.message = `连接出错(${error.response.status})!` |
| | | } |
| | | |
| | | } else { |
| | | errJson.message = '连接服务器失败!' |
| | | |
| | | errJson.message = "连接服务器失败!" |
| | | |
| | | // router.push({ |
| | | // path: '/login' |
| | | // }); |
| | | } |
| | | |
| | | if(error.response&&error.response.data&&!error.response.data.success ) { |
| | | errJson.message =error.response.data.msg |
| | | |
| | | if (error.response && error.response.data && !error.response.data.success) { |
| | | errJson.message = error.response.data.msg |
| | | } |
| | | |
| | | if(error.response.status == 401) { |
| | | if (error.response.status == 401) { |
| | | return |
| | | } |
| | | |
| | | Notification({ |
| | | title: '错误', |
| | | showClose: true, |
| | | message:errJson.message, |
| | | type: 'error' |
| | | }) |
| | | |
| | | Notification({ |
| | | title: "错误", |
| | | showClose: true, |
| | | message: errJson.message, |
| | | type: "error" |
| | | }) |
| | | // 返回 response 里的错误信息 |
| | | return Promise.reject(errJson) |
| | | } |
| | | ) |
| | | |
| | | Axios.defaults.timeout = 60 * 1000 |
| | | Axios.defaults.timeout = 60 * 1000 * 2 |
| | | export default Axios |