phoneLogin.vue 5.7 KB

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