Browse Source

反向代理
Signed-off-by: Caner <5658514@qq.com>

Caner 4 years ago
parent
commit
48fdb6be71
3 changed files with 33 additions and 17 deletions
  1. 20 8
      web/src/pages/index/views/index.vue
  2. 0 1
      web/src/utils/axios.js
  3. 13 8
      web/vite.config.js

+ 20 - 8
web/src/pages/index/views/index.vue

@@ -42,6 +42,7 @@ export default {
       show: false,
       show: false,
       newImg: [],
       newImg: [],
       table: [],
       table: [],
+      URL: process.env.SERVERURL,
     };
     };
   },
   },
   methods: {
   methods: {
@@ -116,19 +117,15 @@ export default {
         this.show = true;
         this.show = true;
         const formData = new FormData();
         const formData = new FormData();
         formData.append("pic", this.newImg[0].data);
         formData.append("pic", this.newImg[0].data);
-        const res = await axios.post("/uploadOneInvoicePic", formData);
-        this.table = this.setData(res.data.invoice_data.words_result[0].result);
+        const { data,success } = await axios.post("/uploadOneInvoicePic", formData);
+        if(!success) throw new Error("上传错误");
+        await this.reGetData(data.result_url,start);
       } catch (error) {
       } catch (error) {
+        this.show = false;
         Notice.warning({
         Notice.warning({
           desc: error,
           desc: error,
         });
         });
       }
       }
-      this.show = false;
-      const end = Date.now();
-      Message.info({
-        content: "识别总用时:" + (start - end) / 1000 + "s",
-        duration: 5,
-      });
     },
     },
     // 处理数据
     // 处理数据
     setData(data) {
     setData(data) {
@@ -208,6 +205,21 @@ export default {
       }
       }
       return name;
       return name;
     },
     },
+    // 递归获取数据
+    async reGetData(url,start) {
+      const res = await axios.get(url);
+      if (res.success) {
+        this.table = this.setData(res.data.invoice_data.words_result[0].result);
+        const end = Date.now();
+        Message.info({
+          content: "识别总用时:" + Math.abs((start - end) / 1000) + "s",
+          duration: 5,
+        });  
+        this.show = false;       
+      } else {
+        this.reGetData(url,start);
+      }
+    },
   },
   },
 };
 };
 </script>
 </script>

+ 0 - 1
web/src/utils/axios.js

@@ -2,7 +2,6 @@ import axios from 'axios'
 // http request 拦截
 // http request 拦截
 axios.interceptors.request.use(
 axios.interceptors.request.use(
   config => {
   config => {
-    config.baseURL = process.env.SERVERURL
     return config
     return config
   },
   },
   err => {
   err => {

+ 13 - 8
web/vite.config.js

@@ -47,13 +47,18 @@ export default ({ mode }) => defineConfig({
     strictPort: false,
     strictPort: false,
     https: false,
     https: false,
     // 反向代理
     // 反向代理
-    // proxy: {
-    //   '/': {
-    //     target: 'http://172.16.1.215:5000',
-    //     changeOrigin: true,
-    //     rewrite: (path) => path.replace(/^\//, '')
-    //   },
-    // }
+    proxy: {
+      '/uploadOneInvoicePic': {
+        target: 'https://ocr.caner.top',
+        changeOrigin: true,
+        rewrite: (path) => path.replace(/^\//, '')
+      },
+      '/getInvoiceResult': {
+        target: 'https://ocr.caner.top',
+        changeOrigin: true,
+        rewrite: (path) => path.replace(/^\//, '')
+      },      
+    }
   },
   },
   build: {
   build: {
     rollupOptions: {
     rollupOptions: {
@@ -74,7 +79,7 @@ export default ({ mode }) => defineConfig({
   },
   },
   define: { //环境变量配置
   define: { //环境变量配置
     'process.env': {
     'process.env': {
-      'SERVERURL': mode === 'development' ? 'https://ocr.caner.top':''
+      'SERVERURL': mode === 'development' ? 'https://ocr.caner.top':'https://ocr.caner.top'
     }
     }
   }
   }
 })
 })