From da51e7d5bbf5ff1610209510571e94d0523b515c Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 24 四月 2024 17:40:37 +0800
Subject: [PATCH] 完善自动评估模块,规范性分析报告的后台任务和结果下载逻辑

---
 src/api/fysp/evaluateApi.js |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/api/fysp/evaluateApi.js b/src/api/fysp/evaluateApi.js
index 6e752a6..26414ca 100644
--- a/src/api/fysp/evaluateApi.js
+++ b/src/api/fysp/evaluateApi.js
@@ -1,3 +1,4 @@
+import { Base64 } from 'js-base64';
 import { $fysp } from '../index';
 
 export default {
@@ -6,5 +7,49 @@
    */
   fetchAutoEvaluation(param) {
     return $fysp.post(`evaluation/auto/record`, param).then((res) => res.data);
+  },
+
+  /**
+   * 鏍规嵁宸℃煡浠诲姟鑾峰彇璇勫垎缁嗗垯
+   */
+  
+
+  /**
+   * 鏌ヨ璇勪及鎬昏鍒�
+   * @param {Object} param
+   * @returns
+   */
+  fetchEvaluationRule(param) {
+    return $fysp.post(`evaluationrule/find`, param).then((res) => res.data);
+  },
+
+  autoEvaluate(param) {
+    return $fysp.post(`evaluation/auto`, param).then((res) => res.data);
+  },
+
+  /**
+   * 涓嬭浇瑙勮寖鎬ц瘎浼颁笌鍒嗘瀽鎶ュ憡
+   */
+  downloadAutoEvaluation(param, forceUpdate) {
+    return $fysp
+      .post(`evaluation/auto/record/download?forceUpdate=${forceUpdate}`, param, { responseType: 'blob' })
+      .then((res) => {
+        // 鏂囨。鏈敓鎴愶紝宸插惎鍔ㄦ枃妗g敓鎴愬悗鍙颁换鍔�
+        if (res.data.type == 'application/json') {
+          return false
+        } 
+        // 鏂囨。宸插瓨鍦紝鐩存帴涓嬭浇
+        else {
+          const name = Base64.decode(res.headers.get('filename'));
+          const url = window.URL.createObjectURL(res.data);
+          const link = document.createElement('a');
+          link.href = url;
+          link.setAttribute('download', name);
+          document.body.appendChild(link);
+          link.click();
+          document.body.removeChild(link);
+          window.URL.revokeObjectURL(url);
+        }
+      });
   }
 };

--
Gitblit v1.9.3