series.ts 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { http } from './http'
  2. export interface PksSeries {
  3. device_code: string
  4. start: string
  5. end: string
  6. count: number
  7. times: string[]
  8. oil: (number | null)[]
  9. coupling: (number | null)[]
  10. chain: (number | null)[]
  11. }
  12. export async function fetchPksSeries(
  13. deviceCode: string,
  14. start: string,
  15. end: string,
  16. onProgress?: (percent: number) => void,
  17. ): Promise<PksSeries> {
  18. const res = await http.get<PksSeries>('/api/pks-series', {
  19. params: { device_code: deviceCode, start, end },
  20. onDownloadProgress: (event) => {
  21. if (onProgress && event.total) {
  22. onProgress(Math.round((event.loaded / event.total) * 100))
  23. }
  24. },
  25. })
  26. onProgress?.(100)
  27. return res.data
  28. }
  29. export async function fetchRecentSeries(deviceCode: string, hours = 6): Promise<PksSeries> {
  30. const res = await http.get<PksSeries>('/api/recent-series', {
  31. params: { device_code: deviceCode, hours },
  32. })
  33. return res.data
  34. }