portal html css js resource

loginNew.js 9.3KB

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