claims.vue
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
<div>
<iframe
id="myIframe"
class="box"
allowfullscreen
:src="iframeSrc + iframeUrlWithParams"
></iframe>
</div>
</template>
<script>
import { baseConfig } from "@/main"
import { mapState } from "vuex"
export default {
data() {
return {
iframeSrc: baseConfig.scrm,
// iframeSrc: "http://192.168.1.178:6654",
iframeUrl: "/#/claims/index"
}
},
computed: {
// sessionId, merchantId
iframeUrlWithParams() {
// 处理单个参数的函数
const updateParam = (url, paramName, paramValue) => {
const regex = new RegExp(`([?&])${paramName}=[^&]*`)
if (url.includes(`${paramName}=`)) {
return url.replace(regex, `$1${paramName}=${paramValue}`)
} else {
return (
url + (url.includes("?") ? "&" : "?") + `${paramName}=${paramValue}`
)
}
}
let finalUrl = this.iframeUrl
// 确保在添加或更新参数时的顺序正确
console.log(this.scrmInfo.merchantId, "this.scrmInfo.merchantId")
if (this.scrmInfo.merchantId) {
finalUrl = updateParam(finalUrl, "merchantId", this.scrmInfo.merchantId)
console.log(finalUrl, "finalUrl")
}
if (this.scrmInfo.sessionId) {
finalUrl = updateParam(finalUrl, "sessionId", this.scrmInfo.sessionId)
console.log(finalUrl, "finalUrl")
}
return finalUrl
},
...mapState({
scrmInfo: (state) => state.d2admin.user.scrmInfo
})
},
mounted() {
// 监听来自 iframe 的消息
// window.addEventListener("message", (event) => {
// console.log("收到 iframe 消息:", event.data)
// if (event.data.type === "location-change") {
// console.log("Iframe 地址已改变:", event.data.url)
// // 在这里可以执行其他操作,比如更新 iframe 的 src 属性
// this.handleIframeLocationChange(event.data.url)
// }
// })
},
methods: {
handleIframeLocationChange(url) {
const iframe = document.getElementById("myIframe")
const internalUrl = url
let newInternalUrl = internalUrl
if (internalUrl.includes("?t=")) {
newInternalUrl = internalUrl.replace(
/(\?|&)t=[^&]+/,
"$1t=" + this.SSOInfo.t
)
} else {
newInternalUrl = internalUrl.includes("?")
? internalUrl + "&t=" + this.SSOInfo.t
: internalUrl + "?t=" + this.SSOInfo.t
}
console.log("新的内部地址:", newInternalUrl)
this.iframeUrl = newInternalUrl
}
}
}
</script>
<style lang="scss" scoped>
.box {
position: absolute;
width: 97%;
height: 96%;
border: 0;
margin: 20px;
background-color: #fff;
}
</style>