icenaked 3 лет назад
Родитель
Сommit
7561f1e8c9
5 измененных файлов с 91 добавлено и 31 удалено
  1. 1 12
      src/api/model.js
  2. 18 3
      src/api/prediction.js
  3. 11 0
      src/api/utils.js
  4. 6 4
      src/views/ml/ModelList.vue
  5. 55 12
      src/views/ml/PredictionList.vue

+ 1 - 12
src/api/model.js

@@ -136,18 +136,7 @@ export const getOneModel = async payload => {
         // const res=await axios.get(`${MOCK}/ml/models/:modelId/train`);
         return res;
     }
-    /**
-     * 使用模型预测 GET /model/use
-     * @param modelId
-     * @param fileId
-     * @returns
-     */
-    export const use = async data=>{
-        const {modelId,fileId}=data;
-        // const res=await axios.get(`${MODEL_MODULE}/use?fileId=${fileId}&modelId=${modelId}`);
-        const res=await axios.post(`${MOCK}/ml/predictions/predict:modelId=1&fileInfoId=2`);
-        return res;
-    }
+
 
 
 

+ 18 - 3
src/api/prediction.js

@@ -2,15 +2,30 @@ import {axios} from '../utils/request'
 import {MODEL_MODULE, PREDICTION_MODULE} from "./_prefix";
 import {MOCK} from "./_prefix";
 
+
+/**
+ * 使用模型预测 POST /model/use
+ * @param modelId
+ * @param fileId
+ * @returns
+ */
+export const use = async payload =>{
+    const {modelId, fileInfoId, userId}=payload;
+    const res=await axios.post(
+        `${PREDICTION_MODULE}/predict?modelId=${modelId}&fileInfoId=${fileInfoId}&userId=${userId}`
+    );
+    // const res=await axios.post(`${MOCK}/ml/predictions/predict:modelId=1&fileInfoId=2`);
+    return res;
+}
 /**
  * 获取某一个模型下的预测结果 GET
  * @param userId
  * @returns
  */
 export const getPrediction = async payload => {
-    const{ modelId } = payload;
-    // const res = await axios.get(`${MODEL_MODULE}/get/all`, {params: {userId: userId}})
-    const res = await axios.get(`${MOCK}/ml/predictions/models/:modelId`)
+    const{ modelId, userId } = payload;
+     const res = await axios.get(`${PREDICTION_MODULE}/models/${modelId}`, {params: {userId: userId}})
+    // const res = await axios.get(`${MOCK}/ml/predictions/models/:modelId`)
     return res
 }
 

+ 11 - 0
src/api/utils.js

@@ -5,4 +5,15 @@ import {MOCK} from "./_prefix";
 export const getEnum = () => {
     const res = axios.get(`${API_MODULE}/hello/enum`)
     return res
+}
+export const downloadFile = (payload) => {
+    const {fileUri} =payload
+    const res =axios.get(`${API_MODULE}/download?fileUri=${fileUri}`,{
+            headers:{
+                'Content-Type': "multipart/form-data;"
+                // 'Content-Type': "false",
+                // 'Process-Data': 'false',
+            }
+    })
+    return res
 }

+ 6 - 4
src/views/ml/ModelList.vue

@@ -146,7 +146,8 @@
 <script>
 import { ref, reactive } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
-import {getAllModel, getOneModel, train, use} from "../../api/model";
+import {getAllModel, getOneModel, train} from "../../api/model";
+import {use} from "../../api/prediction";
 import {GetAllFile} from "../../api/file";
 import {useRoute, useRouter} from "vue-router";
 import {deleteModel} from "../../api/model";
