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>(); /** * 列表接口 * @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; }; 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; }; 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).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); }); res.sgGxObj.devSgjc.forEach((e) => { e.o2val = e.o2Val || 0; e.coval = e.coVal || 0; e.gasval = e.gasVal || 0; e.ch2val = e.ch2Val || 0; e.chval = e.chVal || 0; }); return res; }); };