wangzhibo
2021-09-06 2efb5d2a02ce47a9fd6f1cec138496aba72f0815
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
"use strict";
 
$(document).ready(function () {
  initView();
});
 
function initView() {
  //根据设置,加载不同样式或皮肤
  setStyleByTheme();
 
  // var guid;
 
  // 验证码刷新
  // $(".reload-vify").on("click", function () {
  //   var $img = $(this).children("img");
  //   guid = getGUID();
 
  //   $img.prop("src", baseUrl + "userlogin/captcha.jpg?uuid=" + guid);
  // });
  // $(".reload-vify").click();
 
  //登录按钮
  $("#btnLogin").click(function () {
    var user = $("#txtUser").val();
    if (user == null || user.length == 0) {
      layer.tips("请输入用户名", "#txtUser");
      return;
    }
 
    var pwd = $("#txtPwd").val();
    if (pwd == null || pwd.length == 0) {
      layer.tips("请输入密码", "#txtPwd");
      return;
    }
 
    //var captcha = $("#txtCaptcha").val();
    //if (captcha == null || captcha.length == 0) {
    //    layer.tips('请输入验证码', '#txtCaptcha');
    //    return;
    //}
 
    //请求后端,完成登录验证
    if (window.hasServer) {
      sendAjax({
        url: "pub/user/login",
        data: JSON.stringify({
          username: user, //登录用户名
          password: pwd, //登录密码
          // "captcha": captcha,    //登录验证码
          // "uuid": guid,        //登录验证码对应的uuid标识
        }),
        type: "post",
        contentType: "application/json",
        success: function (data) {
          haoutil.storage.add("token", data.token);
          haoutil.storage.add("user", JSON.stringify(data));
 
          location.href = "index.html";
        },
        error: function () {
          $("#txtCaptcha").val("");
          $(".reload-vify").click();
        },
      });
    } else {
      //客户端校验
      var arrUser = [
        { user: "mars3d", pwd: "mars3d" },
        { user: "marsgis", pwd: "marsgis" },
      ];
 
      var checkStatus = false;
      for (var i = 0; i < arrUser.length; i++) {
        var item = arrUser[i];
        if (user == item.user && pwd == item.pwd) {
          checkStatus = true;
          break;
        }
      }
      if (checkStatus) {
        haoutil.storage.add("user", JSON.stringify({ userId: 1, name: "火 星 科 技", username: user }));
        location.href = "index.html";
      } else {
        layer.tips("用户名或密码错误", "#txtUser");
      }
    }
  });
 
  $(document).keyup(function (event) {
    if (event.keyCode == 13) {
      $("#btnLogin").trigger("click");
    }
  });
}
 
function getGUID() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c == "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}
 
//根据设置,加载不同样式
function setStyleByTheme() {
  setInterval(slideSwitch, 5000);
  slideSwitch();
}
 
//图片轮播
function slideSwitch() {
  var $active = $("#loginBJ IMG.active");
  if ($active.length == 0) {
    $active = $("#loginBJ IMG:last");
  }
 
  // use this to pull the images in the order they appear in the markup
  var $next = $active.next().length ? $active.next() : $("#loginBJ IMG:first");
  $active.addClass("last-active");
 
  $next
    .css({ opacity: 0.0 })
    .addClass("active")
    .animate({ opacity: 1.0 }, 1000, function () {
      $active.removeClass("active last-active");
    });
}