common.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import axios from "axios";
  2. import config from "@/config"
  3. import http from "@/utils/request"
  4. export default {
  5. folder: {
  6. url: `${config.API_URL}/api/folder`,
  7. name: "文件上传",
  8. up: async function (data, config = {}) {
  9. return await http.post(`${this.url}/up`, data, config);
  10. },
  11. rm: async function (entityID) {
  12. return await http.post(`${this.url}/rm`, { querys: [], expands: { entityID } });
  13. },
  14. download: async function (entityID, isTxt = false) { // url: string, isTxt: txt解码
  15. const config = {
  16. responseType: "blob",
  17. transformResponse: isTxt && [
  18. async function (data) {
  19. return await transformData(data);
  20. }
  21. ] || []
  22. }
  23. return await http.get(`${this.url}/${entityID}`, {}, config);
  24. }
  25. },
  26. minio: {
  27. url: `${config.API_URL}/ops/minio`,
  28. name: "文件上传",
  29. airecord: async function (data, config = {}) {
  30. return await http.post(`${this.url}/uploadAihazard`, data, config);
  31. },
  32. parking: async function (data, config = {}) {
  33. return await http.post(`${this.url}/uploadParking`, data, config);
  34. },
  35. rm: async function (fileName) {
  36. return await http.post(`${this.url}/remove`, { fileName });
  37. },
  38. download: async function (entityID) {
  39. return await http.get(`${this.url.replace("/ops", "")}${entityID}`, {}, { responseType: "blob" });
  40. }
  41. },
  42. opsTask: {
  43. name: "任务列表",
  44. url: `${config.API_URL}/ops/opsTask`,
  45. get: async function (data = {}) {
  46. return await http.post(`${this.url}/getPage`, data);
  47. },
  48. stop: async function (data = {}) {
  49. return await http.post(`${this.url}/stopTask`, data);
  50. }
  51. },
  52. }
  53. function transformData(data) {
  54. return new Promise(resolve => {
  55. const reader = new FileReader();
  56. reader.readAsText(data, "UTF-8");
  57. reader.onload = () => {
  58. if (reader.result.includes("�")) {
  59. reader.readAsText(data, "GBK");
  60. reader.onload = () => resolve(reader.result);
  61. } else resolve(reader.result);
  62. };
  63. });
  64. }