|
@@ -0,0 +1,193 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+var API_ADDR = "",
|
|
|
+ SYS_ADDR = location.href.replace(/login\/+$/, ""),
|
|
|
+ COOKIE_EXPIRES = 1,
|
|
|
+ COOKIE_PATH = location.pathname.replace(/login\/+$/, "");
|
|
|
+var configurejs = SYS_ADDR + "configure.js";
|
|
|
+
|
|
|
+
|
|
|
+require([configurejs], function (AppX) {
|
|
|
+ API_ADDR = AppX.appConfig.apiRoot;
|
|
|
+ load();
|
|
|
+})
|
|
|
+function load() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var userInput = $(".username");
|
|
|
+ var passwordInput = $('.password');
|
|
|
+ var btnLogin = $('.login');
|
|
|
+ if (Cookies.get(hex_sha1("remember")) == "true") {
|
|
|
+ $(".remember_check").addClass("check");
|
|
|
+ userInput.val(getCookies("username"));
|
|
|
+ passwordInput.val(getCookies("psw"));
|
|
|
+ btnLogin[0].focus();
|
|
|
+ } else
|
|
|
+ userInput[0].focus();
|
|
|
+ $(document).keydown(enterKeyDown.bind(this));
|
|
|
+ btnLogin.on('click', loginCallBack.bind(this));
|
|
|
+ userInput.on('focus', function () {
|
|
|
+ $(".error").hide();
|
|
|
+ }.bind(this));
|
|
|
+ passwordInput.on('focus', function () {
|
|
|
+ $(".error").hide();
|
|
|
+ }.bind(this));
|
|
|
+ $(".remember_check").off("click").on("click", function (e) {
|
|
|
+ if ($(e.currentTarget).hasClass("check")) {
|
|
|
+ $(e.currentTarget).removeClass("check");
|
|
|
+ } else {
|
|
|
+ $(e.currentTarget).addClass("check");
|
|
|
+ }
|
|
|
+ }.bind(this))
|
|
|
+
|
|
|
+ function enterKeyDown() {
|
|
|
+ if (event.keyCode == 13) {
|
|
|
+ showLoading();
|
|
|
+ loginCallBack.bind(this)();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function showLoading() {
|
|
|
+ $(".login").attr("disabled", true);
|
|
|
+ $(".loginLoading").show();
|
|
|
+ $(".loginTxt").addClass("loginTxtLoading");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function hideLoading() {
|
|
|
+ $(".login").attr("disabled", false);
|
|
|
+ $(".loginLoading").hide();
|
|
|
+ $(".loginTxt").removeClass("loginTxtLoading");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ function loginCallBack(result) {
|
|
|
+ if (userInput.val() == '' && passwordInput.val() != '') {
|
|
|
+ hideLoading();
|
|
|
+ $(".error").show();
|
|
|
+ $(".errorInfoUsername").text("用户名不能为空!");
|
|
|
+ } else if (userInput.val() != '' && passwordInput.val() == '') {
|
|
|
+ hideLoading();
|
|
|
+ $(".error").show();
|
|
|
+ $(".errorInfoUsername").show().text("密码不能为空!");
|
|
|
+ } else if (userInput.val() == '' && passwordInput.val() == '') {
|
|
|
+ hideLoading();
|
|
|
+ $(".error").show();
|
|
|
+ $(".errorInfoUsername").show().text("用户名与密码不能为空!");
|
|
|
+ } else {
|
|
|
+ $.ajax({
|
|
|
+ url: API_ADDR + "/auth/oauth/token?project=8020",
|
|
|
+ data: {
|
|
|
+ "username": $.trim(userInput.val()),
|
|
|
+ "password": sm3($.trim(passwordInput.val()))
|
|
|
+ },
|
|
|
+ type: "post",
|
|
|
+ dataType: "json",
|
|
|
+ success: ajaxCallBack.bind(this),
|
|
|
+ error: errorCallBack.bind(this)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function getSearchString(key, Url) {
|
|
|
+ var str = Url;
|
|
|
+ str = str.substring(1, str.length);
|
|
|
+
|
|
|
+ var arr = str.split("&");
|
|
|
+ var obj = new Object();
|
|
|
+
|
|
|
+ for (var i = 0; i < arr.length; i++) {
|
|
|
+ var tmp_arr = arr[i].split("=");
|
|
|
+ obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
|
|
|
+ }
|
|
|
+ return obj[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ * 根据mydesk token登录
|
|
|
+ * @param {*} token
|
|
|
+ */
|
|
|
+ function loginWithTokenCheck(token) {
|
|
|
+ $.ajax({
|
|
|
+ url: API_ADDR + "/auth/oauth/login?project=8020",
|
|
|
+ headers: { "tokenCheck": token },
|
|
|
+ type: "GET",
|
|
|
+ dataType: "json",
|
|
|
+ success: ajaxCallBack.bind(this),
|
|
|
+ error: errorCallBack.bind(this)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ function ajaxCallBack(result) {
|
|
|
+ hideLoading();
|
|
|
+ if ($(".remember_check").hasClass("check")) {
|
|
|
+ var remember = hex_sha1("remember");
|
|
|
+ Cookies.set(remember, "true", {
|
|
|
+ path: SYS_ADDR
|
|
|
+ });
|
|
|
+ Cookies.set(hex_sha1("username"), Secret_Key(userInput.val(), 'encryption'), {
|
|
|
+ path: SYS_ADDR
|
|
|
+ });
|
|
|
+ Cookies.set(hex_sha1("psw"), Secret_Key(passwordInput.val(), 'encryption'), {
|
|
|
+ path: SYS_ADDR
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Cookies.remove(hex_sha1("remember"), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ Cookies.remove(hex_sha1("username"), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ Cookies.remove(hex_sha1("psw"), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (result.code == 1) {
|
|
|
+ Cookies.set(hex_sha1("username"), Secret_Key(userInput.val(), 'encryption'), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ Cookies.set(hex_sha1("token"), Secret_Key(result.result.accessToken, 'encryption'), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+
|
|
|
+ if (result.result.userLevel == "1") {
|
|
|
+ Cookies.set(hex_sha1("deptname"), Secret_Key("超级管理员", 'encryption'), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Cookies.set(hex_sha1("deptname"), Secret_Key(result.result.departmentName, 'encryption'), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Cookies.set(hex_sha1("realname"), Secret_Key(result.result.realName, 'encryption'), {
|
|
|
+ path: COOKIE_PATH
|
|
|
+ });
|
|
|
+
|
|
|
+ window.location.href = SYS_ADDR + "projectSelectPanel/";
|
|
|
+ } else {
|
|
|
+ $(".error").show();
|
|
|
+ $(".errorInfoUsername").text(result.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function errorCallBack(mesg) {
|
|
|
+ hideLoading();
|
|
|
+ console.log(mesg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取cookies值
|
|
|
+ */
|
|
|
+ function getCookies(name) {
|
|
|
+ var tempName = Cookies.get(hex_sha1(name));
|
|
|
+ if (tempName)
|
|
|
+ return Secret_Key(Cookies.get(hex_sha1(name)), 'decryption');
|
|
|
+ else
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|