login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. computed: {
  45. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  46. // 邀请码长度是否符合要求
  47. isCodeEmpty() {
  48. return this.invitationCode.trim().length < 6
  49. }
  50. },
  51. methods: {
  52. ...mapMutations(['login']),
  53. // 登录
  54. goLogin() {
  55. // 获取用户微信信息
  56. wx.getUserInfo({
  57. success: res => {
  58. this.isUserInfo = false
  59. this.userInfo = res.userInfo
  60. // 验证邀请码
  61. this.UserService.userInvitation({
  62. invitationCode: this.invitationCode,
  63. nickName: res.userInfo.nickName,
  64. openid: uni.getStorageSync('openid')
  65. })
  66. .then(response => {
  67. console.log(response)
  68. // 保存用户信息
  69. this.login(response.data)
  70. this.$store.commit('updateStatus', response.data)
  71. // 登录成功提示
  72. this.$util.msg('登录成功', 1500, false, 'success')
  73. setTimeout(() => {
  74. this.$api.navigateTo(`/pages/index/index`)
  75. }, 1500)
  76. })
  77. .catch(error => {
  78. this.loginMessage = error.msg
  79. this.isUserInfo = false
  80. // this.$util.msg(error.msg, 2000)
  81. })
  82. }
  83. })
  84. },
  85. // 输入框输入介绍
  86. vcodeInput(val) {
  87. // this.invitationCode = val
  88. console.log(val)
  89. },
  90. // 输入框输入事件
  91. vcodeChangeHandle(val) {
  92. this.invitationCode = val
  93. // console.log(val)
  94. },
  95. // 控制组件获取焦点
  96. setFocus() {
  97. this.$refs.VcodeInput.setFocus()
  98. },
  99. // 控制组件失去焦点
  100. setBlur() {
  101. this.$refs.VcodeInput.setBlur()
  102. },
  103. // 清除已输入
  104. clearValue() {
  105. this.$refs.VcodeInput.clearValue()
  106. }
  107. },
  108. onShow() {}
  109. }
  110. </script>
  111. <style lang="scss">
  112. .login {
  113. display: flex;
  114. align-items: center;
  115. flex-direction: column;
  116. .login-main,
  117. .login-title,
  118. .logo-message {
  119. width: 590rpx;
  120. }
  121. .login-main {
  122. display: flex;
  123. justify-content: center;
  124. margin: 180rpx 0 60rpx;
  125. image {
  126. width: 151rpx;
  127. height: 151rpx;
  128. border-radius: 50%;
  129. }
  130. }
  131. .login-title {
  132. display: flex;
  133. justify-content: flex-start;
  134. image {
  135. width: 40rpx;
  136. height: 40rpx;
  137. margin-right: 6rpx;
  138. }
  139. }
  140. .login-btn {
  141. width: 600rpx;
  142. height: 90rpx;
  143. text-align: center;
  144. line-height: 90rpx;
  145. background-color: #000;
  146. border-radius: 45rpx;
  147. color: #fff;
  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>