vhis.js 3.04 KB
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: {},
        }
    },
    components: {
        Auth
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo
        }),
    },
    methods: {
        init() {
            if (this.isLogin()) {
                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() {
            let url = process.env.VUE_APP_VHIS_INDEX;
            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=VHIS001";
            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.outsideUrl = url;
        }
    },
    watch: {
    },
    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);
        // }
    },
    created() {
    }
}