chengsc
2025-05-22 fd9ce381b904a22593de2ab242fb8f65cee45efa
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
//  var IP = "http://47.104.149.73:1991";//接口IP
// var IP = "https://localhost:44368";
//var IP = "http://localhost:13243/api";
var IP = "http://localhost:50515/api";
//var IP = "http://192.168.1.2:8017/";
// var IP = "http://192.168.10.112/WmsService/";
// var IP = "http://192.168.1.226:8086";
// var IP = "http://192.168.62.200:8888/api";  
jQuery.support.cors = true;
function sendData(url, data, type, callbackFun) {
    // callbackFun("{}");
    // return;
    var deferred = $.Deferred();
    if (type != "get") {
        data = JSON.stringify(data);
    }
    if (url != IP + "/WeatherForecast/Login") {
        if (!$.cookie('token')) {
            callbackFun("登录人信息已失效");
            try {
                parent.window.location.href = '/View/login.html';
            }
            catch (error) {
                window.location.href = '/View/login.html';
            }
            return;
        }
        if (isTokenExpired($.cookie('token'))) {
            try {
                parent.window.location.href = '/View/login.html';
            }
            catch (error) {
                window.location.href = '/View/login.html';
            }
            return;
        }
    }
    $.ajax({
        url: url,
        data: data,
        type: type,
        headers: {
            'Content-Type': 'application/json',
            "ToKen": $.cookie('token')
        },
        timeout: 45000,
        async: true,
        cache: false,
        beforeSend: function (xhr, settings) { },
        success: function (res, status, xhr) {
            callbackFun(res);
        },
        error: function (xhr, status, error) {
            callbackFun(xhr, status, error);
            // layer.msg(xhr.statusText, {
            //   icon: 2,
            //   time: 2000 //2秒关闭(如果不配置,默认是3秒)
            // }, function() {});
        }
    });
}
function synData(url, data, type, callbackFun) {
    var deferred = $.Deferred();
    if (type != "get") {
        data = JSON.stringify(data);
    }
    if (url != IP + "/WeatherForecast/Login") {
        if (!$.cookie('token')) {
            callbackFun("登录人信息已失效");
            try {
                parent.window.location.href = '/View/login.html';
            }
            catch (error) {
                window.location.href = '/View/login.html';
            }
            return;
        }
        if (isTokenExpired($.cookie('token'))) {
            try {
                parent.window.location.href = '/View/login.html';
            }
            catch (error) {
                window.location.href = '/View/login.html';
            }
            return;
        }
    }
    $.ajax({
        url: url,
        data: data,
        type: type,
        headers: {
            "Content-Type": "application/json",
            "ToKen": $.cookie('token'),
        },
        timeout: 45000,
        async: false,
        cache: false,
        beforeSend: function (xhr, settings) { },
        success: function (res, status, xhr) {
            callbackFun(res);
        },
        error: function (xhr, status, error) {
            console.log("失败了");
            console.log(xhr);
            callbackFun(xhr, status, error);
        },
    });
}
 
$("#navIcon").click(function () {
    if ($(".nav_list").css('display') == 'none') {
        $(".nav_list").show();
    } else {
        $(".nav_list").hide();
    }
});
 
//深拷贝
function deepCopy(obj) {
    let newobj = null     // 接受拷贝的新对象
    if (typeof (obj) == 'object' && typeof (obj) !== null) {   // 判断是否是引用类型
        newobj = obj instanceof Array ? [] : {}               // 判断是数组还是对象
        for (var i in obj) {
            newobj[i] = deepCopy(obj[i])                        // 判断下一级是否还是引用类型
        }
    } else {
        newobj = obj
    }
 
    return newobj
}
 
function isTokenExpired(token) {
    if(token==undefined||token==''){
        return true;
    }
    const tokenParts = token.split('.');
    if (tokenParts.length !== 3) {
      return true; // JWT 格式不正确
    }
    const payloadBase64 = tokenParts[1];
    const payload = JSON.parse(atob(payloadBase64));
    
    if (!payload || !payload.exp) {
      return true; // 没有有效载荷或者没有过期时间
    }
    
    const now = Date.now() / 1000; // 当前时间戳(秒)
    const expiration = payload.exp;
    
    return now >= expiration;
  }