洪海涛 4 жил өмнө
parent
commit
a8a4a7c2fc

+ 61 - 5
src/views/useCase/components/useCase.vue

@@ -11,7 +11,9 @@
 </template>
 <script>
 import { mapGetters } from 'vuex'
-// import { EncryptId } from '@/utils/crypto-js.js'
+import addDOMEventListener from 'add-dom-event-listener'
+import { EncryptId, desDecryptId } from '@/utils/crypto-js.js'
+import { getEnv } from '@/apiConfig/requestIP'
 // import { getEnv } from '@/apiConfig/requestIP.js'
 export default {
   data() {
@@ -19,6 +21,8 @@ export default {
       ifr: null,
       srcHost: '/case/caseList/zhihui/',
       loading: false,
+      path: '/useCase',
+      eventHandlers: '',
       fullScreen: false // 是否全屏
     }
   },
@@ -30,9 +34,14 @@ export default {
       //   getEnv() === 'test'
       //     ? 'http://10.96.83.94:9000/index.html#'
       //     : getEnv() === 'pre'
-      //       ? 'http://agiletc-pre.intra.xiaojukeji.com/#'
-      //       : 'http://agiletc.intra.xiaojukeji.com/#'
-      const src = `http://localhost:7100/#/useCase?bizId=${this.bizId}&hiddenNav=true`
+      //     ? 'http://agiletc-pre.intra.xiaojukeji.com/#'
+      //     : 'http://agiletc.intra.xiaojukeji.com/#'
+      // const src = `${host}${
+      //   this.$route.query.detailCaseUrl
+      //     ? '/case/caseManager/zhihui/'
+      //     : this.srcHost
+      // }${this.$route.query.detailCaseUrl || encodeURIComponent(bizId)}`
+      const src = `${'http://localhost:7100'}/#${this.$route.query.detailCaseUrl || this.path}?bizId=${this.bizId}&hiddenNav=true`
       return src
     }
   },
@@ -46,13 +55,60 @@ export default {
     }
   },
   mounted() {
+    window.addEventListener('message', this.setRouterPath, false)
 
+    window.addEventListener(
+      'message',
+      e => this.setRouterPath(e),
+      false
+    )
   },
   beforeDestroy() {
 
+  },
+  // 销毁监听事件
+  destroyed() {
+    window.removeEventListener(
+      'message',
+      e => {
+        // console.log('销毁')
+      },
+      false
+    )
   },
   methods: {
-
+    setRouterPath(e) {
+      console.log(e)
+      // console.log(e.nativeEvent.data)
+      // console.log(desDecryptId(this.$route.query.bizId))
+      // console.log(this.$route.query)
+      // this.path = msg.nativeEvent.data.path
+    /*  const { event, payload } = e.data
+      const { href, hash } = window.location
+      // 链接跳转时发送message的data
+      if (event === 'case-link') {
+        // const detailCaseUrl = payload.url.replace(/http.*zhihui\//, '') // 截取 iframe 传递过来的页面地址
+        const detailCaseUrl = payload // 截取 iframe 传递过来的页面地址
+        if (detailCaseUrl.search(/http/) > -1) return // 字符串截取失败终止
+        let websiteUrl = `${href}&detailCaseUrl=${encodeURIComponent(
+          detailCaseUrl
+        )}` // 新的页面地址
+        // 如果当前打开页面地址是已分享地址,则将原有的 detailCaseUrl 值替换
+        console.log(hash, href)
+        if (hash.search(/detailCaseUrl/) > -1) {
+          websiteUrl = href.replace(
+            /detailCaseUrl=.*!/,
+            `detailCaseUrl=${encodeURIComponent(detailCaseUrl)}`
+          )
+        }
+        // 改变浏览器历史URL
+        window.history.pushState(
+          { url: websiteUrl, title: document.title },
+          document.title,
+          websiteUrl
+        )
+      }*/
+    }
   }
 }
 </script>