login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div>
  3. <img src="../assets/login_background.png"
  4. style="max-width: 100%"
  5. />
  6. <div class="card">
  7. <van-cell-group>
  8. <van-field
  9. v-model="phone"
  10. required
  11. clearable
  12. label="手机号"
  13. placeholder="请输入手机号"
  14. :error="phoneError"
  15. @click="phoneError=false"
  16. />
  17. <van-field
  18. v-model="password"
  19. required
  20. clearable
  21. type="password"
  22. label="密码"
  23. placeholder="请输入密码"
  24. :error="passError"
  25. @click="passError=false"
  26. />
  27. <van-field
  28. v-model="sms"
  29. center
  30. clearable
  31. label="短信验证码"
  32. placeholder="请输入短信验证码(暂时不用)"
  33. required
  34. disabled
  35. >
  36. <van-button slot="button" size="small" type="primary" disabled>发送验证码</van-button>
  37. </van-field>
  38. </van-cell-group>
  39. </div>
  40. <div style="position: fixed; bottom: 5px; width:100%">
  41. <van-button type="primary" size="large" class='login' @click="Login">登录</van-button>
  42. <van-button type="default" size="large" class='register' @click="Register">注册</van-button>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import 'whatwg-fetch';
  48. import { BasicFunction } from '../connector/basic-service';
  49. import {
  50. Field,
  51. CellGroup,
  52. Button,
  53. } from 'vant';
  54. export default {
  55. components: {
  56. [Field.name]: Field,
  57. [CellGroup.name]: CellGroup,
  58. [Button.name]: Button
  59. },
  60. data() {
  61. return {
  62. phone: '',
  63. phoneError: false,
  64. sms: '',
  65. password: '',
  66. passError: false
  67. }
  68. },
  69. methods: {
  70. Login() {
  71. // 检查输入
  72. if(this.phone.length !== 11) {
  73. this.phoneError = true;
  74. return;
  75. } else if(this.password.length < 8) {
  76. this.passError = true;
  77. return;
  78. }
  79. window.routerme = this.$router; //TODO: 考虑 encodeURIComponent(this.password)
  80. BasicFunction.get_data("ajaxlogin?u=" + this.phone + "&p=" + this.password, function (response) {
  81. console.log("------ Data Rcvd in Login --------");
  82. console.log(response);
  83. if(response.ret === "10000"){
  84. // userId
  85. localStorage.setItem("frontend-userid", response.model.userId);
  86. window.routerme.push('index');
  87. } else {
  88. // 密码错误的处理
  89. console.warn("登录失败");
  90. }
  91. }, {});
  92. },
  93. Register() {
  94. this.$router.push('verify');
  95. },
  96. SendOTP() {
  97. BasicFunction.get_data("ajaxsendotp?u=" + this.phone, function (response) {
  98. console.log('------ sms Rcvd in Login --------');
  99. console.log(response);
  100. }, {})
  101. }
  102. }
  103. }
  104. /** Post JSON **/
  105. /*
  106. // 怎么把一段放到另一个文件?
  107. fetch('/users', {
  108. method: 'POST',
  109. headers: {
  110. 'Content-Type': 'application/json'
  111. },
  112. body: JSON.stringify({
  113. name: 'Hubot',
  114. login: 'hubot',
  115. })
  116. })
  117. */
  118. </script>
  119. <style scoped>
  120. .card {
  121. margin: 20px 20px 130px;
  122. border: solid 1px #e4e4e4;
  123. }
  124. .login {
  125. margin-bottom: 10px;
  126. width: 85%;
  127. background-color: #fd6740;
  128. border-color: #fd6740;
  129. }
  130. .register {
  131. margin-bottom: 5px;
  132. width: 85%;
  133. }
  134. </style>