| | |
| | | /* |
| | | * @Author: shuishen 1109946754@qq.com |
| | | * @Date: 2022-07-29 15:19:13 |
| | | * @LastEditors: shuishen 1109946754@qq.com |
| | | * @LastEditTime: 2022-08-05 10:51:10 |
| | | * @FilePath: \zhny-dsj\src\router\axios.js |
| | | * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
| | | */ |
| | | /** |
| | | * 全站http配置 |
| | | * |
| | |
| | | * isToken是否需要token |
| | | */ |
| | | import axios from 'axios' |
| | | const httpName = window.location.protocol + '//' + window.location.hostname |
| | | const url = httpName + '/apis' |
| | | // setTimeout(() => { |
| | | // console.log(window.location); |
| | | // console.log(url); |
| | | // }, 3000); |
| | | window.$apiUrls = 'http://171.34.197.243:782' |
| | | // window.$apiUrls = 'http://192.168.0.109:82' |
| | | const service = axios.create({ |
| | | // baseURL: 'http://192.168.0.107:83', |
| | | import router from '@/router/page/index.js' |
| | | import { Message } from 'element-ui' |
| | | import * as auth from '@/utils/auth' |
| | | |
| | | // baseURL: "http://localhost:82", |
| | | // baseURL: "http://192.168.0.107:82", |
| | | // baseURL: "http://192.168.0.107:80", |
| | | // baseURL: "http://192.168.0.110:82", //唐 |
| | | // baseURL: "http://171.34.197.243:790", //正常接口 |
| | | baseURL: window.$apiUrls, // 2 |
| | | // baseURL: "http://171.34.197.243:82", //3 |
| | | // baseURL: "http://171.34.197.243:82/api", //验收 |
| | | // baseURL: "https://6e78efa6.cpolar.io/apis", //https接口 |
| | | // baseURL: url, //https接口 |
| | | // baseURL: 'http://s16s652780.51mypc.cn/api', |
| | | const service = axios.create({ |
| | | baseURL: 'http://dev.jxpskj.com:8020/api', // 2 |
| | | // baseURL:'http://127.0.0.1:89', |
| | | timeout: 600000 // request timeout |
| | | }) |
| | | |
| | |
| | | // http request拦截 |
| | | service.interceptors.request.use( |
| | | (config) => { |
| | | const token = auth.getToken() |
| | | |
| | | // 添加token |
| | | token && (config.headers.token = token) |
| | | |
| | | return config |
| | | }, |
| | | (error) => { |
| | |
| | | // http response 拦截 |
| | | service.interceptors.response.use( |
| | | (res) => { |
| | | return res |
| | | const code = res.data.code |
| | | |
| | | // console.log(code, 555) |
| | | |
| | | if (code == '403' || code == '401') { |
| | | sessionStorage.removeItem('token') |
| | | router.push('/login') |
| | | } else { |
| | | return res |
| | | } |
| | | }, |
| | | (error) => { |
| | | Message({ |
| | | message: error.message, |
| | | type: 'error', |
| | | duration: 5 * 1000 |
| | | }) |
| | | |
| | | return Promise.reject(new Error(error)) |
| | | } |
| | | ) |