Browse Source

fix: 未登录跳转登录页面

cuiyalong 3 năm trước cách đây
mục cha
commit
a1796d5f52
2 tập tin đã thay đổi với 24 bổ sung8 xóa
  1. 19 7
      src/api/index.js
  2. 5 1
      src/views/analysisReport/MarketAnalysis.vue

+ 19 - 7
src/api/index.js

@@ -1,6 +1,13 @@
 import axios from './axios'
 import qs from 'qs'
 
+// 此处添加全局请求拦截
+// $.ajaxPrefilter((options, originalOptions, jqXHR) => {
+//   console.log('options', options)
+//   console.log('originalOptions', originalOptions)
+//   console.log('jqXHR', jqXHR)
+// })
+
 // jquery请求
 const ajax = config => new Promise((resolve, reject) => {
   // 获取url参数
@@ -37,19 +44,24 @@ const ajax = config => new Promise((resolve, reject) => {
   }
 
   // 此处数据预处理
-
   // 此处添加请求拦截(请求发送前处理参数)
-  // $.ajaxPrefilter((options, originalOptions, jqXHR) => {
-  //   console.log('options', options)
-  //   console.log('originalOptions', originalOptions)
-  //   console.log('jqXHR', jqXHR)
-  // })
 
   $.ajax({
     ...ajaxConf,
-    beforeSend: xhr => {},
+    beforeSend: xhr => {
+      // 此处请求预处理
+      // 此处添加请求拦截(请求发送前处理参数)
+    },
     success: res => {
       // 此处添加响应拦截
+      if (process.env.NODE_ENV === 'production') {
+        const noPermissionText = ['未登录', '需要登录']
+        const noPermission = noPermissionText.includes(res.error_msg)
+        if (noPermission) {
+          location.href = '/notin/page'
+          return
+        }
+      }
       resolve(res)
     },
     error: err => {

+ 5 - 1
src/views/analysisReport/MarketAnalysis.vue

@@ -126,7 +126,11 @@ export default {
     this.getUrlQuery()
   },
   mounted () {
-    this.initKeyMap()
+    try {
+      this.initKeyMap()
+    } catch (error) {
+      console.log(error)
+    }
     this.initDefaultTime()
   },
   methods: {