重新筛选
This commit is contained in:
@@ -1,33 +1,45 @@
|
||||
import axios from 'axios';
|
||||
import QS from 'qs';
|
||||
import { goTologin } from '@/utils/util.js'
|
||||
import { showFullScreenLoading, tryHideFullScreenLoading } from './loading'
|
||||
import store from '@/store/index';
|
||||
import axios from "axios"
|
||||
import QS from "qs"
|
||||
import { goTologin } from "@/utils/util.js"
|
||||
import { showFullScreenLoading, tryHideFullScreenLoading } from "./loading"
|
||||
import store from "@/store/index"
|
||||
|
||||
axios.defaults.baseURL = 'https://app.gter.net'
|
||||
axios.defaults.baseURL = "https://app.gter.net"
|
||||
// axios.defaults.baseURL = '/index'
|
||||
axios.defaults.emulateJSON = true
|
||||
axios.defaults.withCredentials = true
|
||||
|
||||
axios.interceptors.request.use( //响应拦截
|
||||
axios.interceptors.request.use(
|
||||
//响应拦截
|
||||
async config => {
|
||||
if (config.url != '/tenement/pc/api/user/operation') showFullScreenLoading()
|
||||
// 不需要遮罩
|
||||
let noMask = false
|
||||
|
||||
|
||||
if (config.method == "get") noMask = config.params?.noMask || false
|
||||
|
||||
if (config.url != "/tenement/pc/api/user/operation" && !noMask) showFullScreenLoading()
|
||||
// 开发时登录用的,可以直接替换小程序的 authorization
|
||||
// if (process.env.NODE_ENV == "development") config['headers']['authorization'] = "x2mmnl9grt51bpplj2k6ioiuummzhnw3"
|
||||
if (process.env.NODE_ENV == "development") config['headers']['authorization'] = "gifqtoiomgb2efu7tcr16kcgs2"
|
||||
return config;
|
||||
if (process.env.NODE_ENV == "development") config["headers"]["authorization"] = "gifqtoiomgb2efu7tcr16kcgs2"
|
||||
|
||||
// 当 noMask == true 和 confing.method == 'get' 时,删除 config.params['noMask']
|
||||
if (noMask && config.method == "get") delete config.params["noMask"]
|
||||
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.error(error);
|
||||
})
|
||||
return Promise.error(error)
|
||||
}
|
||||
)
|
||||
// 响应拦截器
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
tryHideFullScreenLoading()
|
||||
if (response.status === 200) return Promise.resolve(response); //进行中
|
||||
else return Promise.reject(response); //失败
|
||||
if (response.status === 200) return Promise.resolve(response) //进行中
|
||||
else return Promise.reject(response) //失败
|
||||
},
|
||||
// 服务器状态码不是200的情况
|
||||
// 服务器状态码不是200的情况
|
||||
error => {
|
||||
tryHideFullScreenLoading()
|
||||
if (error.response.status) {
|
||||
@@ -40,57 +52,62 @@ axios.interceptors.response.use(
|
||||
case 403:
|
||||
// router.push('/login')
|
||||
break
|
||||
// 404请求不存在
|
||||
// 404请求不存在
|
||||
case 404:
|
||||
break;
|
||||
break
|
||||
// 其他错误,直接抛出错误提示
|
||||
default:
|
||||
}
|
||||
return Promise.reject(error.response);
|
||||
return Promise.reject(error.response)
|
||||
}
|
||||
}
|
||||
);
|
||||
/**
|
||||
* get方法,对应get请求
|
||||
* @param {String} url [请求的url地址]
|
||||
* @param {Object} params [请求时携带的参数]
|
||||
)
|
||||
/**
|
||||
* get方法,对应get请求
|
||||
* @param {String} url [请求的url地址]
|
||||
* @param {Object} params [请求时携带的参数]
|
||||
*/
|
||||
const $get = (url, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(url, {
|
||||
params: params,
|
||||
}).then(res => {
|
||||
resolve(res.data);
|
||||
}).catch(err => {
|
||||
reject(err.data)
|
||||
})
|
||||
});
|
||||
axios
|
||||
.get(url, {
|
||||
params: params,
|
||||
})
|
||||
.then(res => {
|
||||
resolve(res.data)
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* post方法,对应post请求
|
||||
* @param {String} url [请求的url地址]
|
||||
* @param {Object} params [请求时携带的参数]
|
||||
/**
|
||||
* post方法,对应post请求
|
||||
* @param {String} url [请求的url地址]
|
||||
* @param {Object} params [请求时携带的参数]
|
||||
*/
|
||||
const $post = (url, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
//是将对象 序列化成URL的形式,以&进行拼接
|
||||
axios.post(url, QS.stringify(params)).then(res => {
|
||||
resolve(res.data);
|
||||
}).catch(err => {
|
||||
if (err.data.code == 401) {
|
||||
resolve(err.data);
|
||||
} else reject(err.data)
|
||||
|
||||
})
|
||||
});
|
||||
//是将对象 序列化成URL的形式,以&进行拼接
|
||||
axios
|
||||
.post(url, QS.stringify(params))
|
||||
.then(res => {
|
||||
resolve(res.data)
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.data.code == 401) {
|
||||
resolve(err.data)
|
||||
} else reject(err.data)
|
||||
})
|
||||
})
|
||||
}
|
||||
//下面是vue3必须加的,vue2不需要,只需要暴露出去get,post方法就可以
|
||||
export default {
|
||||
get: $get,
|
||||
post: $post,
|
||||
install: (app) => {
|
||||
app.config.globalProperties['$get'] = $get;
|
||||
app.config.globalProperties['$post'] = $post;
|
||||
app.config.globalProperties['$axios'] = axios;
|
||||
}
|
||||
}
|
||||
install: app => {
|
||||
app.config.globalProperties["$get"] = $get
|
||||
app.config.globalProperties["$post"] = $post
|
||||
app.config.globalProperties["$axios"] = axios
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user