| | |
| | | import website from '@/config/website' |
| | | import { Base64} from 'js-base64' |
| | | |
| | | const http = new Request() |
| | | const httpGd = new Request() |
| | | |
| | | export function request (config) { |
| | | return new Promise((resolve, reject) => { |
| | | http |
| | | httpGd |
| | | .request(config) |
| | | .then(res => { |
| | | resolve(res) |
| | |
| | | |
| | | |
| | | // 请求拦截器 |
| | | function requestInterceptors(http) { |
| | | function requestInterceptors(httpGd) { |
| | | |
| | | http.interceptors.request.use((config) => { |
| | | httpGd.interceptors.request.use((config) => { |
| | | const {detail} = useUserStore().$state?.userInfo || {} |
| | | // 假设有token值需要在头部需要携带 |
| | | let accessToken = useUserStore()?.$state?.userInfo?.gd_access_token; |
| | |
| | | }) |
| | | } |
| | | |
| | | function responseInterceptors(http) { |
| | | http.interceptors.response.use((response) => { |
| | | function responseInterceptors(httpGd) { |
| | | httpGd.interceptors.response.use((response) => { |
| | | let res = response |
| | | const status = res.data.error_code || res.data.code || res.statusCode |
| | | const message = res?.data?.msg || res?.data?.error_description || res?.data?.message || '系统错误' |
| | |
| | | |
| | | // 引入拦截器配置 |
| | | export function setupRequest () { |
| | | http.setConfig(defaultConfig => { |
| | | httpGd.setConfig(defaultConfig => { |
| | | |
| | | /* defaultConfig 为默认全局配置 */ |
| | | defaultConfig.baseURL = getEnvObj().VITE_API_BASE_URL_GD |
| | | // #ifdef H5 |
| | |
| | | // #endif |
| | | return defaultConfig |
| | | }) |
| | | requestInterceptors(http) |
| | | responseInterceptors(http) |
| | | requestInterceptors(httpGd) |
| | | responseInterceptors(httpGd) |
| | | } |
| | | |
| | | |