configurable.api.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { defHttp } from '/@/utils/http/axios';
  2. enum Api {
  3. list = '/safety/ventanalyDevice/homedata2',
  4. getHomeData = '/safety/ventanalyDevice/homedata',
  5. getBDDustData = '/ventanaly-device/monitor/disaster/getDisDustHome',
  6. getBDFireData = '/ventanaly-device/monitor/disaster/getDisFireHome',
  7. }
  8. // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。
  9. // 这会导致相同的请求被同时发送多次。
  10. const cache = new Map<string, Promise<any>>();
  11. /**
  12. * 列表接口
  13. * @param params
  14. */
  15. export const list = (params) => defHttp.post({ url: Api.list, params });
  16. export const getHomeData = (params) => {
  17. const key = `${Api.getHomeData}?${JSON.stringify(params)}`;
  18. if (!cache.has(key)) {
  19. cache.set(
  20. key,
  21. defHttp.post({ url: Api.getHomeData, params }).finally(() => {
  22. cache.delete(key);
  23. })
  24. );
  25. }
  26. return cache.get(key) as Promise<any>;
  27. };
  28. export const getBDDustData = (params) => {
  29. const key = `${Api.getBDDustData}?${JSON.stringify(params)}`;
  30. if (!cache.has(key)) {
  31. cache.set(
  32. key,
  33. defHttp.post({ url: Api.getBDDustData, params }).finally(() => {
  34. cache.delete(key);
  35. })
  36. );
  37. }
  38. return cache.get(key) as Promise<any>;
  39. };
  40. export const getBDFireData = (params) => {
  41. const key = `${Api.getBDFireData}?${JSON.stringify(params)}`;
  42. if (!cache.has(key)) {
  43. cache.set(
  44. key,
  45. defHttp.post({ url: Api.getBDFireData, params }).finally(() => {
  46. cache.delete(key);
  47. })
  48. );
  49. }
  50. return (cache.get(key) as Promise<any>).then((res) => {
  51. res.pdArray.forEach((e) => {
  52. e.arrayFiber.forEach((j) => {
  53. j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
  54. });
  55. });
  56. res.sgGxObj.devGxcw.forEach((e) => {
  57. e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
  58. });
  59. res.sgGxObj.devSgjc.forEach((e) => {
  60. e.o2val = e.o2Val || 0;
  61. e.coval = e.coVal || 0;
  62. e.gasval = e.gasVal || 0;
  63. e.ch2val = e.ch2Val || 0;
  64. e.chval = e.chVal || 0;
  65. });
  66. return res;
  67. });
  68. };