index.ts 659 B

12345678910111213141516171819202122232425
  1. /*
  2. * @Author: wjc
  3. * @Date: 2023-11-17 11:46:48
  4. * @LastEditors: LiZhiWei
  5. * @LastEditTime: 2026-01-09 15:40:43
  6. * @Description:
  7. */
  8. import type { FetchContext, FetchResponse } from 'ofetch'
  9. import { apiBase } from '~/constants'
  10. import Request from './request'
  11. import { checkStatus } from './checkStatus'
  12. const http = new Request({
  13. baseURL: `${apiBase}`,
  14. interceptor: {
  15. // 响应错误拦截
  16. onResponseError({ response }: FetchContext & { response: FetchResponse<any> }) {
  17. if (response?.status) {
  18. checkStatus(response?.status, response._data?.message || '服务不可用,请稍候再试')
  19. }
  20. },
  21. },
  22. })
  23. export { http }