login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="container login">
  3. <!-- logo区域 -->
  4. <view class="login-main">
  5. <image class="logo" src="/static/ws/logo.png" mode="widthFix"></image>
  6. </view>
  7. <!-- 邀请码标题 -->
  8. <view class="login-title">
  9. <image src="/static/ws/invitation_code.png" mode="widthFix"></image> <text>邀请码</text>
  10. </view>
  11. <!-- 邀请码 -->
  12. <view class="login-input">
  13. <vcode-input
  14. borderValueColor="#e8e8e8"
  15. borderActiveColor="#e8e8e8"
  16. ref="vcodeInputRef"
  17. @vcodeInput="vcodeInput"
  18. @vcodeChange="vcodeChangeHandle"
  19. sum="6"
  20. ></vcode-input>
  21. </view>
  22. <!-- 提示信息 -->
  23. <view class="logo-message" v-if="loginMessage !== ''"
  24. ><text>{{ loginMessage }}</text>
  25. </view>
  26. <button class="login-btn" @click="goLogin" :disabled="isCodeEmpty">登录</button>
  27. </view>
  28. </template>
  29. <script>
  30. import authorize from '@/common/config/authorize.js'
  31. import wxLogin from '@/common/config/wxLogin.js'
  32. import VcodeInput from '@/components/vcode-input/vcode-input'
  33. import { mapState, mapMutations } from 'vuex'
  34. import { invitationCodeLogin } from '@/services/use.js'
  35. export default {
  36. components: { VcodeInput },
  37. data() {
  38. return {
  39. invitationCode: '', //获取用户登录的邀请码
  40. loginMessage: '' //登录信息反馈
  41. }
  42. },
  43. onLoad(option) {
  44. },
  45. computed: {
  46. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  47. // 邀请码长度是否符合要求
  48. isCodeEmpty() {
  49. return this.invitationCode.trim().length < 6
  50. }
  51. },
  52. methods: {
  53. ...mapMutations(['login']),
  54. // 登录
  55. goLogin() {
  56. // 获取用户微信信息
  57. wx.getUserInfo({
  58. success: res => {
  59. this.isUserInfo = false
  60. this.userInfo = res.userInfo
  61. let params = {
  62. invitationCode: this.invitationCode,
  63. nickName: res.userInfo.nickName,
  64. openid: uni.getStorageSync('openid')
  65. }
  66. // 验证邀请码
  67. this.UserService.userInvitation(params).then(response => {
  68. console.log(response)
  69. // 保存用户信息
  70. this.login(response.data)
  71. this.$store.commit('updateStatus',response.data)
  72. setTimeout(()=>{
  73. this.$api.navigateTo(`/pages/index/index`)
  74. },1500)
  75. }).catch(error => {
  76. this.loginMessage = error.msg
  77. this.isUserInfo = false
  78. // this.$util.msg(error.msg, 2000)
  79. })
  80. }
  81. })
  82. },
  83. // 输入框输入介绍
  84. vcodeInput(val) {
  85. // this.invitationCode = val
  86. console.log(val)
  87. },
  88. // 输入框输入事件
  89. vcodeChangeHandle(val) {
  90. this.invitationCode = val
  91. // console.log(val)
  92. },
  93. // 控制组件获取焦点
  94. setFocus() {
  95. this.$refs.VcodeInput.setFocus()
  96. },
  97. // 控制组件失去焦点
  98. setBlur() {
  99. this.$refs.VcodeInput.setBlur()
  100. },
  101. // 清除已输入
  102. clearValue() {
  103. this.$refs.VcodeInput.clearValue()
  104. }
  105. },
  106. onShow() {
  107. }
  108. }
  109. </script>
  110. <style lang="scss">
  111. .login {
  112. display: flex;
  113. align-items: center;
  114. flex-direction: column;
  115. .login-main,
  116. .login-title,
  117. .logo-message {
  118. width: 590rpx;
  119. }
  120. .login-main {
  121. display: flex;
  122. justify-content: center;
  123. margin: 180rpx 0 60rpx;
  124. image {
  125. width: 151rpx;
  126. height: 151rpx;
  127. border-radius: 50%;
  128. }
  129. }
  130. .login-title {
  131. display: flex;
  132. justify-content: flex-start;
  133. image {
  134. width: 40rpx;
  135. height: 40rpx;
  136. margin-right: 6rpx;
  137. }
  138. }
  139. .login-btn {
  140. width: 600rpx;
  141. height: 90rpx;
  142. text-align: center;
  143. line-height: 90rpx;
  144. background-color: #000;
  145. border-radius: 45rpx;
  146. color: #fff;
  147. box-shadow: 4rpx 4rpx 40rpx rgba(0, 0, 0, 0.2);
  148. margin-top: 40rpx;
  149. }
  150. .login-input {
  151. margin: 30rpx 0;
  152. }
  153. .logo-message {
  154. margin-bottom: 64rpx;
  155. font-size: 24rpx;
  156. line-height: 33rpx;
  157. color: #ff2a2a;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. &::before {
  162. content: '!';
  163. display: block;
  164. width: 22rpx;
  165. height: 22rpx;
  166. border: 1px solid #ff2a2a;
  167. border-radius: 50%;
  168. color: #ff2a2a;
  169. text-align: center;
  170. line-height: 22rpx;
  171. margin-right: 6rpx;
  172. }
  173. }
  174. }
  175. </style>