phoneLogin.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="wrap">
  3. <view class="content">
  4. <view class="title">手机号登录</view>
  5. <input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" />
  6. <button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button>
  7. <u-message-input v-if="show" :focus="true" :value="messageCode" @change="change" @finish="finish" mode="bottomLine" :maxlength="codelength"></u-message-input>
  8. </view>
  9. <!-- <text v-if="messageError">验证码错误,请重新输入</text> -->
  10. <view class="captcha">
  11. <!-- <text v-if="show&&this.messageDisable==false" @tap="noCaptcha">收不到验证码点这里</text> -->
  12. <text v-if="messageShow">{{ second }}秒后可重新获取验证码</text>
  13. </view>
  14. <view class="buttom">
  15. <view class="hint">
  16. 登录代表同意
  17. <text class="link">隐私政策,</text>
  18. 并授权使用您的账号信息(如昵称、头像、收获地址)以便您统一管理
  19. </view>
  20. </view>
  21. <u-toast ref="uToast" />
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. tel: '',
  29. messageCode:'',
  30. messageShow: false,
  31. messageDisable: false,
  32. codelength: 4,
  33. show: false,
  34. second:10,
  35. toastMsg:'',
  36. toastUrl:'',
  37. toastType:'',
  38. accessToken:'',
  39. userId:'',
  40. // messageError:false
  41. }
  42. },
  43. onLoad() {
  44. },
  45. computed: {
  46. inputStyle() {
  47. let style = {};
  48. if(this.tel.length==11&&this.messageDisable==false&&this.$u.test.mobile(this.tel)) {
  49. style.color = "#fff";
  50. style.backgroundColor = '#5295F5';
  51. // style.backgroundColor = this.$u.color['warning'];
  52. }
  53. return style;
  54. }
  55. },
  56. methods: {
  57. showToast() {
  58. this.$refs.uToast.show({
  59. title: this.toastMsg,
  60. type: this.toastType,
  61. url: this.toastUrl
  62. })
  63. },
  64. submit() {
  65. if(this.$u.test.mobile(this.tel)&&this.messageDisable==false) {
  66. let that = this;
  67. this.$u.api.getPhoneLoginCode({mobile:this.tel})
  68. .then(res =>{
  69. this.messageDisable = true;
  70. this.messageShow = true;
  71. this.show = true;
  72. let interval = setInterval(() => {
  73. that.second--;
  74. if (that.second <= 0) {
  75. that.messageDisable=false
  76. that.messageShow = false;
  77. if (that.messageCode.lenth != 4) {
  78. // this.messageError = true;
  79. }
  80. clearInterval(interval);
  81. that.second=10;
  82. }
  83. }, 1000);
  84. console.log('getcode res',res);
  85. this.accessToken = res.data.accessToken;
  86. this.$u.vuex('vuex_token', res.data.accessToken);
  87. this.userId = res.data.userId;
  88. }).catch(err=>{
  89. console.log('err',err)
  90. this.toastMsg = err.code + ":" + err.msg;
  91. this.showToast();
  92. console.log('getcode err',err)
  93. });
  94. }
  95. },
  96. // 收不到验证码选择时的选择
  97. // noCaptcha() {
  98. // uni.showActionSheet({
  99. // itemList: ['重新获取验证码', '接听语音验证码'],
  100. // success: function(res) {
  101. // },
  102. // fail: function(res) {
  103. // }
  104. // });
  105. // },
  106. // change事件侦听
  107. change(value) {
  108. // console.log('change', value);
  109. },
  110. // 输入完验证码最后一位执行
  111. finish(value) {
  112. let params = {
  113. accessToken:this.accessToken,
  114. userId:this.userId,
  115. code:value
  116. };
  117. console.log('params',params);
  118. this.$u.api.phoneLoginAuth(params)
  119. .then(res =>{
  120. if(res.code=='200'){
  121. // console.log('finish res',res);
  122. this.$u.vuex('vuex_user', res.data);
  123. this.$u.vuex('vuex_hasLogin', true);
  124. this.$refs.uToast.show({
  125. title: '操作成功',
  126. url: '/pages/index/index',
  127. isTab:true
  128. });
  129. // this.$u.api.getuseinfo().then(res => {
  130. // console.log('getuseinfo',res.retBody);
  131. // this.$u.vuex('vuex_user', res.retBody);
  132. // this.toastMsg = '操作成功';
  133. // this.showToast();
  134. // setTimeout(() => {
  135. // this.$u.route({
  136. // url: 'pages/template/wxCenter/index'
  137. // })
  138. // }, 2000);
  139. // });
  140. }else{
  141. this.toastMsg = res.msg;
  142. this.showToast();
  143. }
  144. }).catch(err=>{
  145. console.log('finish err',err);
  146. this.toastMsg = err.msg;
  147. this.showToast();
  148. });
  149. }
  150. }
  151. };
  152. </script>
  153. <style lang="scss" scoped>
  154. .hide{display: none!important;}
  155. .wrap {
  156. font-size: 28rpx;
  157. .content {
  158. width: 600rpx;
  159. margin: 80rpx auto 0;
  160. .title {
  161. text-align: left;
  162. font-size: 60rpx;
  163. font-weight: 500;
  164. margin-bottom: 100rpx;
  165. }
  166. input {
  167. text-align: left;
  168. margin-bottom: 10rpx;
  169. padding-bottom: 20rpx;
  170. border-bottom: 1px solid #ddd;
  171. }
  172. .getCaptcha {
  173. margin: 45rpx auto 130rpx;
  174. background-color: #a8c6f1;
  175. color: $u-tips-color;
  176. border: none;
  177. font-size: 30rpx;
  178. padding: 12rpx 0;
  179. &::after {
  180. border: none;
  181. }
  182. }
  183. }
  184. .buttom {
  185. .hint {
  186. padding: 20rpx 40rpx;
  187. font-size: 20rpx;
  188. color: $u-tips-color;
  189. .link {
  190. color: $u-type-warning;
  191. }
  192. }
  193. }
  194. .captcha {
  195. color: $u-type-warning;
  196. font-size: 30rpx;
  197. margin-top: 40rpx;
  198. text-align: center;
  199. }
  200. }
  201. </style>