login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div style="background: #F7F7F7;">
  3. <div v-document_title>登录</div>
  4. <div class="login_input">
  5. <input type="tel" name="userMobile" class="input_mobile" v-model="userMobile" placeholder="请输入您的手机号码">
  6. <flexbox :gutter="20">
  7. <flexbox-item>
  8. <input type="number" name="code" v-model="code" class="input_mobile" placeholder="请输入验证码">
  9. </flexbox-item>
  10. <flexbox-item>
  11. <button type="button" @click="getCode" class="get_code_btn">{{isCount?countTime:btn_msg}}</button>
  12. </flexbox-item>
  13. </flexbox>
  14. <button type="button" class="button_submit" @click="login_submit">立即登录</button>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { Flexbox , FlexboxItem , Divider} from 'vux';
  20. import Api from '../../lib/api';
  21. export default {
  22. data () {
  23. return {
  24. userMobile:'',
  25. btn_msg:'获取验证码',
  26. code:'',
  27. countTime:60,
  28. isCount:false
  29. }
  30. },
  31. components: {
  32. Flexbox,
  33. FlexboxItem,
  34. Divider
  35. },
  36. methods:{
  37. login_submit(){
  38. let mobile = this.userMobile;
  39. let code = this.code;
  40. if(!mobile || !/^1(3|4|5|7|8)\d{9}$/.test(mobile)) {
  41. this.$vux.toast.show({
  42. type:'text',
  43. text: '请输入正确的电话号码',
  44. position:'middle'
  45. })
  46. }
  47. else if(!code ) {
  48. this.$vux.toast.show({
  49. type:'text',
  50. text: '请输入验证码',
  51. position:'middle'
  52. })
  53. }
  54. else {
  55. this.$store.commit('updateLoadingStatus', {isLoading: true});
  56. this.$http.jsonp(Api.login(mobile,code),{_timeout:5000}).then(function(res)
  57. {
  58. if(res.body.code == 200)
  59. {
  60. this.$http.jsonp(Api.memberInfo(),{_timeout:5000}).then(function(res){
  61. if(res.body.code !== 10014) {
  62. this.$store.commit('updateLogIn');
  63. this.$store.commit('updateUser',{'name':res.body.datas.member_nickname,'image':res.body.datas.member_avatar});
  64. this.$http.jsonp(Api.userBonus()).then(function(res){
  65. this.$store.commit('updateUser_bonus',{'array':res.body.datas.bonus_rate});
  66. });
  67. this.$store.commit('updateLoadingStatus', {isLoading: false});
  68. this.$router.push('/');
  69. }
  70. },(err) => {
  71. this.$vux.toast.show({
  72. type: 'text',
  73. text: "网络错误",
  74. position: 'middle'
  75. })
  76. });
  77. }
  78. else {
  79. this.$store.commit('updateLoadingStatus', {isLoading: false});
  80. this.$vux.toast.show({
  81. type:'text',
  82. text: res.body.message,
  83. position:'middle'
  84. })
  85. }
  86. },(err) => {
  87. this.$vux.toast.show({
  88. type: 'text',
  89. text: "网络错误",
  90. position: 'middle'
  91. })
  92. });
  93. }
  94. },
  95. getCode(){
  96. let mobile = this.userMobile;
  97. if(!mobile || !/^1(3|4|5|7|8)\d{9}$/.test(mobile)) {
  98. this.$vux.toast.show({
  99. type:'text',
  100. text: '请输入正确的电话号码',
  101. position:'middle'
  102. })
  103. }
  104. else {
  105. if(this.isCount) return;
  106. this.isCount = true;
  107. let _self = this;
  108. let count = setInterval(function(){
  109. _self.countTime = _self.countTime -1;
  110. if(_self.countTime<=0) {
  111. clearInterval(count);
  112. _self.isCount = false;
  113. }
  114. },1000);
  115. this.$http.jsonp(Api.getCode(mobile),{_timeout:5000}).then(function(res){
  116. if(res.body.code != 200) {
  117. this.$vux.toast.show({
  118. type:'text',
  119. text: res.body.message,
  120. position:'middle'
  121. })
  122. }
  123. },(err) => {
  124. this.$vux.toast.show({
  125. type: 'text',
  126. text: "网络错误",
  127. position: 'middle'
  128. })
  129. });
  130. }
  131. }
  132. }
  133. }
  134. </script>
  135. <style scoped>
  136. .login_input {
  137. padding-top:12px;
  138. width: 600px;
  139. margin: 0 auto;
  140. }
  141. .input_mobile {
  142. display: block;
  143. width: 98%;
  144. height:72px;
  145. padding-left: 2%;
  146. font-size: 24px;
  147. background: #ffffff;
  148. border: none;
  149. border-radius: 5px;
  150. margin-bottom: 20px;
  151. }
  152. .button_submit,.get_code_btn {
  153. display: block;
  154. width: 100%;
  155. height: 72px;
  156. text-align: center;
  157. background: #EB4E4F;
  158. color: #fff;
  159. border: none;
  160. border-radius: 5px;
  161. font-size: 24px;
  162. margin-bottom: 20px;
  163. }
  164. </style>