123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- import axios from "axios";
- import {timeout, baseUrl, baseUrl_Address,withCredentials} from "@/service/config";
- import {UserInfo} from "@/unit/UserInfo";
- import {showMessage} from "@/unit/element-ui/tip";
- import {closeShowLoading, showLoading} from "@/data/element-loading/element-loader";
- import router from "@/router";
- const requestInstance = axios.create({
- baseURL:import.meta.env.VITE_BASE_API,
- timeout,
- method:"post",
- headers:{
- Systemtype:'ebb42096345340359741dcb9c039f15c'
- },
- withCredentials,
- // headers:{
- //
- // "Content-Type":"application/x-www-form-urlencoded"
- // },
- // transformRequest:[(data) => {
- //
- // if(data) {
- // let params = new FormData()
- // let keys = Object.keys(data)
- // keys.forEach(key => {
- // params.append(key,data[key])
- // })
- // return params
- // }
- // return data
- // }
- // ]
- })
- export function setConfigInstance(config) {
- let instance = axios.create({
- baseURL:baseUrl,
- timeout,
- // method:"post",
- ...config
- })
- return instance
- }
- requestInstance.interceptors.request.use((config) => {
- if (!config.url.includes('/user/updateLoginLasttime')){
- showLoading({
- fullscreen:true
- })
- }
- let reg = /appkey=.*/
- //let isMatch = reg.test(config.url.split('?')[1])
- let isMatch = config.data.hasOwnProperty('appkey');
- return {
- ...config,
- data:new UserInfo().GetUserKeyCode()?(isMatch?config.data:{...config.data,appkey:new UserInfo().GetUserKeyCode()}):config.data
- }
- },(error) => {
- return new Error(error)
- })
- requestInstance.interceptors.response.use(function (res) {
- if (!res.config.url.includes('/user/updateLoginLasttime')){
- closeShowLoading()
- }
- let isAppkeyIsFailed = false
- try {
- if (+res.data.msg[0].code === 401){
- isAppkeyIsFailed= true
- }else {
- isAppkeyIsFailed= false
- }
- }catch {
- isAppkeyIsFailed = false
- }
- if (isAppkeyIsFailed){
- showMessage({
- type:'warning',
- message:'登录验证过期,请重新登录'
- })
- router.replace('/login')
- router.go(0)
- }
- return res.data
- },function (error) {
- closeShowLoading()
- return new Error(error)
- })
- export {
- requestInstance
- }
- const requestInstance_Get = axios.create({
- baseURL:import.meta.env.VITE_BASE_API,
- timeout,
- method:"get",
- withCredentials,
- responseType: "blob",
- headers:{
- Systemtype:'ebb42096345340359741dcb9c039f15c'
- },
- // headers:{
- //
- // "Content-Type":"application/x-www-form-urlencoded"
- // },
- // transformRequest:[(data) => {
- //
- // if(data) {
- // let params = new FormData()
- // let keys = Object.keys(data)
- // keys.forEach(key => {
- // params.append(key,data[key])
- // })
- // return params
- // }
- // return data
- // }
- // ]
- })
- requestInstance_Get.interceptors.request.use((config) => {
- return config
- },(error) => {
- return new Error(error)
- })
- requestInstance_Get.interceptors.response.use(function (res) {
- return res.data
- },function (error) {
- return new Error(error)
- })
- export {
- requestInstance_Get
- }
- const requestInstance_Html = axios.create({
- baseURL:import.meta.env.VITE_BASE_API,
- timeout,
- method:"get",
- withCredentials,
- headers:{
- Systemtype:'ebb42096345340359741dcb9c039f15c'
- },
- // headers:{
- //
- // "Content-Type":"application/x-www-form-urlencoded"
- // },
- // transformRequest:[(data) => {
- //
- // if(data) {
- // let params = new FormData()
- // let keys = Object.keys(data)
- // keys.forEach(key => {
- // params.append(key,data[key])
- // })
- // return params
- // }
- // return data
- // }
- // ]
- })
- requestInstance_Html.interceptors.request.use((config) => {
- return config
- },(error) => {
- return new Error(error)
- })
- requestInstance_Html.interceptors.response.use(function (res) {
- return res
- },function (error) {
- return new Error(error)
- })
- export {
- requestInstance_Html
- }
|