فهرست منبع

fix 导出文件

Michael Wang 3 سال پیش
والد
کامیت
0f048d7ed8

+ 2 - 0
package.json

@@ -24,6 +24,7 @@
     "mitt": "^3.0.0",
     "moment": "^2.29.1",
     "pinia": "^2.0.0-rc.12",
+    "qs": "^6.10.1",
     "tailwindcss": "^2.2.10",
     "ua-parser-js": "^0.7.28",
     "vue": "^3.2.14",
@@ -35,6 +36,7 @@
     "@types/js-md5": "^0.4.3",
     "@types/lodash-es": "^4.17.4",
     "@types/node": "^16.10.3",
+    "@types/qs": "^6.9.7",
     "@types/ua-parser-js": "^0.7.36",
     "@vitejs/plugin-vue": "^1.9.3",
     "@vue/compiler-sfc": "^3.2.14",

+ 17 - 1
src/api/courseManagementPage.ts

@@ -1,4 +1,6 @@
 import { httpApp } from "@/plugins/axiosApp";
+import { responseToFile } from "@/utils/utils";
+import qs from "qs";
 
 /** 科目分页查询 */
 export function getCourseList(params: {
@@ -49,5 +51,19 @@ export function exportCourses(params: {
   name?: string;
   enable?: boolean;
 }) {
-  return httpApp.post(`/api/ess/course/export`, params);
+  return httpApp
+    .get(
+      `/api/ess/course/export?` + qs.stringify(params),
+      // new URLSearchParams([
+      //   ["rootOrgId", params.rootOrgId + ""],
+      //   ["code", params.code],
+      //   ["name", params.name],
+      //   ["type", params.type],
+      //   ["enable", params.enable + ""],
+      // ]),
+      { responseType: "blob" }
+    )
+    .then(function (response) {
+      return responseToFile(response);
+    });
 }

+ 12 - 4
src/api/projectParamsManagementPage.ts

@@ -1,4 +1,5 @@
 import { httpApp } from "@/plugins/axiosApp";
+import { responseToFile } from "@/utils/utils";
 
 /** 科目分页查询 */
 export function getProjectCourseList(params: {
@@ -20,10 +21,17 @@ export function importProjectParams(projectId: number, file: File) {
 
 /** 导出项目参数配置 */
 export function exportProjectParams(projectId: number) {
-  return httpApp.post(
-    `/api/ess/course/export`,
-    new URLSearchParams({ projectId: projectId + "" })
-  );
+  return httpApp
+    .post(
+      `/api/ess/course/export`,
+      new URLSearchParams({ projectId: projectId + "" }),
+      {
+        responseType: "blob",
+      }
+    )
+    .then(function (response) {
+      return responseToFile(response);
+    });
 }
 
 /** 更新科目 */

+ 10 - 2
src/api/subOrgPage.ts

@@ -1,4 +1,6 @@
 import { httpApp } from "@/plugins/axiosApp";
+import { responseToFile } from "@/utils/utils";
+import QueryString from "qs";
 
 /** 机构分页查询 */
 export function getSubOrgList(params: {
@@ -52,7 +54,13 @@ export function exportOrgs(params: {
   rootOrgId: number;
   code: string;
   name: string;
-  enable?: boolean;
+  enable: boolean;
 }) {
-  return httpApp.post(`/api/ess/org/export`, params);
+  return httpApp
+    .get(`/api/ess/org/export?` + QueryString.stringify(params), {
+      responseType: "blob",
+    })
+    .then(function (response) {
+      return responseToFile(response);
+    });
 }

+ 9 - 1
src/api/userManagementPage.ts

@@ -1,5 +1,7 @@
 import { httpApp } from "@/plugins/axiosApp";
 import { Privilege_Type } from "@/types";
+import { responseToFile } from "@/utils/utils";
+import QueryString from "qs";
 
 /** 用户分页查询 */
 export function getUserList(params: {
@@ -60,7 +62,13 @@ export function exportUsers(params: {
   name?: string;
   enable?: boolean;
 }) {
-  return httpApp.post(`/api/ess/user/export`, params);
+  return httpApp
+    .get(`/api/ess/user/export?` + QueryString.stringify(params), {
+      responseType: "blob",
+    })
+    .then(function (response) {
+      return responseToFile(response);
+    });
 }
 
 /** 用户科目/机构数据权限分页查询 */

+ 1 - 1
src/features/subOrg/SubOrg.vue

@@ -302,7 +302,7 @@ async function handleImport() {
 /** </handleImport> */
 
 async function handleExport() {
-  await exportOrgs({ rootOrgId, name, code, enable });
+  await exportOrgs({ rootOrgId, name, code, enable: true });
   message.success({ content: "导出成功" });
 }
 

+ 1 - 1
src/plugins/axiosApp.ts

@@ -24,7 +24,7 @@ const config = {
 const cacheGetUrls: [RegExp] | [] = [];
 
 const _axiosApp = axios.create(config);
-axiosRetry(_axiosApp);
+axiosRetry(_axiosApp, { retries: 3, retryDelay: () => 3000 });
 
 function gToken(
   method: "get" | "post",

+ 23 - 17
src/utils/utils.ts

@@ -1,32 +1,38 @@
 import { httpApp } from "@/plugins/axiosApp";
 import router from "@/router";
+import { AxiosResponse } from "axios";
 
 // 下载文件
 export async function downloadFileURL(url: string, name?: string) {
   return httpApp
     .get(url, { responseType: "blob" })
     .then((res) => {
-      const { data, headers } = res;
-      const fileName = headers["content-disposition"].replace(
-        /\w+;\s+filename=(.*)/,
-        "$1"
-      );
-      //Here, when the JSON file is returned, the JSON.stringify Processing, other types of files do not need to be processed
-      //const blob = new Blob([JSON.stringify(data)], ...)
-      const blob = new Blob([data], { type: headers["content-type"] });
-      let dom = document.createElement("a");
-      let url = window.URL.createObjectURL(blob);
-      dom.href = url;
-      dom.download = decodeURI(fileName);
-      dom.style.display = "none";
-      document.body.appendChild(dom);
-      dom.click();
-      dom.parentNode?.removeChild(dom);
-      window.URL.revokeObjectURL(url);
+      return responseToFile(res);
     })
     .catch((err) => {});
 }
 
+export async function responseToFile(response: AxiosResponse) {
+  return new Promise((resolve) => {
+    const { data, headers } = response;
+    const fileName = headers["content-disposition"].replace(
+      /\w+;\s*filename=(.*)/,
+      "$1"
+    );
+    //Here, when the JSON file is returned, the JSON.stringify Processing, other types of files do not need to be processed
+    //const blob = new Blob([JSON.stringify(data)], ...)
+    const blob = new Blob([data], { type: headers["content-type"] });
+    let dom = document.createElement("a");
+    let url = window.URL.createObjectURL(blob);
+    dom.href = url;
+    dom.download = decodeURI(fileName);
+    dom.style.display = "none";
+    document.body.appendChild(dom);
+    dom.click();
+    dom.parentNode?.removeChild(dom);
+    window.URL.revokeObjectURL(url);
+  });
+}
 // 返回
 export function goBack() {
   router.back();

+ 27 - 1
yarn.lock

@@ -170,6 +170,11 @@
   resolved "https://registry.nlark.com/@types/parse-json/download/@types/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
   integrity sha1-L4u0QUNNFjs1+4/9zNcTiSf/uMA=
 
+"@types/qs@^6.9.7":
+  version "6.9.7"
+  resolved "https://registry.nlark.com/@types/qs/download/@types/qs-6.9.7.tgz?cache=0&sync_timestamp=1629708766601&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fqs%2Fdownload%2F%40types%2Fqs-6.9.7.tgz#63bb7d067db107cc1e457c303bc25d511febf6cb"
+  integrity sha1-Y7t9Bn2xB8weRXwwO8JdUR/r9ss=
+
 "@types/throttle-debounce@^2.1.0":
   version "2.1.0"
   resolved "https://registry.nlark.com/@types/throttle-debounce/download/@types/throttle-debounce-2.1.0.tgz#1c3df624bfc4b62f992d3012b84c56d41eab3776"
@@ -531,7 +536,7 @@ bytes@^3.0.0:
   resolved "https://registry.npm.taobao.org/bytes/download/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
   integrity sha1-9s95M6Ng4FiPqf3oVlHNx/gF0fY=
 
-call-bind@^1.0.2:
+call-bind@^1.0.0, call-bind@^1.0.2:
   version "1.0.2"
   resolved "https://registry.npm.taobao.org/call-bind/download/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
   integrity sha1-sdTonmiBGcPJqQOtMKuy9qkZvjw=
@@ -1398,6 +1403,11 @@ object-hash@^2.2.0:
   resolved "https://registry.nlark.com/object-hash/download/object-hash-2.2.0.tgz?cache=0&sync_timestamp=1622019485009&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fobject-hash%2Fdownload%2Fobject-hash-2.2.0.tgz#5ad518581eefc443bd763472b8ff2e9c2c0d54a5"
   integrity sha1-WtUYWB7vxEO9djRyuP8unCwNVKU=
 
+object-inspect@^1.9.0:
+  version "1.11.0"
+  resolved "https://registry.nlark.com/object-inspect/download/object-inspect-1.11.0.tgz#9dceb146cedd4148a0d9e51ab88d34cf509922b1"
+  integrity sha1-nc6xRs7dQUig2eUauI00z1CZIrE=
+
 omit.js@^2.0.0:
   version "2.0.2"
   resolved "https://registry.npm.taobao.org/omit.js/download/omit.js-2.0.2.tgz#dd9b8436fab947a5f3ff214cb2538631e313ec2f"
@@ -1636,6 +1646,13 @@ purgecss@^4.0.3:
     postcss "^8.2.1"
     postcss-selector-parser "^6.0.2"
 
+qs@^6.10.1:
+  version "6.10.1"
+  resolved "https://registry.npm.taobao.org/qs/download/qs-6.10.1.tgz#4931482fa8d647a5aab799c5271d2133b981fb6a"
+  integrity sha1-STFIL6jWR6Wqt5nFJx0hM7mB+2o=
+  dependencies:
+    side-channel "^1.0.4"
+
 queue-microtask@^1.2.2:
   version "1.2.3"
   resolved "https://registry.npm.taobao.org/queue-microtask/download/queue-microtask-1.2.3.tgz?cache=0&sync_timestamp=1616391471040&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fqueue-microtask%2Fdownload%2Fqueue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
@@ -1749,6 +1766,15 @@ shallow-equal@^1.0.0:
   resolved "https://registry.npm.taobao.org/shallow-equal/download/shallow-equal-1.2.1.tgz#4c16abfa56043aa20d050324efa68940b0da79da"
   integrity sha1-TBar+lYEOqINBQMk76aJQLDaedo=
 
+side-channel@^1.0.4:
+  version "1.0.4"
+  resolved "https://registry.npm.taobao.org/side-channel/download/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"
+  integrity sha1-785cj9wQTudRslxY1CkAEfpeos8=
+  dependencies:
+    call-bind "^1.0.0"
+    get-intrinsic "^1.0.2"
+    object-inspect "^1.9.0"
+
 simple-swizzle@^0.2.2:
   version "0.2.2"
   resolved "https://registry.npm.taobao.org/simple-swizzle/download/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"