portal html css js resource

loginNew.js 9.4KB

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