|
@@ -1,130 +1,133 @@
|
|
-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} from "@/store/mutation-types"
|
|
|
|
-const key = "1"
|
|
|
|
|
|
+/**
|
|
|
|
+ * @file reauest 配置
|
|
|
|
+ * @author zhuxinbo
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+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} from '@/store/mutation-types';
|
|
|
|
+const key = '1';
|
|
// 创建 axios 实例
|
|
// 创建 axios 实例
|
|
|
|
|
|
-if (process.env.NODE_ENV == 'development') {
|
|
|
|
- axios.defaults.baseURL = '/jeecg-boot'
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-else if (process.env.NODE_ENV == 'debug') {
|
|
|
|
-}
|
|
|
|
-else if (process.env.NODE_ENV == 'production') {
|
|
|
|
-
|
|
|
|
- // axios.defaults.baseURL = 'http://apipre.tjyourong.com.cn/jeecg-boot';//预生产
|
|
|
|
- axios.defaults.baseURL = 'http://139.186.165.84:8806/jeecg-boot';
|
|
|
|
- // axios.defaults.baseURL = 'http://api.tjyourong.com.cn/jeecg-boot';//生产环境
|
|
|
|
|
|
+if (process.env.NODE_ENV === 'development') {
|
|
|
|
+ axios.defaults.baseURL = '/jeecg-boot';
|
|
|
|
+}
|
|
|
|
+else if (process.env.NODE_ENV === 'debug') {
|
|
|
|
+}
|
|
|
|
+else if (process.env.NODE_ENV === 'production') {
|
|
|
|
+ // axios.defaults.baseURL = 'http://apipre.tjyourong.com.cn/jeecg-boot';//预生产
|
|
|
|
+ axios.defaults.baseURL = 'http://139.186.165.84:8806/jeecg-boot';
|
|
|
|
+ // axios.defaults.baseURL = 'http://api.tjyourong.com.cn/jeecg-boot';//生产环境
|
|
}
|
|
}
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
-// baseURL: '/jeecg-boot', // api base_url
|
|
|
|
- timeout: 6000000 // 请求超时时间
|
|
|
|
-})
|
|
|
|
|
|
+ // baseURL: '/jeecg-boot', // api base_url
|
|
|
|
+ timeout: 6000000 // 请求超时时间
|
|
|
|
+});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const err = (error) => {
|
|
const err = (error) => {
|
|
- if (error.esponse) {
|
|
|
|
- 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({key,message: '系统提示', description: '拒绝访问', duration: 4})
|
|
|
|
- break
|
|
|
|
- case 500:
|
|
|
|
- //notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
|
|
|
- if (token && data.message == "Token失效,请重新登录") {
|
|
|
|
- // update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
|
- // store.dispatch('Logout').then(() => {
|
|
|
|
- // window.location.reload()
|
|
|
|
- // })
|
|
|
|
- Modal.error({
|
|
|
|
- title: '登录已过期',
|
|
|
|
- content: '很抱歉,登录已过期,请重新登录',
|
|
|
|
- okText: '重新登录',
|
|
|
|
- mask: false,
|
|
|
|
- onOk: () => {
|
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
|
- Vue.ls.remove(ACCESS_TOKEN)
|
|
|
|
- window.location.reload()
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- // update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
|
- }
|
|
|
|
- break
|
|
|
|
- case 404:
|
|
|
|
- notification.error({key,message: '系统提示', description: '很抱歉,资源未找到!', duration: 4})
|
|
|
|
- break
|
|
|
|
- case 504:
|
|
|
|
- notification.error({key,message: '系统提示', description: '网络超时'})
|
|
|
|
- break
|
|
|
|
- case 401:
|
|
|
|
- notification.error({key,message: '系统提示', description: '未授权,请重新登录', duration: 4})
|
|
|
|
- if (token) {
|
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
|
- setTimeout(() => {
|
|
|
|
- window.location.reload()
|
|
|
|
- }, 1500)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- break
|
|
|
|
- default:
|
|
|
|
- notification.error({
|
|
|
|
- key,
|
|
|
|
- message: '系统提示',
|
|
|
|
- description: data.message,
|
|
|
|
- duration: 4
|
|
|
|
- })
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return Promise.reject(error)
|
|
|
|
|
|
+ if (error.esponse) {
|
|
|
|
+ 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({key,message: '系统提示', description: '拒绝访问', duration: 4})
|
|
|
|
+ break
|
|
|
|
+ case 500:
|
|
|
|
+ //notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
|
|
|
+ if (token && data.message == "Token失效,请重新登录") {
|
|
|
|
+ // update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
|
+ // store.dispatch('Logout').then(() => {
|
|
|
|
+ // window.location.reload()
|
|
|
|
+ // })
|
|
|
|
+ Modal.error({
|
|
|
|
+ title: '登录已过期',
|
|
|
|
+ content: '很抱歉,登录已过期,请重新登录',
|
|
|
|
+ okText: '重新登录',
|
|
|
|
+ mask: false,
|
|
|
|
+ onOk: () => {
|
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
|
+ Vue.ls.remove(ACCESS_TOKEN)
|
|
|
|
+ window.location.reload()
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ // update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ case 404:
|
|
|
|
+ notification.error({key,message: '系统提示', description: '很抱歉,资源未找到!', duration: 4})
|
|
|
|
+ break
|
|
|
|
+ case 504:
|
|
|
|
+ notification.error({key,message: '系统提示', description: '网络超时'})
|
|
|
|
+ break
|
|
|
|
+ case 401:
|
|
|
|
+ notification.error({key,message: '系统提示', description: '未授权,请重新登录', duration: 4})
|
|
|
|
+ if (token) {
|
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ window.location.reload()
|
|
|
|
+ }, 1500)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ default:
|
|
|
|
+ notification.error({
|
|
|
|
+ key,
|
|
|
|
+ message: '系统提示',
|
|
|
|
+ description: data.message,
|
|
|
|
+ duration: 4
|
|
|
|
+ })
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return Promise.reject(error)
|
|
};
|
|
};
|
|
|
|
|
|
// request interceptor
|
|
// request interceptor
|
|
service.interceptors.request.use(config => {
|
|
service.interceptors.request.use(config => {
|
|
- const token = Vue.ls.get(ACCESS_TOKEN)
|
|
|
|
- if (token) {
|
|
|
|
- config.headers['X-Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
|
|
- }
|
|
|
|
- if (config.method == 'get') {
|
|
|
|
- config.params = {
|
|
|
|
- _t: Date.parse(new Date()) / 1000,
|
|
|
|
- ...config.params
|
|
|
|
|
|
+ const token = Vue.ls.get(ACCESS_TOKEN);
|
|
|
|
+ if (token) {
|
|
|
|
+ config.headers['X-Access-Token'] = token; // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
}
|
|
}
|
|
- }
|
|
|
|
- return config
|
|
|
|
|
|
+ if (config.method === 'get') {
|
|
|
|
+ config.params = {
|
|
|
|
+ _t: Date.parse(new Date()) / 1000,
|
|
|
|
+ ...config.params
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ return config;
|
|
}, (error) => {
|
|
}, (error) => {
|
|
- return Promise.reject(error)
|
|
|
|
-})
|
|
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
+});
|
|
|
|
|
|
// response interceptor
|
|
// response interceptor
|
|
service.interceptors.response.use((response) => {
|
|
service.interceptors.response.use((response) => {
|
|
- return response.data
|
|
|
|
|
|
+ return response.data;
|
|
}, (error) => {
|
|
}, (error) => {
|
|
notification.error({
|
|
notification.error({
|
|
key,
|
|
key,
|
|
message: '系统提示',
|
|
message: '系统提示',
|
|
description: '网络超时,请刷新页面'
|
|
description: '网络超时,请刷新页面'
|
|
- })
|
|
|
|
- return
|
|
|
|
- })
|
|
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+});
|
|
|
|
|
|
const installer = {
|
|
const installer = {
|
|
- vm: {},
|
|
|
|
- install(Vue, router = {}) {
|
|
|
|
- Vue.use(VueAxios, router, service)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ vm: {},
|
|
|
|
+ install(Vue, router = {}) {
|
|
|
|
+ Vue.use(VueAxios, router, service);
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
|
|
export {
|
|
export {
|
|
- installer as VueAxios,
|
|
|
|
- service as axios
|
|
|
|
-}
|
|
|
|
|
|
+ installer as VueAxios,
|
|
|
|
+ service as axios
|
|
|
|
+};
|