网站
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

407 Zeilen
13 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. loginType:'login'
  12. };
  13. //自定义公共方法
  14. var tools = new Tools();
  15. // 可调参数
  16. var BACKGROUND_COLOR = "#4A97F4"; // 背景颜色
  17. var POINT_NUM = 100; // 星星数目
  18. var POINT_COLOR = "rgba(255,255,255,0.7)"; // 点的颜色
  19. var LINE_LENGTH = 10000; // 点之间连线长度(的平方)
  20. // 创建背景画布
  21. var cvs = document.createElement("canvas");
  22. cvs.width = window.innerWidth;
  23. cvs.height = window.innerHeight;
  24. cvs.style.cssText = "\
  25. position:fixed;\
  26. top:0px;\
  27. left:0px;\
  28. z-index:-1;\
  29. opacity:1.0;\
  30. ";
  31. document.body.appendChild(cvs);
  32. var ctx = cvs.getContext("2d");
  33. var startTime = new Date().getTime();
  34. //默认进入页面加载方法
  35. module.init = function (page) {
  36. //点击登录
  37. $('#login-submit').on('click', module.login)
  38. //点击图形验证码
  39. $('#graphicImg').on('click', module.verificationCode)
  40. //点击图形验证码
  41. $('#mobileGraphicImg').on('click', module.verificationCode1)
  42. //点击发送验证码
  43. $('#getSmsCode').on('click', module.getSmsCode)
  44. //图形验证码加载
  45. module.verificationCode()
  46. //背景高度
  47. module.register()
  48. //网站配置信息(网站名称 底部联系方式 公安备案号 网站备案号)
  49. tools.getWebConfig();
  50. document.onkeydown = function (event) {
  51. var e = event || window.event;
  52. if (e && e.keyCode == 13) { //回车键的键值为13
  53. $("#login-submit").click(); //调用登录按钮的登录事件
  54. }
  55. };
  56. initPoints(POINT_NUM);
  57. drawFrame();
  58. };
  59. //随机数函数
  60. function randomInt(min, max) {
  61. return Math.floor((max - min + 1) * Math.random() + min);
  62. }
  63. function randomFloat(min, max) {
  64. return (max - min) * Math.random() + min;
  65. }
  66. //构造点类
  67. function Point() {
  68. this.x = randomFloat(0, cvs.width);
  69. this.y = randomFloat(0, cvs.height);
  70. var speed = randomFloat(0.3, 1.4);
  71. var angle = randomFloat(0, 2 * Math.PI);
  72. this.dx = Math.sin(angle) * speed;
  73. this.dy = Math.cos(angle) * speed;
  74. this.r = 1.2;
  75. this.color = POINT_COLOR;
  76. }
  77. Point.prototype.move = function () {
  78. this.x += this.dx;
  79. if (this.x < 0) {
  80. this.x = 0;
  81. this.dx = -this.dx;
  82. } else if (this.x > cvs.width) {
  83. this.x = cvs.width;
  84. this.dx = -this.dx;
  85. }
  86. this.y += this.dy;
  87. if (this.y < 0) {
  88. this.y = 0;
  89. this.dy = -this.dy;
  90. } else if (this.y > cvs.height) {
  91. this.y = cvs.height;
  92. this.dy = -this.dy;
  93. }
  94. }
  95. Point.prototype.draw = function () {
  96. ctx.fillStyle = this.color;
  97. ctx.beginPath();
  98. ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
  99. ctx.closePath();
  100. ctx.fill();
  101. }
  102. var points = [];
  103. function initPoints(num) {
  104. for (var i = 0; i < num; ++i) {
  105. points.push(new Point());
  106. }
  107. }
  108. var p0 = new Point(); //鼠标
  109. p0.dx = p0.dy = 0;
  110. var degree = 2.5;
  111. document.onmousemove = function (ev) {
  112. p0.x = ev.clientX;
  113. p0.y = ev.clientY;
  114. }
  115. document.onmousedown = function (ev) {
  116. degree = 5.0;
  117. p0.x = ev.clientX;
  118. p0.y = ev.clientY;
  119. }
  120. document.onmouseup = function (ev) {
  121. degree = 2.5;
  122. p0.x = ev.clientX;
  123. p0.y = ev.clientY;
  124. }
  125. window.onmouseout = function () {
  126. p0.x = null;
  127. p0.y = null;
  128. }
  129. function drawLine(p1, p2, deg) {
  130. var dx = p1.x - p2.x;
  131. var dy = p1.y - p2.y;
  132. var dis2 = dx * dx + dy * dy;
  133. if (dis2 < 2 * LINE_LENGTH) {
  134. if (dis2 > LINE_LENGTH) {
  135. if (p1 === p0) {
  136. p2.x += dx * 0.03;
  137. p2.y += dy * 0.03;
  138. } else return;
  139. }
  140. var t = (1.05 - dis2 / LINE_LENGTH) * 0.2 * deg;
  141. ctx.strokeStyle = "rgba(255,255,255," + t + ")";
  142. ctx.beginPath();
  143. ctx.lineWidth = 1.5;
  144. ctx.moveTo(p1.x, p1.y);
  145. ctx.lineTo(p2.x, p2.y);
  146. ctx.closePath();
  147. ctx.stroke();
  148. }
  149. return;
  150. }
  151. //绘制每一帧
  152. function drawFrame() {
  153. cvs.width = window.innerWidth;
  154. cvs.height = window.innerHeight;
  155. ctx.fillStyle = BACKGROUND_COLOR;
  156. ctx.fillRect(0, 0, cvs.width, cvs.height);
  157. var arr = (p0.x == null ? points : [p0].concat(points));
  158. for (var i = 0; i < arr.length; ++i) {
  159. for (var j = i + 1; j < arr.length; ++j) {
  160. drawLine(arr[i], arr[j], 1.0);
  161. }
  162. arr[i].draw();
  163. arr[i].move();
  164. }
  165. window.requestAnimationFrame(drawFrame);
  166. }
  167. module.getSmsCode = function () {
  168. var mobile = $('#mobile').val();
  169. tools.doPost(getSmsCode, {mobile:mobile,code:$('#mobileCode').val(),uuid:module.uuid}, module.getSmsCodeAjax, true)
  170. }
  171. module.getSmsCodeAjax = function (data) {
  172. module.uuid = data.uuid;
  173. module.computeTime = 60;
  174. module.timer = setInterval(() => {
  175. module.computeTime--;
  176. document.getElementById('getSmsCode').value = module.computeTime;
  177. if (module.computeTime <= 0) {
  178. clearInterval(module.timer);
  179. document.getElementById('getSmsCode').value = '发送验证码';
  180. }
  181. }, 1000);
  182. }
  183. //底部友情链接
  184. module.bottomFriendsLinks = function (data) {
  185. if (data.code == 200) {
  186. var content = data.data;
  187. console.log(content)
  188. module.data.friendsLinksList = content;
  189. var friendsLinksData = template('friendsLinksData', module.data);
  190. $("#friendsLinksContent").html(friendsLinksData);
  191. }
  192. }
  193. /*-----------------------------自定义方法-------------------------------------*/
  194. //登录方式切换
  195. loginTab = function(type){
  196. document.getElementById('loginTab').style.display = 'none'
  197. document.getElementById('remberPsw').style.display = 'none'
  198. document.getElementById('phoneTab').style.display = 'none'
  199. document.getElementById(type+'Tab').style.display = 'block'
  200. module.loginType = type;
  201. if (type == 'phone'){
  202. //图形验证码加载
  203. module.verificationCode1()
  204. }
  205. if (type == 'login'){
  206. //图形验证码加载
  207. module.verificationCode()
  208. document.getElementById('remberPsw').style.display = 'block'
  209. }
  210. $('#loginBtn').attr('class','')
  211. $('#phoneBtn').attr('class','')
  212. $('#'+type+'Btn').attr('class','active')
  213. }
  214. //背景高度
  215. module.register = function(){
  216. document.getElementById('registerBody').style.height = (document.body.offsetHeight - 112) +'px';
  217. }
  218. //图形验证码
  219. module.verificationCode = function () {
  220. tools.doGet(captchaImage_get, {}, module.verificationAjax, true)
  221. }
  222. module.verificationAjax = function (data) {
  223. if (data.code == 200) {
  224. $('#graphicImg').attr('src', 'data:image/gif;base64,' + data.img)
  225. module.uuid = data.uuid;
  226. }
  227. }
  228. //图形验证码
  229. module.verificationCode1 = function () {
  230. tools.doGet(captchaImage_get, {}, module.verificationAjax1, true)
  231. }
  232. module.verificationAjax1 = function (data) {
  233. if (data.code == 200) {
  234. $('#mobileGraphicImg').attr('src', 'data:image/gif;base64,' + data.img)
  235. module.uuid = data.uuid;
  236. }
  237. }
  238. //用户登录
  239. module.login = function () {
  240. if (module.check()) {
  241. var data = {};
  242. var usernameVal = tools.encrypt($('#username').val());
  243. var passwordVal = tools.encrypt($('#password').val());
  244. var codeVal = $('#code').val();
  245. var mobile = $('#mobile').val();
  246. var mobileCode = $('#mobileCode').val();
  247. var smsCode = $('#smsCode').val();
  248. data['uuid'] = module.uuid;
  249. if(module.loginType == 'login'){
  250. data['username'] = usernameVal;
  251. data['password'] = passwordVal;
  252. data['code'] = codeVal;
  253. tools.doPost(login_post, data, module.loginData, true)
  254. }
  255. if(module.loginType == 'phone'){
  256. data['mobile'] = mobile;
  257. data['smsCode'] = smsCode;
  258. data['code'] = mobileCode;
  259. tools.doPost(login_sms_post, data, module.loginData, true)
  260. }
  261. }
  262. };
  263. //手动验证表单
  264. module.check = function () {
  265. var usernameVal = $('#username').val();
  266. var passwordVal = $('#password').val();
  267. var codeVal = $('#code').val();
  268. var mobile = $('#mobile').val();
  269. var mobileCode = $('#mobileCode').val();
  270. var smsCode = $('#smsCode').val();
  271. var type = module.loginType;
  272. if (type == 'login'){
  273. /* 手机号 */
  274. if (usernameVal == '') {
  275. $('#username')[0].focus()
  276. tools.initTips('请输入用户名', 'right', $('#username')[0], 2000)
  277. return false;
  278. }
  279. /* 密码 */
  280. if (passwordVal == '') {
  281. $('#password')[0].focus()
  282. tools.initTips('请输入密码', 'right', $('#password')[0], 2000)
  283. return false;
  284. } else if (parseInt(passwordVal.length) < 6 || parseInt(passwordVal.length) > 18) {
  285. $('#password')[0].focus()
  286. tools.initTips('请输入正确格式密码', 'right', $('#password')[0], 2000)
  287. return false;
  288. }
  289. /*图形验证码*/
  290. if (module.uuid == '' || codeVal == '') {
  291. $('#code')[0].focus()
  292. tools.initTips('请输入图形验证码', 'right', $('#code')[0], 2000)
  293. return false;
  294. }
  295. }
  296. if (type == 'phone'){
  297. /* 手机号 */
  298. if (mobile == '') {
  299. $('#mobile')[0].focus()
  300. tools.initTips('请输入手机号码', 'right', $('#mobile')[0], 2000)
  301. return false;
  302. }
  303. /*图形验证码*/
  304. if (module.uuid == '' || mobileCode == '') {
  305. $('#mobileCode')[0].focus()
  306. tools.initTips('请输入图形验证码', 'right', $('#mobileCode')[0], 2000)
  307. return false;
  308. }
  309. /* 密码 */
  310. if (smsCode == '') {
  311. $('#smsCode')[0].focus()
  312. tools.initTips('请输入验证码', 'right', $('#smsCode')[0], 2000)
  313. return false;
  314. }
  315. }
  316. return true;
  317. }
  318. //登录校验
  319. module.loginData = function (data) {
  320. console.log(data)
  321. if (data.code == 500) {
  322. if (module.loginType == 'login'){
  323. module.verificationCode()
  324. }
  325. if (module.loginType == 'phone'){
  326. module.verificationCode1()
  327. }
  328. } else {
  329. tools.setCookie('Admin-Token', data.token, 24 * 60 * 60)
  330. //用户资料
  331. tools.doGet(userData, {}, module.userData);
  332. //tools.skip('/')
  333. }
  334. }
  335. //个人中心用户信息
  336. module.userData = function(data){
  337. if (data.code == 200) {
  338. var content = data.user;
  339. console.log(content)
  340. tools.setCookie('userId', content.userId, 24 * 60 * 60);
  341. tools.doGet(userMember + '/' + content.userId, {}, module.userMember);//memberType 1个人 2单位
  342. }
  343. }
  344. //个人中心用户资料
  345. module.userMember = function(data){
  346. if (data.code == 200) {
  347. var content = data.data;
  348. tools.setCookie('userName', content.realname, 24 * 60 * 60);
  349. tools.setCookie('memberId', content.id, 24 * 60 * 60);
  350. tools.setCookie('idCardNum',content.idCardNum,24 * 60 * 60)
  351. tools.setCookie('phone',content.phone,24 * 60 * 60)
  352. tools.setCookie('address',content.address,24 * 60 * 60)
  353. tools.setCookie('bankAddress',content.bankAddress,24 * 60 * 60)
  354. tools.setCookie('bankCardName',content.bankCardName,24 * 60 * 60)
  355. tools.setCookie('bankCardNum',content.bankCardNum,24 * 60 * 60)
  356. tools.setCookie('accountType',content.accountType,24 * 60 * 60)
  357. tools.setCookie('payeePaymentLines',content.payeePaymentLines,24 * 60 * 60)
  358. tools.setCookie('bankType',content.bankType,24 * 60 * 60)
  359. tools.skip('/sunVillage_info/index.html')
  360. }
  361. }
  362. return module;
  363. });