Browse Source

docker: env url

Yi 1 year ago
parent
commit
8f727b16df
2 changed files with 57 additions and 57 deletions
  1. 9 9
      public/index.html
  2. 48 48
      src/utils/request.js

+ 9 - 9
public/index.html

@@ -4,10 +4,10 @@
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
-    <!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" /> -->
+    <!-- <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" /> -->
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
-    <title><%= webpackConfig.name %></title>
-    <script src="config.js?v=<%=new Date().getTime()%>"></script>
+    <title><%= webpackConfig.name %></title>
+    <!--script src="config.js?v=<%=new Date().getTime()%>"></script> -->
 
   </head>
   <body>
@@ -16,11 +16,11 @@
     </noscript>
     <div id="app"></div>
     <!-- built files will be auto injected -->
-  </body>
+  </body>
   <!-- <script src="//api.tianditu.gov.cn/api?v=4.0&tk=dbb376d009d74e90490af79879f33ef5" type="text/javascript"></script> -->
-  <!-- <script src="//lbs.tianditu.gov.cn/js/lib/jquery/jquery-1.7.2.min.js"></script> -->
-  <!-- <script src="//cdn.bootcss.com/d3/3.5.17/d3.js " charset="utf-8"></script> -->
-  <!-- <script src="//lbs.tianditu.gov.cn/api/js4.0/opensource/openlibrary/D3SvgOverlay.js"></script>
-  <script src="//lbs.tianditu.gov.cn/api/js4.0/opensource/openlibrary/CarTrack.js"></script> -->
-  <!-- <script language="javascript" src="//api.tianditu.gov.cn/js/maps.js"></script> -->
+  <!-- <script src="//lbs.tianditu.gov.cn/js/lib/jquery/jquery-1.7.2.min.js"></script> -->
+  <!-- <script src="//cdn.bootcss.com/d3/3.5.17/d3.js " charset="utf-8"></script> -->
+  <!-- <script src="//lbs.tianditu.gov.cn/api/js4.0/opensource/openlibrary/D3SvgOverlay.js"></script>
+  <script src="//lbs.tianditu.gov.cn/api/js4.0/opensource/openlibrary/CarTrack.js"></script> -->
+  <!-- <script language="javascript" src="//api.tianditu.gov.cn/js/maps.js"></script> -->
 </html>

+ 48 - 48
src/utils/request.js

@@ -2,21 +2,21 @@ import axios from 'axios'
 import { MessageBox, Message } from 'element-ui'
 import store from '@/store'
 import { getToken } from '@/utils/auth'
-
-//获取当前url
-
-var aa = window.GLOBAL.SERVICE_URL
-// var aa = process.env.VUE_APP_BASE_API
-//获取当前url
-if(aa.indexOf('/')==0 && aa.length==1){
-  aa= window.location.protocol + "//"+window.location.host+aa
-}
+
+//获取当前url
+
+//var aa = window.GLOBAL.SERVICE_URL
+var aa = process.env.VUE_APP_BASE_API
+//获取当前url
+if(aa.indexOf('/')==0 && aa.length==1){
+  aa= window.location.protocol + "//"+window.location.host+aa
+}
   const service = axios.create({
-    baseURL: aa, // url = base url + request url
-    withCredentials: true, // send cookies when cross-domain requests
-    timeout: 60000 ,// request timeout
-  })
-// request interceptor
+    baseURL: aa, // url = base url + request url
+    withCredentials: true, // send cookies when cross-domain requests
+    timeout: 60000 ,// request timeout
+  })
+// request interceptor
 service.interceptors.request.use(
   config => {
     // do something before request is sent
@@ -29,10 +29,10 @@ service.interceptors.request.use(
     if (store.getters.token) {
       if (process.env.VUE_APP_BASE_API === '/dev-api') {
         config.headers['X-Token'] = getToken()
-      } else {
+      } else {
         config.headers['Authorization'] = 'Bearer ' + getToken()
       }
-    }
+    }
     return config
   },
   error => {
@@ -45,7 +45,7 @@ service.interceptors.request.use(
 // response interceptor
 service.interceptors.response.use(
   response => {
-    const res = response.data
+    const res = response.data
     // if the custom code is not 20000, it is judged as an error.
     if (res.code !== 200) {
       if (res.code === 10000 || res.code === 50012 || res.code === 50014) {
@@ -73,37 +73,37 @@ service.interceptors.response.use(
       return res
     }
   },
-  error => {
-    if (error.response.data.code === 10000) {
-      MessageBox.confirm('你已经注销登陆,你可以取消或重新登陆', '确认注销', {
-        confirmButtonText: '重新登陆',
-        cancelButtonText: '取消',
-        type: 'warning'
-      }).then(() => {
-        store.dispatch('user/resetToken').then(() => {
-          location.reload()
-        })
-      })
-    }
-    let config = error.config
-    if (!config) {
-      Message({ message: error.msg, type: 'error', duration: 5 * 1000 })
-      return Promise.reject(error)
-    }
-    // 设置请求超时次数
-    // config.__retryCount = config.__retryCount || 0
-    // if (config.__retryCount >= 3) {
-    //   Message({ message:'操作失败'+error.response.data.errors[0], type: 'error', duration: 5 * 1000 })
-    //   return Promise.reject(error)
-    // }
-    // config.__retryCount += 1
-    // let backoff = new Promise((resolve) => {
-    //   setTimeout(() => {
-    //     resolve()
-    //   }, config.retryDelay || 1)
-    // })
-    // return backoff.then(() => {
-    //   return service(config)
+  error => {
+    if (error.response.data.code === 10000) {
+      MessageBox.confirm('你已经注销登陆,你可以取消或重新登陆', '确认注销', {
+        confirmButtonText: '重新登陆',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        store.dispatch('user/resetToken').then(() => {
+          location.reload()
+        })
+      })
+    }
+    let config = error.config
+    if (!config) {
+      Message({ message: error.msg, type: 'error', duration: 5 * 1000 })
+      return Promise.reject(error)
+    }
+    // 设置请求超时次数
+    // config.__retryCount = config.__retryCount || 0
+    // if (config.__retryCount >= 3) {
+    //   Message({ message:'操作失败'+error.response.data.errors[0], type: 'error', duration: 5 * 1000 })
+    //   return Promise.reject(error)
+    // }
+    // config.__retryCount += 1
+    // let backoff = new Promise((resolve) => {
+    //   setTimeout(() => {
+    //     resolve()
+    //   }, config.retryDelay || 1)
+    // })
+    // return backoff.then(() => {
+    //   return service(config)
     // })
     Message({
       message: "操作错误!"+error.response.data.errors[0],