ajax.d.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { PlainObject } from "../types";
  2. export declare type ApiMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'download' | 'post-json' | 'post-file' | 'invoke' | 'sql' | string;
  3. export declare type ApiDataType = 'json' | 'form-data' | 'form';
  4. export interface ApiObject {
  5. url: string;
  6. param: PlainObject;
  7. method: ApiMethod;
  8. data?: object;
  9. args: any[];
  10. db?: string;
  11. headers?: PlainObject;
  12. filterModel?: {
  13. [key: string]: any;
  14. };
  15. sortModel?: {
  16. colId: string | undefined;
  17. sort: string | null | undefined;
  18. }[];
  19. config?: {
  20. withCredentials?: boolean;
  21. cancelExecutor?: (cancel: Function) => void;
  22. };
  23. dataType?: ApiDataType;
  24. /**
  25. * 下载文件名
  26. */
  27. fileName?: string;
  28. /**
  29. * 上传文件(如果需要的话)
  30. */
  31. file?: any;
  32. }
  33. export declare type ApiFunction = (api: ApiObject) => Promise<ApiResult>;
  34. /**
  35. * 组件中 Api 的声明
  36. */
  37. export declare type Api = ApiFunction | ApiObject;
  38. export interface ApiResult {
  39. rawData: object;
  40. status: number;
  41. headers: object;
  42. data?: any;
  43. pagination?: any;
  44. success: boolean;
  45. msg: string;
  46. errors?: {
  47. [propName: string]: string;
  48. };
  49. }
  50. export interface CreateAjaxOption {
  51. baseUrl: string;
  52. timeout: number;
  53. }
  54. /**
  55. * 创建一个 Ajax 客户端
  56. */
  57. export declare function createAjax(createOption: CreateAjaxOption): ApiFunction;
  58. export declare function downLoad(downLoadUrl: string, filename: string, data: any, header: any, isJson?: boolean): void;