login.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <h1>登录</h1>
  4. <van-cell-group>
  5. <van-field
  6. v-model="phone"
  7. required
  8. clearable
  9. label="手机号"
  10. placeholder="请输入手机号"
  11. :error="phoneError"
  12. @click="phoneError=false"
  13. />
  14. <van-field
  15. v-model="password"
  16. required
  17. clearable
  18. type="password"
  19. label="密码"
  20. placeholder="请输入密码"
  21. :error="passError"
  22. @click="passError=false"
  23. />
  24. <van-field
  25. v-model="sms"
  26. center
  27. clearable
  28. label="短信验证码"
  29. placeholder="请输入短信验证码(暂时不用)"
  30. required
  31. disabled
  32. >
  33. <van-button slot="button" size="small" type="primary" disabled>发送验证码</van-button>
  34. </van-field>
  35. </van-cell-group>
  36. <div style="position: fixed; bottom: 5px; width:100%">
  37. <van-button type="default" size="large" class='submit' @click="Login">登录</van-button>
  38. <van-button type="default" size="large" class='submit' @click="Register">注册</van-button>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import 'whatwg-fetch';
  44. import { BasicFunction } from '../connector/basic-service';
  45. import {
  46. Field,
  47. CellGroup,
  48. Button,
  49. } from 'vant';
  50. export default {
  51. components: {
  52. [Field.name]: Field,
  53. [CellGroup.name]: CellGroup,
  54. [Button.name]: Button
  55. },
  56. data() {
  57. return {
  58. phone: '',
  59. phoneError: false,
  60. sms: '',
  61. password: '',
  62. passError: false
  63. }
  64. },
  65. methods: {
  66. Login() {
  67. // 检查输入
  68. if(this.phone.length !== 11) {
  69. this.phoneError = true;
  70. return;
  71. } else if(this.password.length < 8) {
  72. this.passError = true;
  73. return;
  74. }
  75. // 检查手机号有无注册
  76. let API = "http://south.niimei.com:8866/server";
  77. let GETUSERINFO = "/smartUsers/list";
  78. // this.$http.get(API+GETUSERINFO).then((data) => {
  79. // // 响应成功回调
  80. // console.log(data);
  81. // }, (err) => {
  82. // // 响应错误回调
  83. // console.log(err);
  84. // console.log(this);
  85. // });
  86. // let login_info = {
  87. // phone: this.phone,
  88. // pass: this.password
  89. // };
  90. // if(get_data(login_info)) {
  91. // this.$router.push('index');
  92. // } else {
  93. // this.phoneError = true;
  94. // this.passError = true;
  95. // }
  96. // 检查手机号有无验证
  97. BasicFunction.get_data("smartUsers/list", function(data) { console.log(data.model.list); } );
  98. BasicFunction.get_data("ajaxlogin", function(response){
  99. console.log("------ Data Rcvd in Login --------");
  100. console.log(response);
  101. if(response.ret === "10000"){
  102. // 不需要 设置 SessionID, 已经自动保存在jSessionID中
  103. this.$router.push('index');
  104. } else {
  105. // 密码错误的处理
  106. console.warn("登录失败");
  107. }
  108. }, { u: this.phone, p : this.passWord });
  109. // this.$router.push('index');
  110. },
  111. Register() {
  112. BasicFunction.get_data("ajaxlogin", function(response){
  113. console.log("------ Data Rcvd in Login --------");
  114. console.log(response);
  115. if(response.ret === "10000"){
  116. // 不需要 设置 SessionID, 已经自动保存在jSessionID中
  117. this.$router.push('verify');
  118. } else {
  119. // 注册失败的处理
  120. console.warn("注册失败");
  121. }
  122. }, { u: this.phone, p : this.passWord });
  123. }
  124. }
  125. }
  126. /** Post JSON **/
  127. /*
  128. // 怎么把一段放到另一个文件?
  129. fetch('/users', {
  130. method: 'POST',
  131. headers: {
  132. 'Content-Type': 'application/json'
  133. },
  134. body: JSON.stringify({
  135. name: 'Hubot',
  136. login: 'hubot',
  137. })
  138. })
  139. */
  140. </script>
  141. <style scoped>
  142. .submit {
  143. margin-top: 10px;
  144. }
  145. </style>