configurable.api.ts 831 B

1234567891011121314151617181920212223242526272829
  1. import { defHttp } from '/@/utils/http/axios';
  2. enum Api {
  3. list = '/safety/ventanalyDevice/homedata2',
  4. getHomeData = '/safety/ventanalyDevice/homedata',
  5. }
  6. // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。
  7. // 这会导致相同的请求被同时发送多次。
  8. const cache = new Map<string, Promise<any>>();
  9. /**
  10. * 列表接口
  11. * @param params
  12. */
  13. export const list = (params) => defHttp.post({ url: Api.list, params });
  14. export const getHomeData = (params) => {
  15. const key = `${Api.getHomeData}?${JSON.stringify(params)}`;
  16. if (!cache.has(key)) {
  17. cache.set(
  18. key,
  19. defHttp.post({ url: Api.getHomeData, params }).finally(() => {
  20. cache.delete(key);
  21. })
  22. );
  23. }
  24. return cache.get(key) as Promise<any>;
  25. };