portal html css js resource

loginNew.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. $(function() {
  2. $(".loginWaySort").on("click", "li", function() {
  3. $(this).parents("#container").find("input").val("");
  4. $(this).parents("#container").find(".frmmsg span").text("");
  5. $(this).parents("#container").find("input").removeClass("frmmsg-warning");
  6. $(this).parents("#container").find(".loginSubmit").attr("disabled", true);
  7. $("#getcode").attr("disabled", true);
  8. $(this).addClass("liactive").siblings().removeClass("liactive");
  9. $(".loginWays ul").eq($(this).index()).removeClass("displayNone").siblings().addClass("displayNone");
  10. })
  11. })
  12. var namePass = false;
  13. var passwordPass = false;
  14. var codePass = false;
  15. var verification = false;
  16. /*校验登录按钮显示状态*/
  17. function checkLoginButtn(_this) {
  18. var username = $(_this).parents(".cmpCoverUl").find(".username").val();
  19. var passwd = $(_this).parents(".cmpCoverUl").find(".passwd").val();
  20. if(username == "" || passwd == "") {
  21. $(_this).parents(".cmpCoverUl").find(".loginSubmit").attr("disabled", true);
  22. } else {
  23. $(_this).parents(".cmpCoverUl").find(".loginSubmit").attr("disabled", false);
  24. }
  25. }
  26. /*获取焦点*/
  27. function getFocus(_this) {
  28. $(_this).next().find("span").text("");
  29. $(_this).removeClass("frmmsg-warning");
  30. }
  31. //校验登录手机和邮箱账户
  32. function nameVal(_this) {
  33. var loginName = $(_this).val();
  34. var gunf = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  35. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  36. if(loginName.length == "") {
  37. $(_this).next().find("span").text("请输入您的手机或邮箱");
  38. $(_this).addClass("frmmsg-warning");
  39. } else if(gunf.test(loginName.trim())) {
  40. userRegisterOk(_this);
  41. $(_this).next().find("span").text("");
  42. $(_this).removeClass("frmmsg-warning");
  43. namePass = true;
  44. } else if(hunPhone.test(loginName.trim())) {
  45. userRegisterOk(_this);
  46. $(_this).next().find("span").text("");
  47. $(_this).removeClass("frmmsg-warning");
  48. namePass = true;
  49. } else {
  50. $(_this).next().find("span").text("请输入正确的手机或邮箱");
  51. $(_this).addClass("frmmsg-warning");
  52. }
  53. }
  54. //校验登录手机账户
  55. function phoneVal(_this) {
  56. var loginName = $(_this).val();
  57. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  58. if(loginName.length == "") {
  59. $(_this).next().find("span").text("请输入您的手机号码");
  60. $(_this).addClass("frmmsg-warning");
  61. } else if(hunPhone.test(loginName.trim())) {
  62. userRegisterOk(_this);
  63. $(_this).next().find("span").text("");
  64. $(_this).removeClass("frmmsg-warning");
  65. namePass = true;
  66. } else {
  67. $(_this).next().find("span").text("请输入正确的手机号码");
  68. $(_this).addClass("frmmsg-warning");
  69. $("#getcode").attr("disabled", true);
  70. }
  71. }
  72. //判断账号是否注册
  73. function userRegisterOk(_this) {
  74. var loginName = $(_this).val();
  75. $.ajax("/ajax/isReg?key=" + loginName, {
  76. type: "GET",
  77. async: true,
  78. success: function($data) {
  79. if($data.data == true) {
  80. $(_this).next().find("span").text("该账号不存在,请检查后重试");
  81. $(_this).addClass("frmmsg-warning");
  82. } else {
  83. $(_this).next().find("span").text("");
  84. $(_this).removeClass("frmmsg-warning");
  85. $("#getcode").attr("disabled", false);
  86. }
  87. },
  88. error: function() {
  89. $.MsgBox.Alert('消息', '服务器请求失败')
  90. },
  91. });
  92. }
  93. //校验登录密码
  94. function passwordVal(_this) {
  95. var passwd = $(_this).val();
  96. if(passwd.length == "") {
  97. $(_this).next().find("span").text("请输入您的登录密码");
  98. $(_this).addClass("frmmsg-warning");
  99. } else if(passwd.length < 6) {
  100. $(_this).next().find("span").text("密码由6-24个字符组成,区分大小写");
  101. $(_this).addClass("frmmsg-warning");
  102. } else {
  103. $(_this).next().find("span").text("");
  104. $(_this).removeClass("frmmsg-warning");
  105. passwordPass = true;
  106. }
  107. }
  108. //验证短信验证码
  109. function codeVerification(_this) {
  110. var code = $(_this).val();
  111. var reg = /^\d{4}$/;
  112. if(code.length == "") {
  113. $(_this).next().find("span").text("请输入您收到的短信验证码");
  114. $(_this).addClass("frmmsg-warning");
  115. } else if(!reg.test(code)) {
  116. $(_this).next().find("span").text("验证码为4位数字");
  117. $(_this).addClass("frmmsg-warning");
  118. } else {
  119. $(_this).next().find("span").text("");
  120. $(_this).removeClass("frmmsg-warning");
  121. verification = true;
  122. }
  123. }
  124. //手机发送验证码
  125. function phoneSend(_this) {
  126. doClick(_this);
  127. phoneVerificationCode(_this);
  128. }
  129. function doClick(_this) {
  130. $(_this).attr("disabled", true);
  131. $(_this).text("60s后重新获取");
  132. var clickTime = new Date().getTime();
  133. var Timer = setInterval(function() {
  134. var nowTime = new Date().getTime();
  135. var second = Math.ceil(60 - (nowTime - clickTime) / 1000);
  136. if(second > 0) {
  137. $(_this).text(second + "s后重新获取");
  138. } else {
  139. clearInterval(Timer);
  140. $(_this).text("获取验证码");
  141. $(_this).attr("disabled", false);
  142. }
  143. }, 1000);
  144. }
  145. //手机发送验证码结束
  146. var state;
  147. function phoneVerificationCode(_this) {
  148. var lp_phone = $(_this).parents(".cmpCoverUl").find(".username").val();
  149. $.ajax("/ajax/sendMobileForLogin", {
  150. type: "get",
  151. dataType: 'json',
  152. data: {
  153. "mobilePhone": lp_phone
  154. },
  155. async: true,
  156. success: function(data) {
  157. console.log(JSON.stringify(data))
  158. if(data.success) {
  159. state = data.data;
  160. }
  161. },
  162. error: function() {
  163. $.MsgBox.Alert('消息', '服务器请求失败')
  164. }
  165. });
  166. };
  167. //验证邀请码
  168. function codeVal(_this) {
  169. var code = $(_this).val();
  170. var reg = /^\d{6}$/;
  171. if(code.length == "") {
  172. $(_this).next().find("span").text("请输入您收到的邀请码");
  173. $(_this).addClass("frmmsg-warning");
  174. } else if(!reg.test(code)) {
  175. $(_this).next().find("span").text("邀请码为6位数字");
  176. $(_this).addClass("frmmsg-warning");
  177. } else {
  178. $(_this).next().find("span").text("");
  179. $(_this).removeClass("frmmsg-warning");
  180. codePass = true;
  181. }
  182. }
  183. //判断用户第一次登录,是否填写了个人信息
  184. function firstLogin() {
  185. var professorId = $.cookie('userid');
  186. $.ajax({
  187. "url": "ajax/professor/" + professorId,
  188. "type": "get",
  189. "async": false,
  190. "success": function(data) {
  191. console.log(data)
  192. if(data.success) {
  193. if(data.data.authentication != undefined || data.data.authentication != null){
  194. alert(11)
  195. window.history.back();
  196. }else{
  197. alert(22)
  198. location.href = "fillinfo-select.html?id=" + professorId;
  199. }
  200. }
  201. },
  202. "error": function() {
  203. $.MsgBox.Alert('消息', '服务器请求失败')
  204. }
  205. })
  206. }
  207. //密码登录
  208. function passwdLogin(_this) {
  209. var loginName = $(_this).parents(".cmpCoverUl").find(".username");
  210. var passwordd = $(_this).parents(".cmpCoverUl").find(".passwd");
  211. if(namePass && passwordPass) {
  212. $.ajax("/ajax/login", {
  213. type: "POST",
  214. data: {
  215. "pw": passwordd.val(),
  216. "lk": loginName.val()
  217. },
  218. dataType: 'json',
  219. async: false,
  220. success: function(data) {
  221. if(data.success) {
  222. if(data.data != "null" && data.data != null) {
  223. firstLogin();
  224. } else {
  225. $(_this).parents(".cmpCoverUl").find(".msgLog2 span").text("登录账号和密码不匹配");
  226. }
  227. }
  228. },
  229. error: function() {
  230. $.MsgBox.Alert('消息', '服务器请求失败');
  231. }
  232. });
  233. }
  234. }
  235. //手机验证码登录
  236. function VerificationLogin(_this) {
  237. var loginName = $(_this).parents(".cmpCoverUl").find(".username");
  238. var code = $(_this).parents(".cmpCoverUl").find(".passwd");
  239. if(namePass && verification) {
  240. $.ajax("/ajax/mobileLogin", {
  241. type: "POST",
  242. dataType: 'json',
  243. data: {
  244. "state": state,
  245. "mobilePhone": loginName.val(),
  246. "validateCode": code.val()
  247. },
  248. async: false,
  249. success: function(data) {
  250. console.log(data)
  251. if(data.success) {
  252. if(data.data != "null" && data.data != null) {
  253. firstLogin();
  254. }
  255. } else {
  256. if(data.code == -1) {
  257. $(_this).parents(".cmpCoverUl").find(".msgCmp03 span").text("验证码已过期,请重新获取");
  258. } else if(data.code == -3 || data.code == 0) {
  259. $(_this).parents(".cmpCoverUl").find(".msgCmp03 span").text("验证码错误,请检查后重试");
  260. }
  261. }
  262. },
  263. error: function() {
  264. $.MsgBox.Alert('消息', '服务器请求失败');
  265. },
  266. });
  267. }
  268. }
  269. //邀请码登录
  270. function InvitationLogin(_this) {
  271. var loginName = $(_this).parents(".cmpCoverUl").find(".username");
  272. var code = $(_this).parents(".cmpCoverUl").find(".passwd");
  273. if(namePass && codePass) {
  274. $.ajax("/ajax/invitelogin", {
  275. type: "POST",
  276. dataType: 'json',
  277. data: {
  278. "code": code.val(),
  279. "key": loginName.val()
  280. },
  281. async: false,
  282. success: function(data) {
  283. console.log(data)
  284. if(data.success) {
  285. if(data.data != "null" && data.data != null) {
  286. if(data.data.auth == true) {
  287. location.href = "index.html";
  288. } else {
  289. location.href = "loginInviteFirst.html";
  290. }
  291. } else {
  292. $(_this).parents(".cmpCoverUl").find(".msgLog2 span").text("邀请码错误,请检查后重试");
  293. }
  294. }
  295. },
  296. error: function() {
  297. $.MsgBox.Alert('消息', '服务器请求失败');
  298. },
  299. });
  300. }
  301. }
  302. //提交登录
  303. function login(_this, num) {
  304. if(num == 1) {
  305. passwdLogin(_this);
  306. } else if(num == 2) {
  307. InvitationLogin(_this);
  308. } else if(num == 3) {
  309. VerificationLogin(_this);
  310. }
  311. }