@@ -351,9 +352,10 @@ export default {
         //todo模型使用
      const useModel = (fileId) => {
       useModelVisible.value=false;
-       let data={
+       let payload={
         modelId:usemodelId.value,
-         fileId:fileId
+         fileInfoId:fileId,
+         userId: 1,
        }
        ElMessageBox( {
          title: "确定要预测吗?",
@@ -364,7 +366,7 @@ export default {
            if (action === 'confirm') {
              instance.confirmButtonLoading = true
              instance.confirmButtonText = '预测中...'
-             use(data).then(res=>{
+             use(payload).then(res=>{
                instance.confirmButtonLoading = false
                console.log("predic_res: ",res);
                if (res.msg === '成功')

+ 55 - 12
src/views/ml/PredictionList.vue

@@ -15,19 +15,32 @@
     >
       <el-table-column prop="modelId" label="模型id"></el-table-column>
       <el-table-column prop="createdTime" label="创建时间"></el-table-column>
-      <el-table-column prop="precitionState" label="预测状态"></el-table-column>
+      <el-table-column prop="predictionState" label="预测状态"></el-table-column>
       <el-table-column prop="finishTime" label="完成时间"></el-table-column>
 
       <el-table-column label="操作" width="180" align="center">
         <template #default="scope">
             <el-button type="text" icon="el-icon-download"
-                       @click="handleDownload(scope.row.predictedFileDownloadingUri)">下载
+                       @click="handleDownload(scope.row.predictionFileDownloadingUri)">下载
             </el-button>
         </template>
       </el-table-column>
     </el-table>
   </div>
 
+  <el-dialog v-model="downloadVisible" title="下载预测结果" width="30%">
+    <el-form width="300px">
+      <el-form-item label="文件名称" required>
+        <el-input v-model="fileName"></el-input>
+      </el-form-item>
+    </el-form>
+    <template #footer>
+          <span class="dialog-footer">
+            <el-button @click="downloadVisible = false">取消</el-button>
+            <el-button type="primary" @click="download" style="margin-left: 10px"> 下载 </el-button>
+          </span>
+    </template>
+  </el-dialog>
 
 </div>
 </template>
@@ -36,6 +49,7 @@
 import {getPrediction} from "../../api/prediction";
 import {useRoute} from "vue-router";
 import {ref} from "vue";
+import {downloadFile} from "../../api/utils";
 
 export default {
   name: "PredictionList",
@@ -44,28 +58,57 @@ export default {
     const tableData = ref([]);
 
     const getPage = () => {
-      getPrediction({modelId: route.query.modelId}).then(res => {
-        tableData.value=res.result.PredictionVOList;
+      const payload={
+        modelId: route.query.modelId ,
+        userId: 1
+      }
+      getPrediction(payload).then(res => {
+        tableData.value=res.result;
       })
     }
     getPage();
+    let fileName = ref('')
+    let downloadUri = ref()
+    let downloadVisible = ref(false)
 
     const handleDownload=(url)=>{
-      const a = document.createElement('a')
-      a.href = url
-      //a.download = res.success.fileName // 下载后文件名
-      a.style.display = 'none'
-      document.body.appendChild(a)
-      a.click() // 点击下载
-      document.body.removeChild(a)
+      downloadVisible.value =true
+      downloadUri.value = url
+    }
+    const download = () =>{
+      const payload={
+        fileUri: downloadUri.value
+      }
+      downloadFile(payload).then(data=>{
+        downloadVisible.value = false
+        let file = new Blob(["\ufeff" + data], { type: 'text/csv'});
+        if (window.navigator.msSaveOrOpenBlob)
+            // IE10+
+          window.navigator.msSaveOrOpenBlob(file, fileName.value);
+        else {
+          // Others
+          let a = document.createElement("a"),
+              url = URL.createObjectURL(file);
+          a.href = url;
+          a.download = fileName.value;
+          document.body.appendChild(a);
+          a.click();
+          setTimeout(function() {
+            document.body.removeChild(a);
+            window.URL.revokeObjectURL(url);
+          }, 0);
+        }
+      })
     }
-
 
     return {
       route,
       tableData,
+      fileName,
+      downloadVisible,
       getPage,
       handleDownload,
+      download,
     };
   },
 }