vhis.js
3.48 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* 页面描述:vhis
* 嵌套平安提供的iFrame
*/
import {
mapState
} from "vuex";
import api from '@/api/api'
import {
httpPost
} from '@/api/fetch-api.js'
import Auth from '@components/auth/auth.vue';
import JsEncrypt from "jsencrypt";
let key = process.env.VUE_APP_CONTENT_ENCRYPT_KEY;
let rsa = new JsEncrypt();
rsa.setPublicKey(key);
function encryptContent(obj) {
let str = JSON.stringify(obj);
let securityContent = rsa.encrypt(str);
return securityContent;
};
export default {
data() {
return {
key: 'value',
outsideUrl: "",
information: null,
}
},
components: {
Auth
},
computed: {
...mapState({
userInfo: state => state.userInfo
}),
},
methods: {
init() {
if (this.isLogin() && !this.information) {
httpPost({
url: api.profile,
sid: true
}).then(content => {
if (content) {
this.information = content;
this.gotoVhis();
}
})
} else {
this.gotoVhis();
}
},
userLogout() {
this.gotoVhis();
},
isLogin() {
return this.userInfo && this.userInfo.sid;
},
gotoVhis() {
// 网销平台productCode : VHIS001,
let url = window.global.vhis;
let productCode = this.$route.query.p;
productCode = productCode ? productCode : "VHIS001";
let lan = this.$i18n.locale;
switch (lan) {
case 'zh':
url += "?language=zh-cn";
break;
case 'en':
url += "?language=en";
break;
default:
url += "?language=zh-hk";
break;
}
url += "&partnerId=PA001&productCode=" + productCode;
// console.log(JSON.stringify(this.information));
if (this.information && this.information.idType && this.information.idNo) {
let data = {
name: this.information.fullName,
gender: this.information.sex,
birthday: this.information.birthDate,
certiType: this.information.policyIdType ? this.information.policyIdType : this.information.idType,
certiNo: this.information.idNo
};
url += "&data=" + encryptContent(data);
}
// url = "http://www.baidu.com"
// console.log("vhis:", url);
this.$set(this, "outsideUrl", "");
var iframe = document.getElementById("myiframe");
try {
iframe.height = 0;
iframe.style.height = "0px";
} catch (ex) {}
let _this = this;
setTimeout(function () {
console.log("vhis:", url);
_this.outsideUrl = url;
}, 100);
}
},
watch: {
"$route.query.p": function () {
this.init();
}
},
mounted() {
this.init();
// let url = this.$route.query.p;
// if (url) {
// this.outsideUrl = url;
// setTimeout(() => {
// var iframe = document.getElementById("myiframe");
// try {
// var bHeight = iframe.contentWindow.document.body.scrollHeight;
// var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
// var height = Math.min(bHeight, dHeight);
// iframe.height = height + 50;
// } catch (ex) {
// }
// }, 500);
// }
// 隐藏滚动条
// document.getElementsByTagName("body")[0].className = "hide-scrollbar";
window.removeEventListener("message", function () {});
window.addEventListener('message', function (e) {
let height = e.data ? e.data.height : null;
if (height) {
var iframe = document.getElementById("myiframe");
try {
iframe.height = height;
iframe.style.height = height + "px";
} catch (ex) {}
}
});
},
beforeDestroy() {
// 移除隐藏滚动条样式
// document.body.removeAttribute("class", "hide-scrollbar");
},
created() {
}
}