wenbobowen 4 роки тому
батько
коміт
f9127f1ae9
2 змінених файлів з 49 додано та 10 видалено
  1. 31 0
      src/utils/index.js
  2. 18 10
      src/views/useCase/components/useCase.vue

+ 31 - 0
src/utils/index.js

@@ -8,6 +8,7 @@
  * @param {string} cFormat
  * @returns {string}
  */
+const _ = require('lodash')
 export function parseTime(time, cFormat) {
   if (arguments.length === 0) {
     return null
@@ -179,3 +180,33 @@ export function strToArr(str) {
   // eslint-disable-next-line no-eval
   return window.eval(str)
 }
+export function getUrlSearch(deleteList, addList) {
+  const urlParamsObj = {}
+  const urlSearch = location.href.includes('?') && location.href.split('?')[1] || ''
+  urlSearch && urlSearch.split('&').map(t => {
+    const obj = t.split('=')
+    urlParamsObj[obj[0]] = obj[1]
+  })
+  const newUrl = _.clone(urlParamsObj)
+  deleteList && deleteList.map(t => { delete newUrl[t] })
+  addList && addList.map(t => { newUrl[t.key] = t.value })
+  let urlParams = ''
+  newUrl && Object.keys(newUrl).forEach(g => {
+    urlParams += `${g}=${newUrl[g]}${Object.keys(newUrl).length - 1 === Object.keys(newUrl).indexOf(g) ? '' : '&'}`
+  })
+  return urlParams
+}
+
+export function getUrlParamsObj(keylist) {
+  // url地址中参数?id=91&workId=222 => {id: "91", workId: "222"}
+  const urlParamsObj = {}
+  const obj = {}
+  location.href.includes('?') && location.href.split('?')[1].split('&').map(t => {
+    const obj = t.split('=')
+    urlParamsObj[obj[0]] = obj[1]
+  })
+  keylist.map(t => {
+    obj[t] = urlParamsObj[t]
+  })
+  return obj
+}

+ 18 - 10
src/views/useCase/components/useCase.vue

@@ -11,9 +11,10 @@
 </template>
 <script>
 import { mapGetters } from 'vuex'
-import addDOMEventListener from 'add-dom-event-listener'
-import { EncryptId, desDecryptId } from '@/utils/crypto-js.js'
-import { getEnv } from '@/apiConfig/requestIP'
+// import addDOMEventListener from 'add-dom-event-listener'
+// import { EncryptId, desDecryptId } from '@/utils/crypto-js.js'
+import { getUrlSearch, getUrlParamsObj } from '@/utils'
+// import { getEnv } from '@/apiConfig/requestIP'
 // import { getEnv } from '@/apiConfig/requestIP.js'
 export default {
   data() {
@@ -29,6 +30,7 @@ export default {
   computed: {
     ...mapGetters(['bizId']),
     src() {
+      const { caseRoute } = getUrlParamsObj(['caseRoute'])
       // const bizId = EncryptId(`${this.bizId}`)
       // const host =
       //   getEnv() === 'test'
@@ -41,7 +43,7 @@ export default {
       //     ? '/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`
+      const src = `${'http://localhost:7100'}/#${this.$route.query.detailCaseUrl || this.path}?bizId=${this.bizId}&hiddenNav=true&caseRoute=${caseRoute}`
       return src
     }
   },
@@ -57,11 +59,11 @@ export default {
   mounted() {
     window.addEventListener('message', this.setRouterPath, false)
 
-    window.addEventListener(
-      'message',
-      e => this.setRouterPath(e),
-      false
-    )
+    // window.addEventListener(
+    //   'message',
+    //   e => this.setRouterPath(e),
+    //   false
+    // )
   },
   beforeDestroy() {
 
@@ -78,7 +80,13 @@ export default {
   },
   methods: {
     setRouterPath(e) {
-      console.log(e)
+      console.log(e.data)
+      const { event, route } = e.data
+      const { href } = window.location
+      if (event === 'usecase-set') {
+        const params = getUrlSearch(['caseRoute'], [{ key: 'caseRoute', value: route }])
+        window.open(`${href.split('?')[0]}?${params}`, '_self')
+      }
       // console.log(e.nativeEvent.data)
       // console.log(desDecryptId(this.$route.query.bizId))
       // console.log(this.$route.query)