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