RequestApiConfig.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * 请求的默认配置
  3. *
  4. * 说明:
  5. * 此处提供的是请求中的默认配置。
  6. *
  7. * Author: imengyu
  8. * Date: 2022/03/25
  9. *
  10. * Copyright (c) 2021 imengyu.top. Licensed under the MIT License.
  11. * See License.txt in the project root for license information.
  12. */
  13. import ApiCofig from "@/common/config/ApiCofig";
  14. import { isDev } from "@/common/config/AppCofig";
  15. import type { KeyValue } from "@imengyu/js-request-transform/dist/DataUtils";
  16. interface ApiConfigInterface {
  17. /**
  18. * 默认转换日期的格式
  19. */
  20. DataDateFormat: string,
  21. /**
  22. * 所有请求默认携带的header
  23. */
  24. DefaultHeader: KeyValue,
  25. /**
  26. * 是否在在控制台上打印出请求信息
  27. */
  28. EnableApiRequestLog: boolean,
  29. /**
  30. * 是否在每一个请求都在控制台上打印出休息数据
  31. */
  32. EnableApiDataLog: boolean,
  33. /**
  34. * 基础请求地址
  35. */
  36. BaseUrl: string;
  37. }
  38. const defaultConfig = {
  39. BaseUrl: isDev ? ApiCofig.serverDev : ApiCofig.serverProd,
  40. DataDateFormat: 'YYYY-MM-DD HH:mm:ss',
  41. DefaultHeader: {},
  42. EnableApiRequestLog: true,
  43. EnableApiDataLog: false,
  44. } as ApiConfigInterface;
  45. let config = defaultConfig;
  46. /**
  47. * 请求中的默认配置
  48. */
  49. const RequestApiConfig = {
  50. getConfig() : ApiConfigInterface { return config; },
  51. setConfig(newConfig: ApiConfigInterface): void { config = newConfig; },
  52. };
  53. export default RequestApiConfig;