|
|
|
@ -1,4 +1,4 @@
|
|
|
|
import uviewPlus from 'uview-plus';
|
|
|
|
import { http } from 'uview-plus';
|
|
|
|
import { useAuthStore, useCommonStore } from '@/store';
|
|
|
|
import { useAuthStore, useCommonStore } from '@/store';
|
|
|
|
import { env } from '@/env';
|
|
|
|
import { env } from '@/env';
|
|
|
|
|
|
|
|
|
|
|
|
@ -12,10 +12,11 @@ export {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const HttpConfig = () => {
|
|
|
|
export const HttpConfig = () => {
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化请求配置
|
|
|
|
// 初始化请求配置
|
|
|
|
uni.$u.http.setConfig((config) => {
|
|
|
|
http.setConfig((config) => {
|
|
|
|
|
|
|
|
|
|
|
|
/* config 为默认全局配置*/
|
|
|
|
/* config 为默认全局配置*/
|
|
|
|
config.baseURL = env.baseApi;
|
|
|
|
config.baseURL = env.baseApi;
|
|
|
|
@ -31,7 +32,7 @@ export const HttpConfig = ()=>{
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 请求拦截
|
|
|
|
// 请求拦截
|
|
|
|
uni.$u.http.interceptors.request.use((config) => {
|
|
|
|
http.interceptors.request.use((config) => {
|
|
|
|
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
|
|
|
|
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
|
|
|
|
config.data = config.data || {};
|
|
|
|
config.data = config.data || {};
|
|
|
|
config.custom = config.custom || {};
|
|
|
|
config.custom = config.custom || {};
|
|
|
|
@ -69,7 +70,7 @@ export const HttpConfig = ()=>{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 响应拦截
|
|
|
|
// 响应拦截
|
|
|
|
uni.$u.http.interceptors.response.use(async (response) => {
|
|
|
|
http.interceptors.response.use(async (response) => {
|
|
|
|
useCommonStore().hideLoading();
|
|
|
|
useCommonStore().hideLoading();
|
|
|
|
const data = response.data;
|
|
|
|
const data = response.data;
|
|
|
|
const custom = response.config.custom || {};
|
|
|
|
const custom = response.config.custom || {};
|
|
|
|
@ -114,4 +115,4 @@ export const HttpConfig = ()=>{
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const http = uni.$u.http;
|
|
|
|
export { http };
|