Browse Source

fix: call use() only once

icenaked 3 years ago
parent
commit
286f7e50a5
3 changed files with 36 additions and 14 deletions
  1. 1 1
      src/router/index.js
  2. 29 7
      src/views/BaseCharts.vue
  3. 6 6
      src/views/ModelList.vue

+ 1 - 1
src/router/index.js

@@ -80,7 +80,7 @@ const routes = [
                 meta: {
                     title: '训练结果'
                 },
-                component: () => import ( /* webpackChunkName: "charts" */ "../views/unused/BaseCharts.vue")
+                component: () => import ( /* webpackChunkName: "charts" */ "../views/BaseCharts.vue")
             },
             {
                 path: "/form",

+ 29 - 7
src/views/unused/BaseCharts.vue → src/views/BaseCharts.vue

@@ -34,9 +34,9 @@
 <script>
 import { ref, reactive } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
-import { fetchData,fetchModuleDetail } from "../../api";
+import { fetchData,fetchModuleDetail } from "../api";
 import {useRoute} from "vue-router";
-import {use}from "../../api/model"
+import {use}from "../api/model"
 
 export default {
     
@@ -64,12 +64,34 @@ export default {
             modelId:modelId,
             fileId:fileId
           }
-          use(data).then(res=>{
-            console.log(res.data);
-            tableData.value=res.data
+          ElMessageBox({
+            title: "正在拼命预测!",
+            beforeClose: (action, instance, done) => {
+              instance.confirmButtonLoading = true
+              instance.confirmButtonText = '预测中...'
+              use(data).then(res=>{
+                instance.confirmButtonLoading = false
+                if (res.status === 200)
+                {
+                  ElMessageBox({
+                    title: '模型使用',
+                    message: `模型预测成功`,
+                    confirmButtonText: '确定',
+                  })
+                  done()
+                }
+                else
+                {
+                  console.log(res);
+                  ElMessage.error("预测失败!失败码:"+res.status);
+                  done()
+                }
+                console.log(res.data);
+                tableData.value=res.data
+              });
+              //console.log("getData被调用了")
+            }
           })
-            console.log("getData被调用了")
-
         };
 
         // 相当于beforeCreated生命周期中调用了getData()函数

+ 6 - 6
src/views/ModelList.vue

@@ -247,13 +247,13 @@ const usemodelId=ref();
         modelId:usemodelId.value,
          fileId:useform.file
        }
-       use(data).then(res=>{
-         console.log(res.data);
-       })
-      // const router=useRouter()
-      // const fileId=useform.file
+       // use(data).then(res=>{
+       //   console.log(res.data);
+       // })
+       const router=useRouter()
+       const fileId=useform.file
 
-      ElMessageBox.alert("成功使用模型,快去查看结果吧",{type:"success"})
+      //ElMessageBox.alert("成功使用模型,快去查看结果吧",{type:"success"})
     };
 
     // 删除操作(单个)