login.vue 4.0 KB

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