signup.js 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. SPA_RESOLVE_INIT = function ($el, $router) {
  2. const html = document.querySelector('html');
  3. const body = document.querySelector('body');
  4. html.className = 'index';
  5. body.className = 'mdui-theme-primary-blue mdui-theme-accent-light-blue index';
  6. mdui.JQ($el).empty();
  7. mdui.JQ($el).append(`
  8. <header class="mdui-appbar mdui-shadow-0">
  9. <div class="mdui-toolbar mdui-color-theme">
  10. <a class="mdui-typo-headline" href="#">CloudSQL Admin Panel</a>
  11. <div class="mdui-toolbar-spacer"></div>
  12. <a class="mdui-btn mdui-ripple mdui-ripple-white" href="#/signin">登陆</a>
  13. <a class="mdui-btn mdui-ripple mdui-ripple-white" href='#/signup'>注册</a>
  14. </div>
  15. </header>
  16. <main style="height: 85%;">
  17. <div class="mdui-container main-section">
  18. <h2 class="mdui-typo-display-1 main-section-tittle">用户注册</h2>
  19. <div class="mdui-container mdui-col-md-8 mdui-center main-sub-section">
  20. <div class="mdui-col-md-6 mdui-center mdui-textfield main-input-row">
  21. <i class="mdui-icon material-icons">person</i>
  22. <input class="mdui-textfield-input" name="userid" type="text" placeholder="用户名/邮箱" />
  23. </div>
  24. <div class="mdui-col-md-6 mdui-center mdui-textfield main-input-row">
  25. <i class="mdui-icon material-icons">lock</i>
  26. <input class="mdui-textfield-input" name="password" type="password" placeholder="密码" />
  27. </div>
  28. <div class="mdui-col-md-6 mdui-center mdui-textfield main-input-row">
  29. <i class="mdui-icon material-icons">code</i>
  30. <input class="mdui-textfield-input" name="invitecode" type="text" placeholder="邀请码" />
  31. </div>
  32. <div class="mdui-col-md-6 mdui-center mdui-textfield main-input-row captcha-row">
  33. <img src="http://admin.cloudsql.1473.cn/v1/captcha?${new Date().getTime()}">
  34. <input class="mdui-textfield-input" name="captcha" type="text" placeholder="验证码" />
  35. </div>
  36. <div class="mdui-col-md-6 mdui-center mdui-typo main-a-row">
  37. <a href="#/signin">已有账户,点击登陆</a>
  38. </div>
  39. <div class="mdui-col-md-6 mdui-center main-button-row">
  40. <button class="mdui-btn mdui-btn-block mdui-color-theme-accent">注册</button>
  41. </div>
  42. </div>
  43. </div>
  44. </main>
  45. <footer>
  46. <div class="footer-copyright">Copyright © 2016 - 2017 <a href="/">CloudSQL</a> All rights reserved.</div>
  47. </footer>
  48. `)
  49. //验证码刷新逻辑
  50. let captchaImg = document.querySelector('.captcha-row img');
  51. Utils.handleEvent('click', {
  52. onElement: captchaImg,
  53. withCallback: function () {
  54. this.src = `http://admin.cloudsql.1473.cn/v1/captcha?${new Date().getTime()}`; //加入当前时间以避免缓存
  55. }
  56. });
  57. /* captchaImg.addEventListener('click', function () {
  58. this.src = `http://admin.cloudsql.1473.cn/v1/captcha?${new Date().getTime()}`; //加入当前时间以避免缓存
  59. }, false); */
  60. let submitButton = document.querySelector('.main-button-row button');
  61. Utils.handleEvent('click', {
  62. onElement: submitButton,
  63. withCallback: function () {
  64. let signupUrl = 'http://admin.cloudsql.1473.cn/v1/signup',
  65. userId = document.querySelector('input[name=userid]').value,
  66. password = document.querySelector('input[name=password]').value,
  67. captchaCode = document.querySelector('input[name=captcha]').value,
  68. postData = `userId=${userId}&password=${password}&captcha=${captchaCode}`;
  69. Utils.ajaxPost(signupUrl, postData, function (response) {
  70. if (response.status == 'successed') {
  71. mdui.snackbar({
  72. message: response.info
  73. });
  74. window.location.hash = response.url;
  75. } else {
  76. mdui.snackbar({
  77. message: response.info
  78. });
  79. }
  80. })
  81. }
  82. });
  83. }