add 大屏调其他系统的axios封装
This commit is contained in:
Generated
-36899
File diff suppressed because it is too large
Load Diff
@@ -27,3 +27,8 @@ window._CONFIG["sendCompanyName"] = "中汽标准所"
|
|||||||
window._CONFIG["sendAddress"] = "天津市东丽区先锋东路68号"
|
window._CONFIG["sendAddress"] = "天津市东丽区先锋东路68号"
|
||||||
// 票据打印--寄件人邮编
|
// 票据打印--寄件人邮编
|
||||||
window._CONFIG["sendPostCode"] = "300300"
|
window._CONFIG["sendPostCode"] = "300300"
|
||||||
|
|
||||||
|
// 大屏--请求WP29的baseUrl
|
||||||
|
window._CONFIG["WP29BaseUrl"] = 'http://localhost:8090/jero-boot'
|
||||||
|
// 大屏--请求ISO的baseUrl
|
||||||
|
window._CONFIG["ISOBaseUrl"] = ''
|
||||||
@@ -26,3 +26,7 @@ window._CONFIG["sendAddress"] = "天津市东丽区先锋东路68号"
|
|||||||
// 票据打印--寄件人邮编
|
// 票据打印--寄件人邮编
|
||||||
window._CONFIG["sendPostCode"] = "300300"
|
window._CONFIG["sendPostCode"] = "300300"
|
||||||
|
|
||||||
|
// 大屏--请求WP29的baseUrl
|
||||||
|
window._CONFIG["WP29BaseUrl"] = ''
|
||||||
|
// 大屏--请求ISO的baseUrl
|
||||||
|
window._CONFIG["ISOBaseUrl"] = ''
|
||||||
@@ -23,4 +23,9 @@ window._CONFIG["sendCompanyName"] = "中汽标准所"
|
|||||||
// 票据打印--寄件人地址
|
// 票据打印--寄件人地址
|
||||||
window._CONFIG["sendAddress"] = "天津市东丽区先锋东路68号"
|
window._CONFIG["sendAddress"] = "天津市东丽区先锋东路68号"
|
||||||
// 票据打印--寄件人邮编
|
// 票据打印--寄件人邮编
|
||||||
window._CONFIG["sendPostCode"] = "300300"
|
window._CONFIG["sendPostCode"] = "300300"
|
||||||
|
|
||||||
|
// 大屏--请求WP29的baseUrl
|
||||||
|
window._CONFIG["WP29BaseUrl"] = ''
|
||||||
|
// 大屏--请求ISO的baseUrl
|
||||||
|
window._CONFIG["ISOBaseUrl"] = ''
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* 大屏部分的请求封装,需要从外部传入baseUrl
|
||||||
|
*/
|
||||||
|
import { axios } from '@/screenRequest/request'
|
||||||
|
|
||||||
|
export function screenGetAction(baseUrl, url, parameter) {
|
||||||
|
return axios({
|
||||||
|
url: baseUrl + url,
|
||||||
|
method:'post' ,
|
||||||
|
data: parameter
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import axios from 'axios'
|
||||||
|
import store from '@/store'
|
||||||
|
import { Modal, notification } from 'ant-design-vue'
|
||||||
|
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【指定 axios的 baseURL】
|
||||||
|
* 如果手工指定 baseURL: '/jero-boot'
|
||||||
|
* 则映射后端域名,通过 vue.config.js
|
||||||
|
* @type {*|string}
|
||||||
|
*/
|
||||||
|
// 创建 axios 实例
|
||||||
|
const service = axios.create({})
|
||||||
|
|
||||||
|
const err = (error) => {
|
||||||
|
if (error.response) {
|
||||||
|
let data = error.response.data
|
||||||
|
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||||
|
console.log('------异常响应------', token)
|
||||||
|
console.log('------异常响应------', error.response.status)
|
||||||
|
switch (error.response.status) {
|
||||||
|
case 403:
|
||||||
|
notification.error({ message: '系统提示', description: '拒绝访问', duration: 4 })
|
||||||
|
break
|
||||||
|
case 500:
|
||||||
|
console.log('------error.response------', error.response)
|
||||||
|
// update-begin- --- author:liusq ------ date:20200910 ---- for:处理Blob情况----
|
||||||
|
let type = error.response.request.responseType
|
||||||
|
if (type === 'blob') {
|
||||||
|
blobToJson(data)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// update-end- --- author:liusq ------ date:20200910 ---- for:处理Blob情况----
|
||||||
|
//notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
||||||
|
if (token && data.message.includes('Token失效')) {
|
||||||
|
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||||
|
Modal.error({
|
||||||
|
title: '登录已过期',
|
||||||
|
content: '很抱歉,登录已过期,请重新登录',
|
||||||
|
okText: '重新登录',
|
||||||
|
mask: false,
|
||||||
|
onOk: () => {
|
||||||
|
store.dispatch('Logout').then(() => {
|
||||||
|
Vue.ls.remove(ACCESS_TOKEN)
|
||||||
|
try {
|
||||||
|
let path = window.document.location.pathname
|
||||||
|
console.log('location pathname -> ' + path)
|
||||||
|
if (path != '/' && path.indexOf('/user/login') == -1) {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 404:
|
||||||
|
notification.error({ message: '系统提示', description: '很抱歉,资源未找到!', duration: 4 })
|
||||||
|
break
|
||||||
|
case 504:
|
||||||
|
notification.error({ message: '系统提示', description: '网络超时' })
|
||||||
|
break
|
||||||
|
case 401:
|
||||||
|
notification.error({ message: '系统提示', description: '未授权,请重新登录', duration: 4 })
|
||||||
|
if (token) {
|
||||||
|
store.dispatch('Logout').then(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload()
|
||||||
|
}, 1500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
notification.error({
|
||||||
|
message: '系统提示',
|
||||||
|
description: data.message,
|
||||||
|
duration: 4
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// request interceptor
|
||||||
|
service.interceptors.request.use(config => {
|
||||||
|
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||||
|
if (token) {
|
||||||
|
config.headers['X-Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
||||||
|
}
|
||||||
|
//update-begin-author:taoyan date:2020707 for:多租户
|
||||||
|
let tenantid = Vue.ls.get(TENANT_ID)
|
||||||
|
if (!tenantid) {
|
||||||
|
tenantid = 0
|
||||||
|
}
|
||||||
|
config.headers['tenant_id'] = tenantid
|
||||||
|
//update-end-author:taoyan date:2020707 for:多租户
|
||||||
|
if (config.method == 'get') {
|
||||||
|
if (config.url.indexOf('sys/dict/getDictItems') < 0) {
|
||||||
|
config.params = {
|
||||||
|
_t: Date.parse(new Date()) / 1000,
|
||||||
|
...config.params
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}, (error) => {
|
||||||
|
return Promise.reject(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
// response interceptor
|
||||||
|
service.interceptors.response.use((response) => {
|
||||||
|
return response.data
|
||||||
|
}, err)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blob解析
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
function blobToJson(data) {
|
||||||
|
let fileReader = new FileReader()
|
||||||
|
let token = Vue.ls.get(ACCESS_TOKEN)
|
||||||
|
fileReader.onload = function () {
|
||||||
|
try {
|
||||||
|
let jsonData = JSON.parse(this.result) // 说明是普通对象数据,后台转换失败
|
||||||
|
console.log('jsonData', jsonData)
|
||||||
|
if (jsonData.status === 500) {
|
||||||
|
console.log('token----------》', token)
|
||||||
|
if (token && jsonData.message.includes('Token失效')) {
|
||||||
|
Modal.error({
|
||||||
|
title: '登录已过期',
|
||||||
|
content: '很抱歉,登录已过期,请重新登录',
|
||||||
|
okText: '重新登录',
|
||||||
|
mask: false,
|
||||||
|
onOk: () => {
|
||||||
|
store.dispatch('Logout').then(() => {
|
||||||
|
Vue.ls.remove(ACCESS_TOKEN)
|
||||||
|
window.location.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// 解析成对象失败,说明是正常的文件流
|
||||||
|
console.log('blob解析fileReader返回err', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileReader.readAsText(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
service as axios
|
||||||
|
}
|
||||||
+1
-1
@@ -88,7 +88,7 @@ module.exports = {
|
|||||||
},*/
|
},*/
|
||||||
'/jero-boot': {
|
'/jero-boot': {
|
||||||
// ''
|
// ''
|
||||||
target: 'http://10.0.10.160:8080', //请求本地 jero-boot后台项目
|
target: 'http://localhost:8080', //请求本地 jero-boot后台项目
|
||||||
ws: false,
|
ws: false,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user