interface.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * @Author: wjc
  3. * @Date: 2023-11-27 15:35:24
  4. * @LastEditors: LiZhiWei
  5. * @LastEditTime: 2026-01-09 15:47:12
  6. * @Description:
  7. */
  8. import type { UseFetchOptions } from '#app'
  9. import type { BasicResponse } from '@/models/common'
  10. export type _AsyncData<DataT, ErrorT> = {
  11. data: Ref<DataT | null>
  12. pending: Ref<boolean>
  13. refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
  14. execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
  15. error: Ref<ErrorT | null>
  16. }
  17. interface AsyncDataExecuteOptions {
  18. dedupe?: boolean
  19. }
  20. export type IInterceptor = {
  21. onRequest?: UseFetchOptions<any>['onRequest']
  22. onRequestError?: UseFetchOptions<any>['onRequestError']
  23. onResponse?: UseFetchOptions<any>['onResponse']
  24. onResponseError?: UseFetchOptions<any>['onResponseError']
  25. }
  26. export interface IConfig {
  27. baseURL: any
  28. interceptor?: IInterceptor
  29. }
  30. type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'get' | 'post' | 'put' | 'delete'
  31. export interface IOption<T> {
  32. url: string
  33. method?: Methods
  34. params?: any // query
  35. data?: any // body
  36. options?: UseFetchOptions<T>
  37. }
  38. export type RequestQueueItem<T = BasicResponse> = {
  39. url: string
  40. options: UseFetchOptions<T>
  41. resolve: (data: T) => void
  42. reject: (data: unknown) => void
  43. }