PageSourceSearch

https://mrcrm.com/crm/login2/index.js

js mrcrm.com collected 2026-10-04 15:57:25 UTC 14,158 bytes, 507 lines download raw bytes

1function onWeixinLoginCode(appid, appcode) {
2
3    $.toast('onWeixinLoginCode: (' + appid + ', ' + appcode + '). location: ' + window.location);
4
5}
6
7function showError(message) {
8    $("body").find('#error-div').text(message).hide().fadeIn();
9}
10
11function showSpinner() {
12    $.showButtonSpinner($('#btn-login'));
13}
14
15function hideSpinner() {
16    $.hideButtonSpinner($('#btn-login'));
17}
18
19function redirect() {
20    var redirect = $.getParameter("redirect");
21    location.href = redirect ? redirect : "/crm/";
22}
23
24var __ROOT_DOMAINS__ = ["localhost", "mrcrm.com", "mrcrm.cn", "crmip.cn", "jinghuasoft.com"];
25
26function isNatAddress(host) {
27    if (/^[\\d\.]+$/g.test(location.hostname)) {
28        // 如果是 IP
29        return true;
30    }
31    return false;
32}
33
34function getDomainFromRequest() {
35
36    var hostname = location.hostname;
37
38    if (isNatAddress(hostname)) {
39        return null;
40    }
41
42    for (var i = 0; i < __ROOT_DOMAINS__.length; i++) {
43        if (hostname == __ROOT_DOMAINS__[i]) {
44            return null;
45        }
46    }
47
48    for (var i = 0; i < __ROOT_DOMAINS__.length; i++) {
49        if (hostname.endsWith("." + __ROOT_DOMAINS__[i])) {
50            var ss = location.hostname.split(".");
51            return ss[0];
52        }
53    }
54
55    return null;
56
57}
58
59function getRootDomain() {
60
61    var hostname = location.hostname;
62
63    if (isNatAddress(hostname)) {
64        return hostname;
65    }
66
67    if (isRootDomain(hostname)) {
68        return hostname;
69    }
70
71    var rootDomain = hostname.substring(hostname.indexOf(".") + 1);
72    return rootDomain;
73
74}
75
76function getRootDomainWithPort() {
77
78    var rootDomain = getRootDomain();
79
80    if (location.port) {
81        return rootDomain + ":" + location.port;
82    }
83    return rootDomain;
84
85}
86
87function isRootDomain(hostname) {
88
89    for (var i = 0; i < __ROOT_DOMAINS__.length; i++) {
90        if (hostname == __ROOT_DOMAINS__[i]) {
91            return true;
92        }
93    }
94
95    return false;
96}
97
98$(function () {
99
100    // $('[role="root-domain-with-port"]').text("." + getRootDomainWithPort());
101    $('[role="root-domain-with-port"]').text(".mrcrm.com");
102
103    if (window.webkit && window.webkit.messageHandlers.call) {
104        // 苹果客户端。不能显示注册、试用等按钮,否则 app 申请不通过。
105        $('[role="btn-register"]').hide();
106    }//
107    else {
108        $('[role="btn-register"]').show();
109    }
110
111    function showDomain() {
112        var dd = $('[role="div-domain"]');
113        if (dd.is(":visible")) {
114            // 当前显示。闪烁。
115            dd.hide().fadeIn();
116        }//
117        else {
118            // 当前隐藏。下拉显示。
119            $('[role="div-domain"]').slideDown();
120        }
121    }
122
123    function toggleDomain() {
124        var dd = $('[role="div-domain"]');
125        if (dd.is(":visible")) {
126            // 当前显示。隐藏。
127            $('[role="div-domain"]').slideUp();
128        }//
129        else {
130            // 当前隐藏。显示。
131            $('[role="div-domain"]').slideDown();
132        }
133    }
134
135    function setLocation(url) {
136        // 在 app 里设置并记住默认首页
137        if (window.android) {
138            try {
139                window.android.setLocation(url);
140            } catch (e) {
141                window.location.href = url;
142            }
143        }//
144        else if (window.webkit && window.webkit.messageHandlers.call) {
145            ios_native_call("setLocation", url, function () {
146            });
147        }//
148        else {
149            location = url;
150        }
151    }
152
153    function redirectToDomain(domain) {
154
155        if (!domain) {
156            return;
157        }
158
159        if (isNatAddress(location.hostname)) {
160            return;
161        }
162
163        if (domain == "crm") {
164            // 内部域名。特殊处理。
165            if (isRootDomain(location.hostname)) {
166                // 根域名。无须处理。
167                return;
168            }//
169            else {
170                // 回到对应的根域名。
171                $('#error-div').html('请稍后... ');
172                $.showButtonSpinner($('#error-div'));
173                setTimeout(function () {
174                    // "http(s):" + "//" + "mrcrm.com:8443";
175                    setLocation(location.protocol + "//" + getRootDomainWithPort() + "/crm/");
176                }, 500);
177                return;
178            }
179        }//
180        else {
181
182            var dd = getDomainFromRequest();
183            if (dd == domain) {
184                // 就是当前子域名。无须处理。
185                return;
186            }//
187            else {
188
189                $('#error-div').html('请稍后... ');
190                $.showButtonSpinner($('#error-div'));
191                setTimeout(function () {
192                    // "http(s):" + "//" + "hzjd" + "." + "mrcrm.com:8443".
193                    var rootDomainWithPort = getRootDomainWithPort();
194                    if (rootDomainWithPort == "localhost") {
195                        // 研发系统
196                        setLocation("https://" + domain + ".mrcrm.com/crm/");
197                    }//
198                    else {
199                        // 生产环境
200                        setLocation(location.protocol + "//" + domain + "." + rootDomainWithPort + "/crm/");
201                    }
202                }, 500);
203                return;
204
205            }
206
207        }
208
209    }
210
211    function showTenantName(name) {
212
213        $('[role="company-name"]').html(name);
214
215        if (name.length >= 10) {
216            $('[role="company-name"]').css("fontSize", "24px");
217        }
218
219    }
220
221    /**
222     * 显示企业信息。如果是切换企业,则重定向到新企业地址。
223     *
224     * @param redirect 是否重定向。第一次打开页面的时候,显示企业信息,但是不重定向。输入别的域名的时候,显示企业信息,并且重定向。
225     * @param callback
226     */
227    function showTenantInfo(redirect, callback) {
228
229        try {
230
231            var domain = $("#domain").val();
232
233            if (domain.startsWith("https://") || domain.startsWith("http://")) {
234                // 支持研发系统。即,可以在手机的域名框内输入网址,打开一个页面。比如,在 app 中打开某个研发系统。
235                // 只重定向,不记录到手机里。即,杀掉 app 重新登录,又打开原来的 crm 页面。
236                window.location.href = domain;
237                return;
238            }
239
240            $.execute(
241                "login.action",
242                "getTenantInfo",
243                {
244                    domain: domain
245                },
246                function (tenantInfo) {
247
248                    try {
249
250                        if (tenantInfo) {
251
252                            showTenantName(tenantInfo.name);
253
254                            if (redirect) {
255                                redirectToDomain(domain);
256                            }//
257                            else {
258                                // 只显示。不重定向。
259                            }
260
261                        }//
262                        else {
263                            // 没有该 tenant
264                            $('[role="company-name"]').html("企业不存在: " + domain);
265                        }
266
267                        if (callback) {
268                            callback();
269                        }
270
271                    } catch (e) {
272
273                        $.error('' +
274                            '<pre>' +
275                            '   ' + e.message + '. ' +
276                            '   stack: ' +
277                            '   ' + e.stack + '' +
278                            '</pre>');
279
280                    }
281
282
283                });
284
285        } catch (e) {
286
287            $.error('' +
288                '<pre>' +
289                '   ' + e.message + '. ' +
290                '   stack: ' +
291                '   ' + e.stack + '' +
292                '</pre>');
293
294        }
295
296    }
297
298    function login() {
299
300        var domain = $("#domain").val().trim();
301        var account = $("#account").val().trim();
302        var password = $("#password").val().trim();
303        var remember = $("#remember").prop("checked");
304        var sessionId = new Date().getTime(); // $.cookie("session-id");
305
306        if (!domain) {
307            showDomain();
308            showError("请输入域");
309            $("#domain").focus();
310            return;
311        }
312
313        if (!account) {
314            showError("请输入账号");
315            $("#account").focus();
316            return;
317        }
318
319        if (!password) {
320            showError("请输入密码");
321            $("#password").focus();
322            return;
323        }
324
325        if (domain) {
326            if (domain.indexOf(".") >= 0) {
327                showError("无效域名: " + domain);
328                showDomain();
329                return;
330            }
331        }
332
333        showSpinner();
334
335        // osType 在前端解析(Win10/11 只能通过 userAgentData 区分)
336        $.getOsType(function (osType) {
337
338        $.execute(
339            "login.action",
340            "login",
341            {
342                domain: domain,
343                account: account,
344                sessionId: sessionId,
345                loginToken: hex_md5(account + password + sessionId),
346                remember: remember,
347                osType: osType
348            },
349            function (userInfo) {
350
351                window.userInfo = userInfo;
352
353                // 延迟重定向。显示动画效果
354                setTimeout(function () {
355                    redirect();
356                }, 500);
357
358            },
359            function (error) {
360
361                // 延迟操作,显示动画效果
362                setTimeout(function () {
363                    hideSpinner();
364                    showError(error);
365                }, 500);
366
367            });
368
369        });
370
371
372    }
373
374    // 提前解析操作系统类型(userAgentData 为异步接口),点击登录时通常已缓存,避免延迟登录请求
375    $.getOsType(function () {});
376
377    $("body").on("click", '#btn-login', function () {
378        login();
379    });
380    $("body").on("keypress", '#account', function (event) {
381        if (event.keyCode == 13 || event.keyCode == 10) {
382            $("#password").focus().select();
383        }
384    });
385    $("body").on("keypress", '#password', function (event) {
386        if (event.keyCode == 13 || event.keyCode == 10) {
387            $('[role=btn-login]').click();
388        }
389    });
390    $("body").on("change", '#domain', function () {
391
392        var domain = $("#domain").val();
393
394        if (!domain) {
395            return;
396        }
397
398        if (domain.startsWith("http:") || domain.startsWith("https:")) {
399
400        }//
401        else if (domain.contains(".")) {
402            showError("非法的域名: " + domain);
403            return;
404        }
405
406        // 显示小圆圈,表示正在切换,同时禁掉所有的输入框
407        // 原因:手机处理速度慢,或者网速慢,切换domain可能非常慢。需要一个提示。
408
409        $('[role="spinner-company-name"]').show();
410        $('[role="company-name"]').hide();
411
412        $("#account").prop("disabled", true);
413        $("#password").prop("disabled", true);
414        $("#remember").prop("disabled", true);
415        $("#btn-login").prop("disabled", true);
416
417        showTenantInfo(true, function () {
418
419            $('[role="spinner-company-name"]').hide();
420            $('[role="company-name"]').show();
421
422            $("#account").prop("disabled", false);
423            $("#password").prop("disabled", false);
424            $("#remember").prop("disabled", false);
425            $("#btn-login").prop("disabled", false);
426
427        });
428    });
429    $("body").on("click", '[role="div-domain"]', function () {
430        $("#domain").focus();
431    });
432    $("body").on("click", '[role="btn-switch-domain"]', function () {
433        // showDomain();
434        toggleDomain();
435    });
436
437    var message = $.getParameter("message");
438    if (message) {
439        showError(message);
440    }
441
442    var domain = getDomainFromRequest();
443
444    if (domain) {
445        // 有域名。显示域名。
446        $("#domain").val(domain);
447    }//
448    else {
449        // 显示默认域名。
450        $.execute("login.action", "getDefaultDomain", function (domain) {
451            $("#domain").val(domain);
452        });
453    }
454
455    $("#account").val($.cookie("account"));
456
457    if (isRootDomain(location.hostname)) {
458        // 默认域名。登陆过则直接重定向。否则显示 domain
459        $('[role="div-domain"]').show();
460    }//
461    else {
462        $('[role="div-domain"]').show();
463        // $('[role="div-domain"]').hide();
464    }
465
466    if (window.android || window.webkit) {
467        $("#remember").prop("checked", true);
468    }
469
470    showTenantInfo(false, function () {
471
472        $.execute("user.action", "getUserInfo", {silence: true}, function (userInfo) {
473            if (userInfo) {
474                // 已经登录。转到主页面。防止用户收藏的是登录页面,重复登录的问题。
475                location = "/crm/";
476            }//
477            else {
478                // $.error("no user info. cookie: " + document.cookie);
479            }
480        });
481
482    });
483
484    $.execute(
485        "license.action",
486        "getSystemInfo",
487        function (systemInfo) {
488
489            window.systemInfo = systemInfo;
490
491            if (systemInfo) {
492
493                if (systemInfo.javascriptForLogin) {
494                    eval(systemInfo.javascriptForLogin);
495                }
496
497            }//
498            else {
499                // 没有授权?
500            }
501
502        },
503        function (error) {
504            // 隐藏错误信息
505        });
506
507});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.