login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 borderValueColor="#e8e8e8" borderActiveColor="#e8e8e8" ref="vcodeInputRef" @vcodeInput="vcodeInput" @vcodeChange="vcodeChangeHandle" 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. vcodeChangeHandle(val){
  102. console.log(val);
  103. },
  104. // 控制组件获取焦点
  105. setFocus() {
  106. this.$refs.VcodeInput.setFocus()
  107. },
  108. // 控制组件失去焦点
  109. setBlur() {
  110. this.$refs.VcodeInput.setBlur()
  111. },
  112. // 清除已输入
  113. clearValue() {
  114. this.$refs.VcodeInput.clearValue()
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .login {
  121. display: flex;
  122. align-items: center;
  123. flex-direction: column;
  124. .login-main,
  125. .login-title,
  126. .logo-message {
  127. width: 590rpx;
  128. }
  129. .login-main {
  130. display: flex;
  131. justify-content: center;
  132. margin: 180rpx 0 60rpx;
  133. image {
  134. width: 151rpx;
  135. height: 151rpx;
  136. border-radius: 50%;
  137. }
  138. }
  139. .login-title {
  140. display: flex;
  141. justify-content: flex-start;
  142. image {
  143. width: 40rpx;
  144. height: 40rpx;
  145. margin-right: 6rpx;
  146. }
  147. }
  148. .login-btn {
  149. width: 600rpx;
  150. height: 90rpx;
  151. text-align: center;
  152. line-height: 90rpx;
  153. background-color: #000;
  154. border-radius: 45rpx;
  155. color: #fff;
  156. }
  157. .login-input {
  158. margin: 30rpx 0;
  159. }
  160. .logo-message {
  161. margin-bottom: 64rpx;
  162. font-size: 24rpx;
  163. line-height: 33rpx;
  164. color: #ff2a2a;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. &::before {
  169. content: '!';
  170. display: block;
  171. width: 22rpx;
  172. height: 22rpx;
  173. border: 1px solid #ff2a2a;
  174. border-radius: 50%;
  175. color: #ff2a2a;
  176. text-align: center;
  177. line-height: 22rpx;
  178. margin-right: 6rpx;
  179. }
  180. }
  181. }
  182. </style>