iframe.vue
3.07 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<template>
<div class="iframe-wrapper">
<h2>客户端</h2>
<el-form size="mini" :model="orderInfo" style="width:200px">
<el-form-item label="申请人姓名">
<el-input v-model="orderInfo.appUserName"></el-input>
</el-form-item>
<el-form-item label="申请人手机号">
<el-input v-model="orderInfo.appUserPhone"></el-input>
</el-form-item>
<el-form-item label="订单号">
<el-input v-model="orderInfo.orderId"></el-input>
</el-form-item>
<el-form-item label="业务员工号">
<el-input v-model="orderInfo.webUserName"></el-input>
</el-form-item>
</el-form>
<p>
<el-button type="primary" @click="open">呼叫</el-button>
<el-button type="primary" @click="cancelCall">取消呼叫</el-button>
</p>
<iframe
v-if="isStart"
ref="srtcIframe"
title="srtcIframe"
:src="target"
frameborder="2"
allow="microphone;camera;midi;encrypted-media;fullscreen;"
></iframe>
</div>
</template>
<script>
export default {
data() {
return {
baseUrl: 'https://pre-web-chery.situdata.com',
isStart: false,
target: '',
strWindowFeatures: `
left=2400,
top=200
height=500,
width=700,
menubar=1,
toolbar=1,
fullscreen=1
`,
orderInfo: {
appUserName: '刘臻',
appUserPhone: '16621043587',
orderId: '9527',
webUserName: 'lz'
}
}
},
beforeMount() {
window.addEventListener('message', this.receiveMessage, false)
},
methods: {
open() {
this.isStart = true
this.target = `${this.baseUrl}/#/srtc-iframe?path="https://localhost:8080"`
this.$nextTick().then(() => {
this.$refs.srtcIframe.onload = () => {
this.sendMessage()
}
})
},
sendMessage() {
const { appUserName, appUserPhone, orderId, webUserName } = this.orderInfo
this.$refs.srtcIframe.contentWindow.postMessage(
{
type: 'startCall',
data: {
appUserName,
appUserPhone,
orderId,
webUserName
}
},
this.baseUrl
)
},
cancelCall() {
this.$refs.srtcIframe.contentWindow.postMessage(
{
type: 'cancelCall'
},
this.baseUrl
)
},
receiveMessage(e) {
if (e.origin !== this.baseUrl) {
return
}
const {
data: { data, type }
} = e
switch (type) {
case 'appHangUp':
this.isStart = false
break
case 'cancelCallCB':
this.isStart = false
break
case 'webHangUp':
this.isStart = false
break
}
this.popMessage(`${type}---${data}`)
},
popMessage(data) {
this.$message({
type: 'error',
message: data
})
}
}
}
</script>
<style lang="scss" scoped>
.iframe-wrapper {
text-align: left;
padding: 40px;
}
iframe {
width: 500px;
height: 600px;
position: fixed;
top: 0;
right: 0;
}
</style>