common.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. up: async function (data, config = {}) {
  30. return await http.post(`${this.url}/uploadAihazard`, data, config);
  31. },
  32. rm: async function (fileName) {
  33. return await http.post(`${this.url}/remove`, { fileName });
  34. },
  35. download: async function (entityID) {
  36. return await http.get(`${this.url.replace("/ops", "")}${entityID}`, {}, { responseType: "blob" });
  37. }
  38. },
  39. opsTask: {
  40. name: "任务列表",
  41. url: `${config.API_URL}/ops/opsTask`,
  42. get: async function (data = {}) {
  43. return await http.post(`${this.url}/getPage`, data);
  44. },
  45. stop: async function (data = {}) {
  46. return await http.post(`${this.url}/stopTask`, data);
  47. }
  48. },
  49. }
  50. function transformData(data) {
  51. return new Promise(resolve => {
  52. const reader = new FileReader();
  53. reader.readAsText(data, "UTF-8");
  54. reader.onload = () => {
  55. if (reader.result.includes("�")) {
  56. reader.readAsText(data, "GBK");
  57. reader.onload = () => resolve(reader.result);
  58. } else resolve(reader.result);
  59. };
  60. });
  61. }