login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. let params = {
  61. invitationCode: this.invitationCode,
  62. nickName: res.userInfo.nickName,
  63. openid: uni.getStorageSync('openid')
  64. }
  65. // 验证邀请码
  66. this.UserService.userInvitation(params).then(response => {
  67. console.log(response)
  68. // 保存用户信息
  69. this.login(response.data)
  70. this.$store.commit('updateStatus',response.data)
  71. setTimeout(()=>{
  72. this.$api.navigateTo(`/pages/index/index`)
  73. },1500)
  74. }).catch(error => {
  75. this.loginMessage = error.msg
  76. this.isUserInfo = false
  77. // this.$util.msg(error.msg, 2000)
  78. })
  79. }
  80. })
  81. },
  82. // 输入框输入介绍
  83. vcodeInput(val) {
  84. // this.invitationCode = val
  85. console.log(val)
  86. },
  87. // 输入框输入事件
  88. vcodeChangeHandle(val) {
  89. this.invitationCode = val
  90. console.log(val)
  91. },
  92. // 控制组件获取焦点
  93. setFocus() {
  94. this.$refs.VcodeInput.setFocus()
  95. },
  96. // 控制组件失去焦点
  97. setBlur() {
  98. this.$refs.VcodeInput.setBlur()
  99. },
  100. // 清除已输入
  101. clearValue() {
  102. this.$refs.VcodeInput.clearValue()
  103. }
  104. },
  105. onShow() {
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .login {
  111. display: flex;
  112. align-items: center;
  113. flex-direction: column;
  114. .login-main,
  115. .login-title,
  116. .logo-message {
  117. width: 590rpx;
  118. }
  119. .login-main {
  120. display: flex;
  121. justify-content: center;
  122. margin: 180rpx 0 60rpx;
  123. image {
  124. width: 151rpx;
  125. height: 151rpx;
  126. border-radius: 50%;
  127. }
  128. }
  129. .login-title {
  130. display: flex;
  131. justify-content: flex-start;
  132. image {
  133. width: 40rpx;
  134. height: 40rpx;
  135. margin-right: 6rpx;
  136. }
  137. }
  138. .login-btn {
  139. width: 600rpx;
  140. height: 90rpx;
  141. text-align: center;
  142. line-height: 90rpx;
  143. background-color: #000;
  144. border-radius: 45rpx;
  145. color: #fff;
  146. box-shadow: 4rpx 4rpx 40rpx rgba(0, 0, 0, 0.2);
  147. margin-top: 40rpx;
  148. }
  149. .login-input {
  150. margin: 30rpx 0;
  151. }
  152. .logo-message {
  153. margin-bottom: 64rpx;
  154. font-size: 24rpx;
  155. line-height: 33rpx;
  156. color: #ff2a2a;
  157. display: flex;
  158. justify-content: center;
  159. align-items: center;
  160. &::before {
  161. content: '!';
  162. display: block;
  163. width: 22rpx;
  164. height: 22rpx;
  165. border: 1px solid #ff2a2a;
  166. border-radius: 50%;
  167. color: #ff2a2a;
  168. text-align: center;
  169. line-height: 22rpx;
  170. margin-right: 6rpx;
  171. }
  172. }
  173. }
  174. </style>