Переглянути джерело

处理登录过期的情况

任一存 2 роки тому
батько
коміт
36be1866cf
4 змінених файлів з 24 додано та 7 видалено
  1. 5 5
      public/static/js/Hot.js
  2. 18 0
      src/App.vue
  3. 1 1
      src/api.js
  4. 0 1
      src/main.js

+ 5 - 5
public/static/js/Hot.js

@@ -1239,17 +1239,17 @@ window.initHot = function (model) {
           g_currentHot = this,
           popup.style.display = "block",
           popup.classList.add("wait")
-          var n = document.createElement("iframe")
+          var iframeElem = document.createElement("iframe")
 
           SoundManager.play('hot')
 
           var src = getCommonHotspotUrl(this.info.link)
-          n.src = src
-          n.id = "id1",
-          n.allowTransparency = "true"
+          iframeElem.src = src
+          iframeElem.id = "id1",
+          iframeElem.allowTransparency = "true"
           var a = document.getElementById("id1")
           if (void 0 === a || null == a) {
-            document.querySelector(".popup-content").appendChild(n)
+            document.querySelector(".popup-content").appendChild(iframeElem)
             document.body.classList.add('hotspot-detail-open')
             var s = !1
             window.loaddingSuccess = function () {

+ 18 - 0
src/App.vue

@@ -18,6 +18,7 @@
 
 <script>
 import '@/assets/style/reset.less'
+import { mapMutations } from 'vuex'
 
 export default {
   mounted() {
@@ -26,8 +27,25 @@ export default {
     }
 
     globalApi.checkLoginStatusAndProcess()
+
+    window.addEventListener('message', (e) => {
+      console.log('receive message...', e)
+      if (e.data === 'token invalid') {
+        this.logoutCallback()
+        if (document.getElementById('closepop')) {
+          document.getElementById('closepop').click()
+        } else if (document.getElementById('popup')) {
+          const popupElement = document.getElementById('popup')
+          popupElement.parentElement.removeChild(popupElement)
+        }
+        this.$router.push({ name: 'Login' })
+      }
+    })
   },
   methods: {
+    ...mapMutations([
+      'logoutCallback',
+    ])
   }
 }
 </script>

+ 1 - 1
src/api.js

@@ -6,7 +6,7 @@ import store from "@/store/index.js"
 axios.interceptors.response.use(function (response) {
   // 2xx 范围内的状态码都会触发该函数。
   // 对响应数据做点什么
-  if (response.data.code === 5001) {
+  if (response.data.code === 5001 || response === 5002) {
     store.commit('logoutCallback')
   }
   return response

+ 0 - 1
src/main.js

@@ -22,7 +22,6 @@ Vue.use(Viewer, {
   }
 })
 
-
 Vue.config.productionTip = false
 Vue.use(ElementUI)
 Vue.use(clickOutside)