|
@@ -20,19 +20,24 @@ export default {
|
|
|
ifr: null,
|
|
|
srcHost: '/case/caseList/zhihui/',
|
|
|
loading: true,
|
|
|
- fullScreen: false, // 是否全屏
|
|
|
+ fullScreen: false // 是否全屏
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
...mapGetters(['bizId']),
|
|
|
src() {
|
|
|
const bizId = EncryptId(`${this.bizId}`)
|
|
|
- const host = 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 = `${host}${this.$route.query.detailCaseUrl?'/case/caseManager/zhihui/' : this.srcHost }${ this.$route.query.detailCaseUrl || encodeURIComponent(bizId)}`
|
|
|
+ const host =
|
|
|
+ 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 = `${host}${
|
|
|
+ this.$route.query.detailCaseUrl
|
|
|
+ ? '/case/caseManager/zhihui/'
|
|
|
+ : this.srcHost
|
|
|
+ }${this.$route.query.detailCaseUrl || encodeURIComponent(bizId)}`
|
|
|
return src
|
|
|
}
|
|
|
},
|
|
@@ -46,49 +51,69 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
- window.addEventListener('message', (e) => {
|
|
|
- if (e.data === 'useCaseDone') {
|
|
|
- this.loading = false
|
|
|
- this.loaded()
|
|
|
- }
|
|
|
- if(e.data && e.data.event){
|
|
|
- const { event, payload } = e.data;
|
|
|
- const { href, hash } = window.location;
|
|
|
- // 链接跳转时发送message的data
|
|
|
- if (event === 'case-link') {
|
|
|
- const detailCaseUrl = payload.url.replace(/http.*zhihui\//, ''); // 截取 iframe 传递过来的页面地址
|
|
|
- if(detailCaseUrl.search(/http/) > -1) return; // 字符串截取失败终止
|
|
|
- let websiteUrl = `${ href }&detailCaseUrl=${encodeURIComponent(detailCaseUrl)}`; // 新的页面地址
|
|
|
- // 如果当前打开页面地址是已分享地址,则将原有的 detailCaseUrl 值替换
|
|
|
- if (hash.search(/detailCaseUrl/) > -1) {
|
|
|
- websiteUrl = href.replace(/detailCaseUrl=.*/,`detailCaseUrl=${encodeURIComponent(detailCaseUrl)}`);
|
|
|
- }
|
|
|
- // 改变浏览器历史URL
|
|
|
- window.history.pushState({url: websiteUrl, title: document.title}, document.title, websiteUrl)
|
|
|
+ window.addEventListener(
|
|
|
+ 'message',
|
|
|
+ e => {
|
|
|
+ if (e.data === 'useCaseDone') {
|
|
|
+ this.loading = false
|
|
|
+ this.loaded()
|
|
|
}
|
|
|
- // 全屏操作时发送message的data
|
|
|
- if (event === 'case-operations') {
|
|
|
- this.fullScreen = payload.fullScreen
|
|
|
+ if (e.data && e.data.event) {
|
|
|
+ const { event, payload } = e.data
|
|
|
+ const { href, hash } = window.location
|
|
|
+ // 链接跳转时发送message的data
|
|
|
+ if (event === 'case-link') {
|
|
|
+ const detailCaseUrl = payload.url.replace(/http.*zhihui\//, '') // 截取 iframe 传递过来的页面地址
|
|
|
+ if (detailCaseUrl.search(/http/) > -1) return // 字符串截取失败终止
|
|
|
+ let websiteUrl = `${href}&detailCaseUrl=${encodeURIComponent(
|
|
|
+ detailCaseUrl
|
|
|
+ )}` // 新的页面地址
|
|
|
+ // 如果当前打开页面地址是已分享地址,则将原有的 detailCaseUrl 值替换
|
|
|
+ if (hash.search(/detailCaseUrl/) > -1) {
|
|
|
+ websiteUrl = href.replace(
|
|
|
+ /detailCaseUrl=.*/,
|
|
|
+ `detailCaseUrl=${encodeURIComponent(detailCaseUrl)}`
|
|
|
+ )
|
|
|
+ }
|
|
|
+ // 改变浏览器历史URL
|
|
|
+ window.history.pushState(
|
|
|
+ { url: websiteUrl, title: document.title },
|
|
|
+ document.title,
|
|
|
+ websiteUrl
|
|
|
+ )
|
|
|
+ }
|
|
|
+ // 全屏操作时发送message的data
|
|
|
+ if (event === 'case-operations') {
|
|
|
+ this.fullScreen = payload.fullScreen
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }, false)
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
- window.removeEventListener('message', (e) => {
|
|
|
- // console.log('销毁')
|
|
|
- }, false)
|
|
|
+ window.removeEventListener(
|
|
|
+ 'message',
|
|
|
+ e => {
|
|
|
+ // console.log('销毁')
|
|
|
+ },
|
|
|
+ false
|
|
|
+ )
|
|
|
},
|
|
|
methods: {
|
|
|
loaded() {
|
|
|
const ifr = document.getElementById('useCaseIframe')
|
|
|
if (ifr) {
|
|
|
- ifr.contentWindow.postMessage({ user: localStorage.getItem('username') }, '*')
|
|
|
+ ifr.contentWindow.postMessage(
|
|
|
+ { user: localStorage.getItem('username') },
|
|
|
+ '*'
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
-<style lang="scss" scoped>
|
|
|
+<style lang='scss' scoped>
|
|
|
.case-main {
|
|
|
// padding: 20px 0 20px 18px;
|
|
|
margin: 10px;
|
|
@@ -107,5 +132,4 @@ export default {
|
|
|
bottom: 0;
|
|
|
z-index: 999;
|
|
|
}
|
|
|
-
|
|
|
</style>
|