You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ki...@apache.org on 2020/12/17 01:39:08 UTC

[incubator-dolphinscheduler] branch dev updated: [Fix][UI]: fix re-login problem in new tab and state synchronization problem in multiple tabs (#4162)

This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new f2a996f  [Fix][UI]: fix re-login problem in new tab and state synchronization problem in multiple tabs (#4162)
f2a996f is described below

commit f2a996f2a241e33c9378598e744f28d071f0012e
Author: Shiwen Cheng <ch...@gmail.com>
AuthorDate: Thu Dec 17 09:38:57 2020 +0800

    [Fix][UI]: fix re-login problem in new tab and state synchronization problem in multiple tabs (#4162)
    
    * fix(ui): re-login problem in new tab
    
    * refresh page in new tab automatically
    
    * support to reload router view in lightweight
    
    * optimize visibility code
---
 dolphinscheduler-ui/src/js/conf/home/App.vue       | 23 ++++++-
 dolphinscheduler-ui/src/js/module/io/index.js      |  2 +-
 .../src/js/module/visibility/index.js              | 70 ++++++++++++++++++++++
 3 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/dolphinscheduler-ui/src/js/conf/home/App.vue b/dolphinscheduler-ui/src/js/conf/home/App.vue
index 97110e5..2d7a5f3 100644
--- a/dolphinscheduler-ui/src/js/conf/home/App.vue
+++ b/dolphinscheduler-ui/src/js/conf/home/App.vue
@@ -17,15 +17,36 @@
 <template>
   <m-layout>
     <m-nav slot="top"></m-nav>
-    <router-view slot="bottom"></router-view>
+    <router-view slot="bottom" v-if="isRenderRouterView"></router-view>
   </m-layout>
 </template>
 
 <script>
+  import visibility from '@/module/visibility'
   import mLayout from '@/module/components/layout/layout'
   import mNav from '@/module/components/nav/nav'
   export default {
     name: 'app',
+    data () {
+      return {
+        isRenderRouterView: true
+      }
+    },
+    methods: {
+      reload () {
+        this.isRenderRouterView = false
+        this.$nextTick(() => {
+          this.isRenderRouterView = true
+        })
+      }
+    },
+    mounted () {
+      visibility.change((evt, hidden) => {
+        if (hidden === false) {
+          this.reload()
+        }
+      })
+    },
     components: { mLayout, mNav }
   }
 </script>
diff --git a/dolphinscheduler-ui/src/js/module/io/index.js b/dolphinscheduler-ui/src/js/module/io/index.js
index 9b806ab..79e2eb5 100644
--- a/dolphinscheduler-ui/src/js/module/io/index.js
+++ b/dolphinscheduler-ui/src/js/module/io/index.js
@@ -75,7 +75,7 @@ io.interceptors.request.use(
     const sIdCookie = cookies.get('sessionId')
     const sessionId = sessionStorage.getItem('sessionId')
     const requstUrl = config.url.substring(config.url.lastIndexOf('/') + 1)
-    if (sIdCookie !== null && requstUrl !== 'login' && sIdCookie !== sessionId) {
+    if ((!sIdCookie || (sessionId && sessionId !== sIdCookie)) && requstUrl !== 'login') {
       window.location.href = `${PUBLIC_PATH}/view/login/index.html`
     } else {
       const { method } = config
diff --git a/dolphinscheduler-ui/src/js/module/visibility/index.js b/dolphinscheduler-ui/src/js/module/visibility/index.js
new file mode 100644
index 0000000..666ffaa
--- /dev/null
+++ b/dolphinscheduler-ui/src/js/module/visibility/index.js
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License") you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+let hidden, visibilityChange
+
+if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support
+  hidden = 'hidden'
+  visibilityChange = 'visibilitychange'
+} else if (typeof document.msHidden !== 'undefined') {
+  hidden = 'msHidden'
+  visibilityChange = 'msvisibilitychange'
+} else if (typeof document.webkitHidden !== 'undefined') {
+  hidden = 'webkitHidden'
+  visibilityChange = 'webkitvisibilitychange'
+} else if (typeof document.mozHidden !== 'undefined') {
+  hidden = 'mozHidden'
+  visibilityChange = 'mozvisibilitychange'
+}
+
+const visibility = {
+  /**
+   * Callback when visibility changed
+   *
+   * @param {Function (event, hidden)} callback
+   *  - {Event} event
+   *  - {Boolean} hidden
+   */
+  change (callback) {
+    if (visibility.isSupported()) {
+      document.addEventListener(visibilityChange, evt => callback(evt, document[hidden]), false)
+    } else {
+      // fallback
+      if (document.addEventListener) {
+        window.addEventListener('focus', evt => callback(evt, false), false)
+        window.addEventListener('blur', evt => callback(evt, true), false)
+      } else {
+        document.attachEvent('onfocusin', evt => callback(evt, false))
+        document.attachEvent('onfocusout', evt => callback(evt, true))
+      }
+    }
+  },
+  /**
+   * Return true if browser support Page Visibility API.
+   */
+  isSupported () {
+    return hidden !== undefined
+  },
+  /**
+   * Return true if page now isn’t visible to user.
+   */
+  hidden () {
+    return document[hidden]
+  }
+}
+
+export default visibility