农燊高科官方网站
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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