1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { defHttp } from '/@/utils/http/axios';
- enum Api {
- list = '/safety/ventanalyDevice/homedata2',
- getHomeData = '/safety/ventanalyDevice/homedata',
- getBDDustData = '/ventanaly-device/monitor/disaster/getDisDustHome',
- getBDFireData = '/ventanaly-device/monitor/disaster/getDisFireHome',
- }
- // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。
- // 这会导致相同的请求被同时发送多次。
- const cache = new Map<string, Promise<any>>();
- /**
- * 列表接口
- * @param params
- */
- export const list = (params) => defHttp.post({ url: Api.list, params });
- export const getHomeData = (params) => {
- const key = `${Api.getHomeData}?${JSON.stringify(params)}`;
- if (!cache.has(key)) {
- cache.set(
- key,
- defHttp.post({ url: Api.getHomeData, params }).finally(() => {
- cache.delete(key);
- })
- );
- }
- return cache.get(key) as Promise<any>;
- };
- export const getBDDustData = (params) => {
- const key = `${Api.getBDDustData}?${JSON.stringify(params)}`;
- if (!cache.has(key)) {
- cache.set(
- key,
- defHttp.post({ url: Api.getBDDustData, params }).finally(() => {
- cache.delete(key);
- })
- );
- }
- return cache.get(key) as Promise<any>;
- };
- export const getBDFireData = (params) => {
- const key = `${Api.getBDFireData}?${JSON.stringify(params)}`;
- if (!cache.has(key)) {
- cache.set(
- key,
- defHttp.post({ url: Api.getBDFireData, params }).finally(() => {
- cache.delete(key);
- })
- );
- }
- return (cache.get(key) as Promise<any>).then((res) => {
- res.pdArray.forEach((e) => {
- e.arrayFiber.forEach((j) => {
- j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
- });
- });
- res.sgGxObj.devGxcw.forEach((e) => {
- e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
- });
- return res;
- });
- };
|