修改中英文切换
This commit is contained in:
@@ -2,8 +2,8 @@ import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
import store from '@/store'
|
||||
import { VueAxios } from './axios'
|
||||
import {Modal, notification} from 'ant-design-vue'
|
||||
import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types"
|
||||
import { Modal, notification } from 'ant-design-vue'
|
||||
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
|
||||
|
||||
/**
|
||||
* 【指定 axios的 baseURL】
|
||||
@@ -11,7 +11,7 @@ import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types"
|
||||
* 则映射后端域名,通过 vue.config.js
|
||||
* @type {*|string}
|
||||
*/
|
||||
let apiBaseUrl = window._CONFIG['domianURL'] || "/jero-boot";
|
||||
let apiBaseUrl = window._CONFIG['domianURL'] || '/jero-boot'
|
||||
//console.log("apiBaseUrl= ",apiBaseUrl)
|
||||
// 创建 axios 实例
|
||||
const service = axios.create({
|
||||
@@ -24,23 +24,23 @@ 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)
|
||||
console.log('------异常响应------', token)
|
||||
console.log('------异常响应------', error.response.status)
|
||||
switch (error.response.status) {
|
||||
case 403:
|
||||
notification.error({ message: '系统提示', description: '拒绝访问',duration: 4})
|
||||
notification.error({ message: '系统提示', description: '拒绝访问', duration: 4 })
|
||||
break
|
||||
case 500:
|
||||
console.log("------error.response------",error.response)
|
||||
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;
|
||||
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失效")){
|
||||
if (token && data.message.includes('Token失效')) {
|
||||
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||
Modal.error({
|
||||
title: '登录已过期',
|
||||
@@ -52,11 +52,11 @@ const err = (error) => {
|
||||
Vue.ls.remove(ACCESS_TOKEN)
|
||||
try {
|
||||
let path = window.document.location.pathname
|
||||
console.log("location pathname -> "+path)
|
||||
if(path!="/" && path.indexOf('/user/login')==-1){
|
||||
console.log('location pathname -> ' + path)
|
||||
if (path != '/' && path.indexOf('/user/login') == -1) {
|
||||
window.location.reload()
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
@@ -66,13 +66,13 @@ const err = (error) => {
|
||||
}
|
||||
break
|
||||
case 404:
|
||||
notification.error({ message: '系统提示', description:'很抱歉,资源未找到!',duration: 4})
|
||||
notification.error({ message: '系统提示', description: '很抱歉,资源未找到!', duration: 4 })
|
||||
break
|
||||
case 504:
|
||||
notification.error({ message: '系统提示', description: '网络超时'})
|
||||
notification.error({ message: '系统提示', description: '网络超时' })
|
||||
break
|
||||
case 401:
|
||||
notification.error({ message: '系统提示', description:'未授权,请重新登录',duration: 4})
|
||||
notification.error({ message: '系统提示', description: '未授权,请重新登录', duration: 4 })
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
@@ -91,59 +91,74 @@ const err = (error) => {
|
||||
}
|
||||
}
|
||||
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 请根据实际情况自行修改
|
||||
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;
|
||||
tenantid = 0
|
||||
}
|
||||
config.headers[ 'tenant_id' ] = tenantid
|
||||
let long = localStorage.getItem('language')
|
||||
let cut = ''
|
||||
if (long && long == 'zh-cn') {
|
||||
cut = 'cn'
|
||||
} else if (long && long == 'en-us') {
|
||||
cut = 'en'
|
||||
}
|
||||
config.headers['tenant_id'] = tenantid
|
||||
//update-end-author:taoyan date:2020707 for:多租户
|
||||
if(config.method=='get'){
|
||||
if(config.url.indexOf("sys/dict/getDictItems")<0){
|
||||
if (config.method == 'get') {
|
||||
if (config.url.indexOf('sys/dict/getDictItems') < 0) {
|
||||
config.params = {
|
||||
_t: Date.parse(new Date())/1000,
|
||||
_t: Date.parse(new Date()) / 1000,
|
||||
cut: cut,
|
||||
...config.params
|
||||
}
|
||||
}
|
||||
} else if((config.method == 'post')) {
|
||||
console.log(config)
|
||||
config.data = {
|
||||
cut: cut,
|
||||
...config.data
|
||||
}
|
||||
}
|
||||
return config
|
||||
},(error) => {
|
||||
}, (error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use((response) => {
|
||||
return response.data
|
||||
}, err)
|
||||
return response.data
|
||||
}, err)
|
||||
|
||||
const installer = {
|
||||
vm: {},
|
||||
install (Vue, router = {}) {
|
||||
install(Vue, router = {}) {
|
||||
Vue.use(VueAxios, router, service)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Blob解析
|
||||
* @param data
|
||||
*/
|
||||
function blobToJson(data) {
|
||||
let fileReader = new FileReader();
|
||||
let token = Vue.ls.get(ACCESS_TOKEN);
|
||||
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)
|
||||
let jsonData = JSON.parse(this.result) // 说明是普通对象数据,后台转换失败
|
||||
console.log('jsonData', jsonData)
|
||||
if (jsonData.status === 500) {
|
||||
console.log("token----------》",token)
|
||||
if(token && jsonData.message.includes("Token失效")){
|
||||
console.log('token----------》', token)
|
||||
if (token && jsonData.message.includes('Token失效')) {
|
||||
Modal.error({
|
||||
title: '登录已过期',
|
||||
content: '很抱歉,登录已过期,请重新登录',
|
||||
@@ -160,9 +175,9 @@ function blobToJson(data) {
|
||||
}
|
||||
} catch (err) {
|
||||
// 解析成对象失败,说明是正常的文件流
|
||||
console.log("blob解析fileReader返回err",err)
|
||||
console.log('blob解析fileReader返回err', err)
|
||||
}
|
||||
};
|
||||
}
|
||||
fileReader.readAsText(data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user