dumu.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { stringify } from 'qs';
  2. import { request } from 'umi';
  3. export async function getList(projectId) {
  4. const res = await request(`/api/v1/dumu/pull-msg/${projectId}`);
  5. res.data.forEach((item) => {
  6. item.url = base64ToImageUrl(item.event_bg);
  7. });
  8. return res.data;
  9. }
  10. export async function getAlarmList(data) {
  11. const res = await request(`/api/task/v1/grade-alarm/list`, {
  12. method: 'POST',
  13. data,
  14. });
  15. return res.data;
  16. }
  17. function base64ToImageUrl(base64String) {
  18. const byteCharacters = atob(base64String);
  19. const byteArrays = [];
  20. for (let i = 0; i < byteCharacters.length; i++) {
  21. byteArrays.push(byteCharacters.charCodeAt(i));
  22. }
  23. const byteArray = new Uint8Array(byteArrays);
  24. const blob = new Blob([byteArray], { type: 'image/png' });
  25. const imageUrl = URL.createObjectURL(blob);
  26. return imageUrl;
  27. }
  28. export async function getHistoryList(projectId, params) {
  29. const res = await request(
  30. `/api/v1/dumu/list/${projectId}?${stringify(params)}`,
  31. );
  32. res.data.list.forEach((item) => {
  33. item.url = base64ToImageUrl(item.event_bg);
  34. });
  35. return res.data.list;
  36. }
  37. export async function getCameraList(projectId, params) {
  38. const res = await request(
  39. `/api/v1/dumu/list/${projectId}?${stringify(params)}`,
  40. );
  41. return res.data;
  42. }
  43. export async function getDetail(detailId, options) {
  44. const res = await request(`/api/v1/dumu/detail/${detailId}`, options);
  45. return res.data;
  46. }