网站
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

188 рядки
6.8 KiB

  1. /**
  2. * Created by admin on 2021/4/5.
  3. *
  4. */
  5. define(['jquery', "Tools","user"], function ($, Tools) {
  6. //数据存储
  7. var module = {
  8. uuid: '', //验证码uuid
  9. computeTime:60,
  10. timer:null
  11. };
  12. //自定义公共方法
  13. var tools = new Tools();
  14. //默认进入页面加载方法
  15. module.init = function (page) {
  16. //点击登录
  17. $('#login-submit').on('click', module.login)
  18. //点击图形验证码
  19. $('#graphicImg').on('click', module.verificationCode)
  20. //点击图形验证码
  21. $('#mobileGraphicImg').on('click', module.verificationCode1)
  22. //点击发送验证码
  23. $('#getSmsCode').on('click', module.getSmsCode)
  24. //图形验证码加载
  25. module.verificationCode()
  26. //图形验证码加载
  27. module.verificationCode1()
  28. //背景高度
  29. module.register()
  30. //网站配置信息(网站名称 底部联系方式 公安备案号 网站备案号)
  31. tools.getWebConfig();
  32. document.onkeydown = function (event) {
  33. var e = event || window.event;
  34. if (e && e.keyCode == 13) { //回车键的键值为13
  35. $("#login-submit").click(); //调用登录按钮的登录事件
  36. }
  37. };
  38. };
  39. module.getSmsCode = function () {
  40. var mobile = $('#mobile').val();
  41. tools.doPost(getSmsCode, {mobile:mobile,code:$('#mobileCode').val(),uuid:module.uuid}, module.getSmsCodeAjax, true)
  42. }
  43. module.getSmsCodeAjax = function (data) {
  44. module.uuid = data.uuid;
  45. module.computeTime = 60;
  46. module.timer = setInterval(() => {
  47. module.computeTime--;
  48. document.getElementById('getSmsCode').value = module.computeTime;
  49. if (module.computeTime <= 0) {
  50. clearInterval(module.timer);
  51. document.getElementById('getSmsCode').value = '发送验证码';
  52. }
  53. }, 1000);
  54. }
  55. //底部友情链接
  56. module.bottomFriendsLinks = function (data) {
  57. if (data.code == 200) {
  58. var content = data.data;
  59. console.log(content)
  60. module.data.friendsLinksList = content;
  61. var friendsLinksData = template('friendsLinksData', module.data);
  62. $("#friendsLinksContent").html(friendsLinksData);
  63. }
  64. }
  65. /*-----------------------------自定义方法-------------------------------------*/
  66. //登录方式切换
  67. loginTab = function(type){
  68. document.getElementById('loginTab').style.display = 'none'
  69. document.getElementById('phoneTab').style.display = 'none'
  70. document.getElementById(type+'Tab').style.display = 'block'
  71. $('#loginBtn').attr('class','')
  72. $('#phoneBtn').attr('class','')
  73. $('#'+type+'Btn').attr('class','active')
  74. }
  75. //背景高度
  76. module.register = function(){
  77. document.getElementById('registerBody').style.height = (document.body.offsetHeight - 112) +'px';
  78. }
  79. //图形验证码
  80. module.verificationCode = function () {
  81. tools.doGet(captchaImage_get, {}, module.verificationAjax, true)
  82. }
  83. module.verificationAjax = function (data) {
  84. if (data.code == 200) {
  85. $('#graphicImg').attr('src', 'data:image/gif;base64,' + data.img)
  86. module.uuid = data.uuid;
  87. }
  88. }
  89. //图形验证码
  90. module.verificationCode1 = function () {
  91. tools.doGet(captchaImage_get, {}, module.verificationAjax1, true)
  92. }
  93. module.verificationAjax1 = function (data) {
  94. if (data.code == 200) {
  95. $('#mobileGraphicImg').attr('src', 'data:image/gif;base64,' + data.img)
  96. module.uuid = data.uuid;
  97. }
  98. }
  99. //用户登录
  100. module.login = function () {
  101. if (module.check()) {
  102. var data = {};
  103. var usernameVal = tools.encrypt($('#username').val());
  104. var passwordVal = tools.encrypt($('#password').val());
  105. var codeVal = $('#code').val();
  106. data['username'] = usernameVal;
  107. data['password'] = passwordVal;
  108. data['code'] = codeVal;
  109. data['uuid'] = module.uuid;
  110. tools.doPost(login_post, data, module.loginData, true)
  111. }
  112. };
  113. //手动验证表单
  114. module.check = function () {
  115. var usernameVal = $('#username').val();
  116. var passwordVal = $('#password').val();
  117. var codeVal = $('#code').val();
  118. /* 手机号 */
  119. if (usernameVal == '') {
  120. $('#username')[0].focus()
  121. tools.initTips('请输入用户名', 'right', $('#username')[0], 2000)
  122. return false;
  123. }
  124. /* 密码 */
  125. if (passwordVal == '') {
  126. $('#password')[0].focus()
  127. tools.initTips('请输入密码', 'right', $('#password')[0], 2000)
  128. return false;
  129. } else if (parseInt(passwordVal.length) < 6 || parseInt(passwordVal.length) > 18) {
  130. $('#password')[0].focus()
  131. tools.initTips('请输入正确格式密码', 'right', $('#password')[0], 2000)
  132. return false;
  133. }
  134. /*图形验证码*/
  135. if (module.uuid == '' || codeVal == '') {
  136. $('#code')[0].focus()
  137. tools.initTips('请输入图形验证码', 'right', $('#code')[0], 2000)
  138. return false;
  139. }
  140. return true;
  141. }
  142. //登录校验
  143. module.loginData = function (data) {
  144. console.log(data)
  145. if (data.code == 500) {
  146. module.verificationCode()
  147. } else {
  148. tools.setCookie('Admin-Token', data.token, 24 * 60 * 60)
  149. //用户资料
  150. tools.doGet(userData, {}, module.userData);
  151. //tools.skip('/')
  152. }
  153. }
  154. //个人中心用户信息
  155. module.userData = function(data){
  156. if (data.code == 200) {
  157. var content = data.user;
  158. console.log(content)
  159. tools.setCookie('userId', content.userId, 24 * 60 * 60);
  160. tools.doGet(userMember + '/' + content.userId, {}, module.userMember);//memberType 1个人 2单位
  161. }
  162. }
  163. //个人中心用户资料
  164. module.userMember = function(data){
  165. if (data.code == 200) {
  166. var content = data.data;
  167. tools.setCookie('userName', content.realname, 24 * 60 * 60);
  168. tools.setCookie('memberId', content.id, 24 * 60 * 60);
  169. tools.setCookie('idCardNum',content.idCardNum,24 * 60 * 60)
  170. tools.setCookie('phone',content.phone,24 * 60 * 60)
  171. tools.setCookie('address',content.address,24 * 60 * 60)
  172. tools.setCookie('bankAddress',content.bankAddress,24 * 60 * 60)
  173. tools.setCookie('bankCardName',content.bankCardName,24 * 60 * 60)
  174. tools.setCookie('bankCardNum',content.bankCardNum,24 * 60 * 60)
  175. tools.skip('/')
  176. }
  177. }
  178. return module;
  179. });