history.api.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { PaginationProps } from '/@/components/Table';
  2. import { defHttp } from '/@/utils/http/axios';
  3. enum Api {
  4. getHistory = '/dataCenter/safety/ventanalyMonitorData/getRealHistory',
  5. getDeviceList = '/monitor/device',
  6. }
  7. /**
  8. * 获取列表的接口
  9. * @param deviceCode 设备编码,作为 strtype 传参
  10. * @param deviceInfo 设备信息,根据分站判别所用的 api
  11. * @param formData 表单数据
  12. * @param pagination 分页数据
  13. * @returns
  14. */
  15. const intervalMap = new Map([
  16. ['1', '1s'],
  17. ['2', '5s'],
  18. ['3', '10s'],
  19. ['4', '30s'],
  20. ['5', '1m'],
  21. ['6', '10m'],
  22. ['7', '30m'],
  23. ['8', '1h'],
  24. ]);
  25. /**
  26. * 根据所给设备的分站信息、设备编码等信息生成历史数据/数据导出api所需的请求参数
  27. * @param deviceCode
  28. * @param deviceInfo
  29. * @param formData
  30. * @param pagination
  31. * @returns
  32. */
  33. export const adaptFormData = (deviceCode: string, deviceInfo: any, formData: any, pagination: PaginationProps) => {
  34. if (deviceInfo.stationtype === 'redis') {
  35. return {
  36. pageNum: pagination.current,
  37. pageSize: pagination.pageSize,
  38. column: 'createTime',
  39. startTime: formData.ttime_begin,
  40. endTime: formData.ttime_end,
  41. deviceId: formData.gdeviceids,
  42. strtype: deviceCode,
  43. isEmployee: deviceCode.startsWith('vehicle') ? false : true,
  44. };
  45. } else {
  46. return {
  47. pageNo: pagination.current,
  48. pageSize: pagination.pageSize,
  49. column: 'createTime',
  50. strtype: deviceCode,
  51. ...formData,
  52. };
  53. }
  54. };
  55. // 获取历史数据
  56. export const getHistoryList = (params) =>
  57. defHttp.get({
  58. url: Api.getHistory,
  59. params,
  60. });
  61. /**
  62. * 根据设备编码获取设备列表
  63. * @param params
  64. */
  65. export const getDeviceList = (params) =>
  66. defHttp.post({ url: Api.getDeviceList, params }).then((r) => {
  67. if (r.records && r.records.length) {
  68. return r.records;
  69. }
  70. if (r.msgTxt && r.msgTxt.length) {
  71. return r.msgTxt[0].datalist;
  72. }
  73. return [];
  74. });