login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // 检查手机号有无注册
  80. let API = "http://south.niimei.com:8866/server";
  81. let GETUSERINFO = "/smartUsers/list";
  82. // this.$http.get(API+GETUSERINFO).then((data) => {
  83. // // 响应成功回调
  84. // console.log(data);
  85. // }, (err) => {
  86. // // 响应错误回调
  87. // console.log(err);
  88. // console.log(this);
  89. // });
  90. // let login_info = {
  91. // phone: this.phone,
  92. // pass: this.password
  93. // };
  94. // if(get_data(login_info)) {
  95. // this.$router.push('index');
  96. // } else {
  97. // this.phoneError = true;
  98. // this.passError = true;
  99. // }
  100. // 检查手机号有无验证
  101. // BasicFunction.get_data("smartUsers/list", function(data) { console.log(data.model.list); } );
  102. BasicFunction.get_data("ajaxlogin", function(response){
  103. console.log("------ Data Rcvd in Login --------");
  104. console.log(response);
  105. if(response.ret === "10000"){
  106. // 不需要 设置 SessionID, 已经自动保存在jSessionID中
  107. this.$router.push('index');
  108. } else {
  109. // 密码错误的处理
  110. console.warn("登录失败");
  111. }
  112. }, { u: this.phone, p : this.passWord });
  113. // this.$router.push('index');
  114. },
  115. Register() {
  116. BasicFunction.get_data("ajaxlogin", function(response){
  117. console.log("------ Data Rcvd in Login --------");
  118. console.log(response);
  119. if(response.ret === "10000"){
  120. // 不需要 设置 SessionID, 已经自动保存在jSessionID中
  121. this.$router.push('verify');
  122. } else {
  123. // 注册失败的处理
  124. console.warn("注册失败");
  125. }
  126. }, { u: this.phone, p : this.passWord });
  127. }
  128. }
  129. }
  130. /** Post JSON **/
  131. /*
  132. // 怎么把一段放到另一个文件?
  133. fetch('/users', {
  134. method: 'POST',
  135. headers: {
  136. 'Content-Type': 'application/json'
  137. },
  138. body: JSON.stringify({
  139. name: 'Hubot',
  140. login: 'hubot',
  141. })
  142. })
  143. */
  144. </script>
  145. <style scoped>
  146. .card {
  147. margin: 20px;
  148. border: solid 1px #e4e4e4;
  149. }
  150. .login {
  151. margin-bottom: 10px;
  152. width: 85%;
  153. background-color: #fd6740;
  154. border-color: #fd6740;
  155. }
  156. .register {
  157. margin-bottom: 5px;
  158. width: 85%;
  159. }
  160. </style>