history.api.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  8. /**
  9. * 获取列表的接口
  10. * @param deviceCode 设备编码,作为 strtype 传参
  11. * @param deviceInfo 设备信息,根据分站判别所用的 api
  12. * @param formData 表单数据
  13. * @param pagination 分页数据
  14. * @returns
  15. */
  16. const intervalMap = new Map([
  17. ['1', '1s'],
  18. ['2', '5s'],
  19. ['3', '10s'],
  20. ['4', '30s'],
  21. ['5', '1m'],
  22. ['6', '10m'],
  23. ['7', '30m'],
  24. ['8', '1h'],
  25. ]);
  26. export const list = (deviceCode: string, deviceInfo: any, formData: any, pagination: PaginationProps) => {
  27. if (deviceInfo.stationType === 'redis') {
  28. return defHttp.post({
  29. url: Api.getHistoryData,
  30. params: {
  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. });
  42. } else {
  43. return defHttp
  44. .get({
  45. url: Api.listdays,
  46. params: {
  47. pageNo: pagination.current,
  48. pageSize: pagination.pageSize,
  49. column: 'createTime',
  50. strtype: deviceCode,
  51. ...formData,
  52. },
  53. })
  54. .then((r) => {
  55. if (r.datalist) return r.datalist;
  56. return { total: 0, records: [] };
  57. });
  58. }
  59. };
  60. /**
  61. * 根据设备编码获取设备列表
  62. * @param params
  63. */
  64. export const getDeviceList = (params) =>
  65. defHttp.post({ url: Api.getDeviceList, params }).then((r) => {
  66. if (r.records && r.records.length) {
  67. return r.records;
  68. }
  69. if (r.msgTxt && r.msgTxt.length) {
  70. return r.msgTxt[0].datalist;
  71. }
  72. return [];
  73. });