sys.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { UPLOAD_FILE, UPLOAD_HEADS, CASE_INFO, AUTH_PWD } from "./constant";
  2. import { axios } from "./instance";
  3. import { jsonToForm } from "@/utils";
  4. import { params } from "@/env";
  5. type UploadFile = LocalFile | string;
  6. export const blobToFile = (blob: Blob, suffix = ".png") =>
  7. new File([blob], `aaa${suffix}`);
  8. export const uploadFile = async (file: UploadFile, suffix = ".png") => {
  9. if (typeof file === "string") {
  10. return file;
  11. } else {
  12. const uploadFile =
  13. file.blob instanceof File ? file.blob : blobToFile(file.blob, suffix);
  14. console.log(uploadFile)
  15. const url = await axios<string>({
  16. method: "POST",
  17. url: UPLOAD_FILE,
  18. data: jsonToForm({ file: uploadFile }),
  19. headers: { ...UPLOAD_HEADS },
  20. });
  21. return url;
  22. }
  23. };
  24. export enum FireStatus {
  25. incomplete = 0,
  26. complete = 1,
  27. }
  28. export type FireProject = {
  29. accidentDate: string;
  30. createTime: string;
  31. creatorDeptId: string;
  32. caseId: number;
  33. creatorId: string;
  34. creatorName: string;
  35. deptId: string;
  36. editTime: string;
  37. editorId: string;
  38. editorName: string;
  39. fireReason: string;
  40. id: string;
  41. isTeached: number;
  42. organizerDeptName: string;
  43. organizerUsers: string;
  44. projectAddress: string;
  45. projectName: string;
  46. projectSite: string;
  47. projectSiteCode: string;
  48. projectSn: string;
  49. status: FireStatus;
  50. statusDesc: string;
  51. updateTime: string;
  52. isDelete?: number;
  53. latlng?: string
  54. field1: string;
  55. field2: string;
  56. field3: string;
  57. field4: string;
  58. field5: string;
  59. field6: string;
  60. field7: string;
  61. field8: string;
  62. field9: string;
  63. field10: string;
  64. };
  65. export interface Case {
  66. caseTitle: string;
  67. tmProject?: FireProject;
  68. }
  69. export const getCaseInfo = () =>
  70. axios.get<Case>(CASE_INFO, { params: { caseId: params.caseId } });
  71. // 校验密码
  72. export const authSharePassword = (randCode: string) =>
  73. axios<boolean>(AUTH_PWD, { params: { randCode, caseId: params.caseId } });