Browse Source

增加跳转知识图谱传输用户名的功能。

yangdr 1 month ago
parent
commit
a1e261ad71
2 changed files with 24 additions and 2 deletions
  1. 1 0
      src/App.vue
  2. 23 2
      src/views/KMPlatform/Home/Home.vue

+ 1 - 0
src/App.vue

@@ -8,6 +8,7 @@
 import { RouterView } from 'vue-router'
 import { ElConfigProvider } from 'element-plus'
 import zhCn from 'element-plus/es/locale/lang/zh-cn'
+
 </script>
 
 <style lang="less">

+ 23 - 2
src/views/KMPlatform/Home/Home.vue

@@ -28,11 +28,13 @@
 </template>
 
 <script setup lang="ts">
-import { ref, watchEffect } from 'vue'
+import { ref, watchEffect, onBeforeUnmount, onMounted } from 'vue'
 import { useRouter } from 'vue-router'
 import { knowledgeGraphAddr } from "@/utils/config"
 import { getSessionVar } from '@/utils/session'
+import { handleError } from 'vue'
 const router = useRouter()
+let timer: any
 // console.log("getSessionVar('knowledageSystem') ", getSessionVar('knowledageSystem'))
 let process = ref<any>([
   {
@@ -90,11 +92,30 @@ watchEffect(() => {
 
 function handleModuleClick(path: string) {
   if (/^https?/g.test(path)) {
-    window.open(path, '_blank');
+    path = 'http://localhost:8081/home.html'
+    const newWindow = window.open(path, '_blank');
+    timer = setInterval(() => {
+      newWindow?.postMessage({ type: 'login', username: getSessionVar("full_name") }, "*")
+    }, 100)
   } else {
     router.push({ path: path })
   }
 }
+function handleLogin(event: any) {
+  const { type, status } = event.data
+  if (type === 'login' && status === 'ok') {
+    // alert('登录成功')
+    clearInterval(timer)
+  }
+}
+onMounted(() => {
+  window.addEventListener('message', handleLogin);
+})
+
+onBeforeUnmount(() => {
+  window.removeEventListener('message', handleLogin);
+  clearInterval(timer)
+})
 </script>
 
 <style lang="less" scoped>