| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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>;
- };
|