Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
157
158
159
160
161
162
//处理登录页面的相关动作
//weidy@2013-08-01
 
var path = "";//后台路径
var configData = {};
var browserInfo = null;
var processStep = 0;
var processInterval = null;
var usedTime = 0;
var projectName = "";
var pathName = "";
$(document).ready(function() {
    // 先判断浏览器版本
    browserInfo = checkBrowser();
    pathName = window.document.location.pathname;
    projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1) + "/";
    //处理页面的内容
    getConfig(function(){
        checkParamFromSso(function(username,params){
            doSingleLogin(username,params);
        });
    });
});
function getConfig(callback){
    $.getJSON(projectName + "config.json",function(data){
        configData = data;
        if(configData.isDebug == "true" || configData.isDebug == true){
            path = configData.backPath;
        }else{
            path = pathName;
            if(pathName.indexOf("/")>-1){
                path = path.substring(0,path.lastIndexOf("/"));
            }
        }
        if(callback){
            callback();
        }
    });
}
 
 
function checkParamFromSso(callback){
    $.ajax({
        url:window.location,
        type:'POST',
        success:function(data,textStatus,jqXHR){
            var userid = jqXHR.getResponseHeader('iv-user');
            if(!userid || userid == null || userid == ''){
                showError("没有获取到用户名,无法执行单点登录");
                return false;
            }
            var params = new Object();
            var url = window.location.search;
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for(var i = 0; i < strs.length; i ++) {
                    params[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            if(callback){
                callback(userid,params);
            }
        },
        error:function(jqXHR,textStatus,errorThrown){
            showError("出现了异常,无法单点登录," + textStatus);
        }
    });
}
 
function crosPost(url1,data,callback,errorCallback){
    $.ajax({
        type:'post',
        // xhrFields: {
        //     withCredentials: true
        // },
        // crossDomain: configData.isDebug?(true == !(document.all)):false,
        url:path + url1,
        data:data,
        success:function(data){
            var result = eval("(" + data + ")");
            if(callback){
                callback(result);
            }
        },
        error:function(xhr,error){
            if(errorCallback){
                errorCallback(xhr,error);
            }
        }
    });
}
 
 
// 显示错误
function showError(text) {
    $("#msg").html( text);
    $("#errorMsg").show();
}
 
 
 
// 登录
function doSingleLogin(userid,params) {
    showLoading();
    var loginData = {
        userid : userid,
        password : "",
        isForceLogin : true,
        browser:browserInfo.browser,
        browserversion:browserInfo.browserversion,
        osversion: browserInfo.osversion
    };
    for(var key in params){
        loginData[key] = params[key];
    }
    //因为每个项目,在登录后获取的内容可能会有不一样,所以登录的路径支持配置configData.loginUrl
    crosPost(configData.singleLoginUrl,loginData,function(result){
        hideLoading();
        if(result == undefined || result == null){
            showError("登录出现了错误!请查看服务器是否开启");
        }
        if (result.success){
            window.location.href = projectName + "main.html";
        }else {
            showError(result.msg);
        }
    },function(xhr,error){
        hideLoading();
        showError(error);
    });
}
 
function showLoading(){
    $(".loadbg").show();
    $(".processbar").show();
    $(".loading").show();
    var preWidth = $(".loading").css("width");
    if(preWidth.indexOf("px")>-1){
        preWidth = preWidth.replace("px","");
    }
    preWidth = preWidth*1/10;
    processInterval = window.setInterval(function(){
        $("#useTime").html(usedTime + 1);
        $(".processbar").css("width",preWidth*(processStep+1));
        usedTime ++;
        processStep ++ ;
        if(processStep == 10){
            processStep = 0;
        }
    },1000);
}
function hideLoading(){
    $(".loadbg").hide();
    $(".processbar").hide();
    $(".loading").hide();
    processStep = 0;
    usedTime =0;
    if(processInterval != null){
        window.clearInterval(processInterval);
    }
}