/* * @Author: wjc * @Date: 2023-11-17 11:46:48 * @LastEditors: LiZhiWei * @LastEditTime: 2026-01-09 15:40:43 * @Description: */ import type { FetchContext, FetchResponse } from 'ofetch' import { apiBase } from '~/constants' import Request from './request' import { checkStatus } from './checkStatus' import whiteList from './whiteList' const http = new Request({ baseURL: `${apiBase}`, interceptor: { // 请求前钩子函数 onRequest({ request, options }: FetchContext) { const isHas = whiteList.find((item) => (request as string).includes(item)) if (isHas) { options.headers = { ...options.headers, Authorization: '', } as any } }, // 响应错误拦截 onResponseError({ response }: FetchContext & { response: FetchResponse }) { if (response?.status && response?.status !== 401) { checkStatus(response?.status, response._data?.message || '服务不可用,请稍候再试') } }, }, }) export { http }