common.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. opsTask: {
  27. name: "任务列表",
  28. url: `${config.API_URL}/ops/opsTask`,
  29. get: async function (data = {}) {
  30. return await http.post(`${this.url}/getPage`, data);
  31. },
  32. stop: async function (data = {}) {
  33. return await http.post(`${this.url}/stopTask`, data);
  34. }
  35. },
  36. }
  37. function transformData(data) {
  38. return new Promise(resolve => {
  39. const reader = new FileReader();
  40. reader.readAsText(data, "UTF-8");
  41. reader.onload = () => {
  42. if (reader.result.includes("�")) {
  43. reader.readAsText(data, "GBK");
  44. reader.onload = () => resolve(reader.result);
  45. } else resolve(reader.result);
  46. };
  47. });
  48. }