import { defHttp } from '/@/utils/http/axios'; enum Api { list = '/safety/ventanalyDevice/homedata2', getHomeData = '/safety/ventanalyDevice/homedata', getDisHome = '/ventanaly-device/monitor/disaster/getDisHome', 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).then((res) => { res.fanmain.forEach((e) => { if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanFreqHz = e.readData.Fan2FreqHz; } else { e.current = '一号'; e.readData.FanFreqHz = e.readData.Fan1FreqHz; } }); res.fanlocal.forEach((e) => { if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanfHz = e.readData.Fan2fHz; } else { e.current = '一号'; e.readData.FanfHz = e.readData.Fan1fHz; } }); res.sys_majorpath.forEach((e) => { e.piechart = [ { val: e.majorpath.drag_1, label: '进风区' }, { val: e.majorpath.drag_2, label: '用风区' }, { val: e.majorpath.drag_3, label: '回风区' }, ]; }); return res; }); }; 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; }); }; export const getDisHome = (params) => { const key = `${Api.getDisHome}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.getDisHome, params }).finally(() => { cache.delete(key); }) ); } return (cache.get(key) as Promise).then((res) => { if (res.pdArray) { res.pdArray.forEach((e) => { e.arrayFiber.forEach((j) => { j.fibreTemperatureArr = JSON.parse(j.fibreTemperature); }); }); } if (res.sgGxObj) { 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; }); } if (res.obfObj) { res.obfObj.obfObjModded = [ { objType: '甲烷', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.ch4Val || 0, }; }), }, { objType: '一氧化碳', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.coVal || 0, }; }), }, { objType: '乙炔', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.c2h2Val || 0, }; }), }, { objType: '二氧化碳', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.co2Val || 0, }; }), }, { objType: '氧气', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.o2Val || 0, }; }), }, { objType: '乙烯', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.c2h4Val || 0, }; }), }, ]; } return res; }); };