浏览代码

iframe地址跳转,在地址栏保存iframe的url参数

mambachenhao_i@didiglobal.com 4 年之前
父节点
当前提交
3c6f0d92f3
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      src/views/useCase/components/requirementCase.vue

+ 9 - 4
src/views/useCase/components/requirementCase.vue

@@ -32,7 +32,7 @@ export default {
         : getEnv() === 'pre'
           ? 'http://agiletc-pre.intra.xiaojukeji.com/#'
           : 'http://agiletc.intra.xiaojukeji.com/#'
-      const src = `${host}${this.srcHost}${encodeURIComponent(bizId)}`
+      const src = `${host}${this.srcHost}${this.$route.query.bizIdUrl || encodeURIComponent(bizId)}`
       return src
     }
   },
@@ -53,11 +53,16 @@ export default {
       }
       if(e.data && e.data.event){
         const { event, payload } = e.data;
+        const { href, hash } = window.location;
         // 链接跳转时发送message的data
         if (event === 'case-link') {
-          this.$store.dispatch('global/setBizId', payload.site)
-          // 获取当前打开页面地址
-          const websiteUrl =  window.location.href.replace(/bizId=.*/,`bizId=${payload.site}`);
+          const bizIdParams = payload.url.replace(/http.*case\/caseList\/zhihui\//, ''); // 截取 iframe 传递过来的页面地址
+          if(bizIdParams.search(/http/) > -1) return; // 字符串截取失败终止
+          let websiteUrl = `${ href }&bizIdUrl=${bizIdParams}`; // 新的页面地址
+          // 如果当前打开页面地址是已分享地址,则将原有的 bizIdUrl 值替换
+          if (hash.search(/bizIdUrl/) > -1) {
+            websiteUrl = href.replace(/bizIdUrl=.*/,`bizIdUrl=${bizIdParams}`);
+          }
           // 改变浏览器历史URL
           window.history.pushState({url: websiteUrl, title: document.title}, document.title, websiteUrl)
         }