login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 ref="vcodeInputRef" @vcodeInput="vcodeInput" sum="6"></vcode-input>
  14. </view>
  15. <!-- 提示信息 -->
  16. <view class="logo-message"><text>邀请码错误,请联系采美客服获取最新邀请码</text> </view>
  17. <button class="login-btn" :disabled="!isCodeEmpty">登录</button>
  18. </view>
  19. </template>
  20. <script>
  21. import authorize from '@/common/config/authorize.js'
  22. import wxLogin from '@/common/config/wxLogin.js'
  23. import VcodeInput from '@/components/vcode-input/vcode-input'
  24. import { mapState, mapMutations } from 'vuex'
  25. import { invitationCodeLogin } from '@/services/use.js'
  26. export default {
  27. components: { VcodeInput },
  28. data() {
  29. return {
  30. invitationCode: '' //获取用户登录的邀请码
  31. }
  32. },
  33. onLoad(option) {},
  34. computed: {
  35. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  36. isCodeEmpty() {
  37. return this.invitationCode.length > 0
  38. }
  39. },
  40. methods: {
  41. ...mapMutations(['login']),
  42. goLogin() {
  43. if (this.invitationCode == '') {
  44. this.$util.msg('请输入邀请码', 2000)
  45. return
  46. }
  47. wx.getUserInfo({
  48. success: res => {
  49. this.isUserInfo = false
  50. this.userInfo = res.userInfo
  51. let params = {
  52. invitationCode: this.invitationCode,
  53. nickName: res.userInfo.nickName,
  54. headimgurl: res.userInfo.avatarUrl
  55. }
  56. invitationCodeLogin(params)
  57. .then(response => {
  58. this.login(response.data)
  59. wxLogin.wxLoginAuthorize()
  60. if (response.data.userIdentity === 3) {
  61. setTimeout(() => {
  62. this.$api.navigateTo('/supplier/pages/index/index')
  63. }, 1000)
  64. } else {
  65. setTimeout(() => {
  66. switch (this.isLoginType) {
  67. case 9:
  68. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  69. break
  70. case 8:
  71. this.$api.navigateTo(
  72. `/pages/goods/product?id=${this.isLoginProductId}`
  73. )
  74. break
  75. case 7:
  76. this.$api.navigateTo(
  77. `/pages/user/order/order-details?type=share&orderID=${
  78. this.isLoginOrderId
  79. }`
  80. )
  81. break
  82. default:
  83. this.$api.switchTabTo('/pages/tabBar/user/user')
  84. }
  85. }, 1000)
  86. }
  87. })
  88. .catch(error => {
  89. this.$util.msg(error.msg, 2000)
  90. this.isUserInfo = false
  91. })
  92. }
  93. })
  94. },
  95. // 用户输入的值
  96. vcodeInput(val) {
  97. console.log(val)
  98. this.invitationCode = 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. }
  114. </script>
  115. <style lang="scss">
  116. .login {
  117. display: flex;
  118. align-items: center;
  119. flex-direction: column;
  120. .login-main,
  121. .login-title,
  122. .logo-message {
  123. width: 590rpx;
  124. }
  125. .login-main {
  126. display: flex;
  127. justify-content: center;
  128. margin: 180rpx 0 60rpx;
  129. image {
  130. width: 151rpx;
  131. height: 151rpx;
  132. border-radius: 50%;
  133. }
  134. }
  135. .login-title {
  136. display: flex;
  137. justify-content: flex-start;
  138. image {
  139. width: 40rpx;
  140. height: 40rpx;
  141. margin-right: 6rpx;
  142. }
  143. }
  144. .login-btn {
  145. width: 600rpx;
  146. height: 90rpx;
  147. text-align: center;
  148. line-height: 90rpx;
  149. background-color: #000;
  150. border-radius: 45rpx;
  151. color: #fff;
  152. }
  153. .login-input {
  154. margin: 30rpx 0;
  155. }
  156. .logo-message {
  157. margin-bottom: 64rpx;
  158. font-size: 24rpx;
  159. line-height: 33rpx;
  160. color: #ff2a2a;
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. &::before {
  165. content: '!';
  166. display: block;
  167. width: 22rpx;
  168. height: 22rpx;
  169. border: 1px solid #ff2a2a;
  170. border-radius: 50%;
  171. color: #ff2a2a;
  172. text-align: center;
  173. line-height: 22rpx;
  174. margin-right: 6rpx;
  175. }
  176. }
  177. }
  178. </style>