history.api.ts 2.5 KB

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