Vue.use(window['vue-dash-event'])

window.onload = function () {
    var vm = new Vue({
        el: '#app',
        data: function () {
            return {
                account: "",
                passWord: "",
                clientId: null,
                domainUrl: config.apiHost,
            }
        },
        created() {
            let _clientId = localStorage.getItem('ocr-clientId')
            let _token = localStorage.getItem('ocr-token')
            if (_clientId) {
                this.clientId = _clientId;
            } else {
                this.clientId = md5(this.getGuid());
                localStorage.setItem("ocr-clientId", this.clientId);
            }
            if (_token) {
                window.location.href = 'index.html';
            }
        },
        methods: {
            getGuid() {
                function S4() {
                    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                }
                return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
            },
            login() {
                if (this.account && this.passWord) {
                    axios.interceptors.request.use(
                        config => {                            
                            config.headers.common["IsLogs"] = true;
                            return config;
                        }
                    )
                    let _url = this.domainUrl + 'v1/Login/SingleSignOnByLoginId';
                    let params = {
                        loginId: this.account,
                        loginPwd: md5(this.passWord),
                        isExclusiveLogin: true,
                        clientId: this.clientId,
                        clientType: 1,
                        systemId: 0,
                    }
                    axios
                        .post(_url, params)
                        .then(
                            res => {
                                let _res = res.Data;
                                if (_res.DetailedStatus == 1) {
                                    let _data = _res.Data;
                                    localStorage.setItem('ocr-token', _data.Token);
                                    localStorage.setItem('user-info', JSON.stringify(_data));
                                    window.location.href = 'index.html';

                                }
                            }
                        )
                }
            },
        },
    })
}