chenhaozhe
3 天以前 cfa35ff1f39c2a7b69d624d45f8e05591f3375d4
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
163
164
165
166
167
168
169
170
171
172
173
174
 
function GetWEBURL() {
    //var WEBURL = "http://192.168.16.80:8011/";        //办公室服务器
    //var WEBURL = "http://61.164.86.218:8099/ABAPI/";
    //var WEBURL = "http://localhost/API/";             //颜晓军本地配置
    //var WEBURL = "http://localhost:8082/API/";        //杜贺本地配置
    //var WEBURL = "http://localhost:81/API/"           //翁涛涛本地配置
    // var WEBURL = "http://localhost:8082/API/";        //张瑞广本地配置
    var WEBURL = "http://localhost:81/API/";          //陈镐哲本地配置
    //var WEBURL = "http://localhost:8082/LuBaoAPI/";   //李林俊本地配置
    //var WEBURL = "http://localhost:8080/API/";        //王仪本地配置
    //var WEBURL = "http://localhost:8082/LuBaoAPI/";   //余思杰本地配置
    //var WEBURL = "http://localhost:8088/ARAPI/";      //余思杰本地配置(安瑞)
    //var WEBURL = "http://47.96.97.237/API/";          //智云服务器
    /* var WEBURL = "http://localhost:8082/LuBaoAPI/";  //余思杰本地配置*/
    // var WEBURL = "http://localhost:81/API/";            // 陈镐哲本地配置*/
    //var WEBURL = "http://localhost:8082/LuBaoAPI/";  //李林俊本地配置
    //var WEBURL = "http://localhost:8088/ARAPI/";      //余思杰本地配置(安瑞)
    //var WEBURL = "http://61.164.86.218:8099/ABAPI/";  //奥邦
    //var WEBURL = "http://10.1.4.155/API/";            //江丰客户NEW
    //var WEBURL = "http://183.129.128.86:9090/API/";   //凯贝奈特客户服务器外网
    //var WEBURL = "http://192.168.1.253:8080/API/";    //凯贝奈特客户服务器内网
    //var WEBURL = "http://220.189.218.154:8092/API/";  //丸井四维尔服务器
    //var WEBURL = "http://192.168.0.214/API/";         //瑞与祺服务器
    //var WEBURL = "http://192.168.10.66/API/";         //森楷服务器
    //var WEBURL = "http://192.168.80.90:9090/API/";    //安瑞服务器
    //var WEBURL = "http://192.168.16.53:8081/API/";    //龙山汽配
    //var WEBURL = "http://122.227.158.218:8090/API/";  //龙山汽配外网
    //var WEBURL = "http://192.168.0.244:8082/API/";    //帅威内网
    //var WEBURL = "http://192.168.1.237:9003/API";     //夏宝内网
    //var WEBURL = "http://60.190.4.42:9003/API";       //夏宝外网
    //var WEBURL = "http://192.168.60.12/API";          //中控
    //var WEBURL = "http://192.168.6.5:8082/API/";      //舜成
    //var WEBURL = "http://121.36.199.126:8181/API/";   //三升
    //var WEBURL = "http://36.134.2.30:200/WEBS-API/";  //金帅
    //var WEBURL = "http://172.16.1.85/API/";           //迦南
    // var WEBURL = "http://61.164.64.222:8082/API_WW/"
    return WEBURL
}
 
function GetWEBURlLanguage() {
    return GetWEBURL()
}
 
layui.use(['jquery', 'layer'], function () {
    var $ = layui.jquery,
        layer = layui.layer;
    // 全局配置
    layer.config({
        scrollbar: false
    });
 
    var pendingRequests = [];
 
    // 全局配置 默认不显示父级滚动框
    var _open = layer.open;
    layer.open = function (opts) {
        // 合并默认配置
        var options = $.extend({}, layer.config, opts);
 
        var oldSuccess = options.success;
        var oldEnd = options.end;
        var needHideScroll = options.scrollbar === false;
 
        // 打开弹窗时
        options.success = function (layero, index) {
            if (needHideScroll) {
                $('body').css('overflow', 'hidden');
            }
            if (oldSuccess) oldSuccess.call(this, layero, index);
        };
 
 
        // 关闭弹窗时
        options.end = function () {
            if (needHideScroll) {
                // 只有最后一个弹窗关闭才恢复
                if ($('.layui-layer:visible').length <= 1) {
                    $('body').css('overflow', '');
                }
            }
            if (oldEnd) oldEnd.call(this);
        };
 
        return _open.call(this, options);
    };
 
 
    // 全局拦截所有 layui ajax 请求
    $(document).ajaxSend(function (event, jqxhr, settings) {
        var token = localStorage.getItem('token');
        pendingRequests.push(jqxhr);
 
        if (typeof token != 'undefined') {
            // 自动带上 token
            jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
 
        }
 
    });
 
 
    // 统一处理 未认证/未授权请求
    $(document).ajaxComplete(function (event, jqxhr, settings) {
        // HTTP 状态码
        var status = jqxhr.status;
        console.log(jqxhr)
        if (status === 401) {
            abortAllPendingRequests(pendingRequests);
            // 未登录 / token 过期
            layer.confirm(jqxhr.responseJSON.Message, { icon: 7, title: '提示' }, function () {
                localStorage.removeItem('token');
                window.top.location.href = '/views/user/login.html'; // 跳到登录页
 
            });
        } else if (status === 403) {
            abortAllPendingRequests(pendingRequests);
            // 无权限
            layer.confirm(jqxhr.responseJSON.Message, {
                icon: 4, skin: 'layui-layer-lan', title: "温馨提示", closeBtn: 0, btn: ['确定']
            });
        }
    });
});
var pendingRequests2 = []
if (typeof $ != 'undefined') {
    $(document).ajaxSend(function (event, jqxhr, settings) {
        var token = localStorage.getItem('token');
        pendingRequests2.push(jqxhr)
 
        if (typeof token != 'undefined') {
            // 自动带上 token
            jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
        }
 
    });
 
 
    // 统一处理 未认证/未授权请求
    $(document).ajaxComplete(function (event, jqxhr, settings) {
        // HTTP 状态码
        var status = jqxhr.status;
 
        if (status === 401) {
            // 未登录 / token 过期
            abortAllPendingRequests(pendingRequests2)
            layer.confirm(jqxhr.responseJSON.Message, { icon: 7, title: '提示' }, function () {
                localStorage.removeItem('token');
                window.top.location.href = '/views/user/login.html'; // 跳到登录页
 
            });
        } else if (status === 403) {
            // 无权限
            abortAllPendingRequests(pendingRequests2)
            layer.confirm(jqxhr.responseJSON.Message, {
                icon: 4, skin: 'layui-layer-lan', title: "温馨提示", closeBtn: 0, btn: ['确定']
            });
        }
    });
}
 
function abortAllPendingRequests(pendingRequests) {
    if (pendingRequests.length === 0) return;
 
    // 遍历取消所有请求
    $.each(pendingRequests, function (i, req) {
        try {
            req.abort(); // 中断请求
        } catch (e) { }
    });
 
    // 清空请求池
    pendingRequests = [];
}