login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="container login">
  3. <!-- logo区域 -->
  4. <view class="login-main">
  5. <image class="logo" :src="StaticUrl+'icon-logo@2x.png'" mode="widthFix"></image>
  6. </view>
  7. <!-- 邀请码 -->
  8. <view class="login-input">
  9. <input class="input"
  10. type="number"
  11. v-model="params.mobile"
  12. @blur="handBlurInput"
  13. placeholder="请输入手机号"
  14. maxlength="11"
  15. />
  16. </view>
  17. <view class="login-input">
  18. <input class="input_code"
  19. type="number"
  20. v-model="params.verificationCode"
  21. placeholder="请输入短信验证码"
  22. maxlength="6"
  23. />
  24. <view class="code-btn" :class="[isMobileDisabled ? 'disabled' : '']">
  25. <button type="button"
  26. @click.stop="GetMobileCodeFn"
  27. :disabled="isMobileDisabled"
  28. class="button"
  29. >
  30. {{ mobileCodeText }}
  31. </button>
  32. </view>
  33. </view>
  34. <!-- 提示信息 -->
  35. <view class="logo-message"><text>{{ loginMessage }}</text></view>
  36. <view class="login-btn" :class="[isLoginStatus ? 'disabled' : '']" @click="SubMitLogins">登录</view>
  37. </view>
  38. </template>
  39. <script>
  40. import authorize from '@/common/config/authorize.js'
  41. import wxLogin from '@/services/wxLogin.js'
  42. import { mapState, mapMutations } from 'vuex'
  43. export default {
  44. data() {
  45. return {
  46. invitationCode: '', //获取用户登录的邀请码
  47. loginMessage: '未注册的手机号验证后自动创建呵呵商城账户' ,//登录信息反馈
  48. StaticUrl:this.$Static,
  49. disabled:false,
  50. params:{
  51. mobile:'',
  52. headImgUrl:'', //微信头像
  53. nickName:'', //微信昵称
  54. openId:'', //微信openId
  55. verificationCode:''//短信验证码
  56. },
  57. count: '', //倒计时
  58. isMobileDisabled:true, //获取手机短信按钮
  59. mobileCodeText: '获取验证码',
  60. codeTime: null,
  61. isLoginStatus:false
  62. }
  63. },
  64. onLoad(option) {},
  65. computed: {
  66. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  67. },
  68. methods: {
  69. ...mapMutations(['login', 'wxLogin']),
  70. // 登录
  71. SubMitLogins() {
  72. const WechatInfo = uni.getStorageSync('wechatUserInfo')
  73. if(this.isLoginStatus){return}
  74. if(!this.params.mobile){
  75. this.$util.msg('请输入手机号',2000);
  76. return
  77. }
  78. if(!this.$reg.isMobile(this.params.mobile)){
  79. this.$util.msg('请输入正确的手机号',2000);
  80. return
  81. }
  82. if( this.params.verificationCode == ''){
  83. this.$util.msg('请输入短信验证码',2000);
  84. return
  85. }
  86. if(!uni.getStorageSync('_WX_State')){
  87. this.$api.navigateTo(`/pages/authorize/authorize`)
  88. return;
  89. }
  90. this.params.openId = uni.getStorageSync('openId');
  91. this.params.nickName = WechatInfo.nickName
  92. this.params.headImgUrl = WechatInfo.avatarUrl
  93. this.isLoginStatus = true
  94. this.UserService.UserMobileLogin(this.params)
  95. .then(response => {
  96. // 保存用户信息
  97. const _data = JSON.parse(response.data);
  98. this.login(_data)
  99. this.$store.commit('updateStatus',_data)
  100. // 登录成功提示
  101. this.$util.msg('登录成功', 1500, false, 'success')
  102. this.isLoginStatus = false
  103. setTimeout(() => {
  104. this.$api.switchTabTo(`/pages/tabBar/index/index`)
  105. }, 1500)
  106. })
  107. .catch(error => {
  108. this.$util.msg(error.msg,2000)
  109. this.isLoginStatus = false
  110. })
  111. },
  112. GetMobileCodeFn(){//获取手机验证码
  113. if( this.params.mobile == ''){
  114. this.$util.msg('请输入手机号',2000);
  115. return
  116. }
  117. if(!this.$reg.isMobile(this.params.mobile)){
  118. this.$util.msg('请输入正确的手机号',2000);
  119. return
  120. }
  121. this.isMobileDisabled = true;
  122. this.PublicService.GetheHeSend(
  123. {
  124. mobile:this.params.mobile,
  125. }
  126. )
  127. .then(res =>{
  128. const TIME_COUNT = 60;
  129. this.$util.msg('验证短信已发送',2000)
  130. if (!this.codeTime) {
  131. this.count = TIME_COUNT;
  132. this.isMobileDisabled = true;
  133. this.codeTime = setInterval(() => {
  134. if (this.count > 1 && this.count <= TIME_COUNT) {
  135. this.count--
  136. this.mobileCodeText = this.count +'s重新发送'
  137. } else {
  138. this.isMobileDisabled = false;
  139. clearInterval(this.codeTime)
  140. this.codeTime = null
  141. this.mobileCodeText = '获取验证码'
  142. }
  143. },1000)
  144. }
  145. })
  146. .catch( error =>{
  147. this.$util.msg(error.msg,2000)
  148. this.isMobileDisabled = false;
  149. })
  150. },
  151. handBlurInput(e){
  152. console.log(e)
  153. if(e.detail.value){
  154. this.isMobileDisabled = false
  155. }else{
  156. this.isMobileDisabled = true
  157. }
  158. }
  159. },
  160. onShow() {
  161. if(uni.getStorageSync('_WX_State')){
  162. wxLogin.wxLoginAuthorize()
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .login {
  169. display: flex;
  170. align-items: center;
  171. flex-direction: column;
  172. .login-main,
  173. .login-title,
  174. .logo-message {
  175. width: 590rpx;
  176. }
  177. .login-main {
  178. display: flex;
  179. justify-content: center;
  180. margin: 180rpx 0 60rpx;
  181. .logo {
  182. width: 200rpx;
  183. height: 200rpx;
  184. display: block;
  185. }
  186. }
  187. .login-title {
  188. display: flex;
  189. justify-content: flex-start;
  190. image {
  191. width: 40rpx;
  192. height: 40rpx;
  193. margin-right: 6rpx;
  194. }
  195. }
  196. .login-btn {
  197. width: 600rpx;
  198. height: 90rpx;
  199. text-align: center;
  200. line-height: 90rpx;
  201. background:$btn-confirm ;
  202. border-radius: 45rpx;
  203. color: #fff !important;
  204. margin-top: 40rpx;
  205. &.disabled{
  206. background: #E1E1E1;
  207. color: #999999;
  208. }
  209. }
  210. .login-input {
  211. margin: 10rpx 0;
  212. width: 600rpx;
  213. height: 90rpx;
  214. box-sizing: border-box;
  215. padding: 25rpx 0;
  216. border-bottom: 1px solid #E1E1E1;
  217. .input{
  218. width: 100%;
  219. height: 40rpx;
  220. left: 40rpx;
  221. font-size: $font-size-28;
  222. color: #333333;
  223. }
  224. .input_code{
  225. width: 420rpx;
  226. height: 40rpx;
  227. left: 40rpx;
  228. font-size: $font-size-28;
  229. color: #333333;
  230. float: left;
  231. }
  232. .code-btn{
  233. width: 180rpx;
  234. height: 40rpx;
  235. line-height: 40rpx;
  236. font-size: $font-size-28;
  237. color: #333333;
  238. float: right;
  239. text-align: center;
  240. .button{
  241. width: 180rpx;
  242. height: 40rpx;
  243. line-height: 40rpx;
  244. padding: 0;
  245. color: $color-system;
  246. }
  247. &.disabled{
  248. .button{
  249. color: #b2b2b2;
  250. }
  251. }
  252. }
  253. }
  254. .logo-message {
  255. font-size: 24rpx;
  256. line-height: 44rpx;
  257. color: #fc464c;
  258. text-align: left;
  259. }
  260. }
  261. </style>