login.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 !== ''"><text>{{loginMessage}}</text> </view>
  24. <button class="login-btn" @click="goLogin" :disabled="isCodeEmpty">登录</button>
  25. </view>
  26. </template>
  27. <script>
  28. import authorize from '@/common/config/authorize.js'
  29. import wxLogin from '@/common/config/wxLogin.js'
  30. import VcodeInput from '@/components/vcode-input/vcode-input'
  31. import { mapState, mapMutations } from 'vuex'
  32. import { invitationCodeLogin } from '@/services/use.js'
  33. export default {
  34. components: { VcodeInput },
  35. data() {
  36. return {
  37. invitationCode: '', //获取用户登录的邀请码
  38. loginMessage:'' //登录信息反馈
  39. }
  40. },
  41. onLoad(option) {},
  42. computed: {
  43. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginProductId', 'isLoginOrderId']),
  44. // 邀请码长度是否符合要求
  45. isCodeEmpty() {
  46. return this.invitationCode.trim().length < 6
  47. }
  48. },
  49. methods: {
  50. ...mapMutations(['login']),
  51. // 登录
  52. goLogin() {
  53. if (this.invitationCode == '') {
  54. this.$util.msg('请输入邀请码', 2000)
  55. return
  56. }
  57. // 获取用户信息
  58. wx.getUserInfo({
  59. success: res => {
  60. this.isUserInfo = false
  61. this.userInfo = res.userInfo
  62. let params = {
  63. invitationCode: this.invitationCode,
  64. nickName: res.userInfo.nickName,
  65. headimgurl: res.userInfo.avatarUrl
  66. }
  67. // 验证邀请码
  68. invitationCodeLogin(params)
  69. .then(response => {
  70. // 保存用户信息
  71. this.login(response.data)
  72. wxLogin.wxLoginAuthorize()
  73. if (response.data.userIdentity === 3) {
  74. setTimeout(() => {
  75. this.$api.navigateTo('/supplier/pages/index/index')
  76. }, 1000)
  77. } else {
  78. setTimeout(() => {
  79. switch (this.isLoginType) {
  80. case 9:
  81. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  82. break
  83. case 8:
  84. this.$api.navigateTo(
  85. `/pages/goods/product?id=${this.isLoginProductId}`
  86. )
  87. break
  88. case 7:
  89. this.$api.navigateTo(
  90. `/pages/user/order/order-details?type=share&orderID=${
  91. this.isLoginOrderId
  92. }`
  93. )
  94. break
  95. default:
  96. this.$api.switchTabTo('/pages/tabBar/user/user')
  97. }
  98. }, 1000)
  99. }
  100. })
  101. .catch(error => {
  102. // this.$util.msg(error.msg, 2000)
  103. this.loginMessage = error.msg
  104. this.isUserInfo = false
  105. })
  106. }
  107. })
  108. },
  109. // 输入框输入介绍
  110. vcodeInput(val) {
  111. // this.invitationCode = val
  112. console.log(val)
  113. },
  114. // 输入框输入事件
  115. vcodeChangeHandle(val) {
  116. this.invitationCode = val
  117. console.log(val)
  118. },
  119. // 控制组件获取焦点
  120. setFocus() {
  121. this.$refs.VcodeInput.setFocus()
  122. },
  123. // 控制组件失去焦点
  124. setBlur() {
  125. this.$refs.VcodeInput.setBlur()
  126. },
  127. // 清除已输入
  128. clearValue() {
  129. this.$refs.VcodeInput.clearValue()
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. .login {
  136. display: flex;
  137. align-items: center;
  138. flex-direction: column;
  139. .login-main,
  140. .login-title,
  141. .logo-message {
  142. width: 590rpx;
  143. }
  144. .login-main {
  145. display: flex;
  146. justify-content: center;
  147. margin: 180rpx 0 60rpx;
  148. image {
  149. width: 151rpx;
  150. height: 151rpx;
  151. border-radius: 50%;
  152. }
  153. }
  154. .login-title {
  155. display: flex;
  156. justify-content: flex-start;
  157. image {
  158. width: 40rpx;
  159. height: 40rpx;
  160. margin-right: 6rpx;
  161. }
  162. }
  163. .login-btn {
  164. width: 600rpx;
  165. height: 90rpx;
  166. text-align: center;
  167. line-height: 90rpx;
  168. background-color: #000;
  169. border-radius: 45rpx;
  170. color: #fff;
  171. }
  172. .login-input {
  173. margin: 30rpx 0;
  174. }
  175. .logo-message {
  176. margin-bottom: 64rpx;
  177. font-size: 24rpx;
  178. line-height: 33rpx;
  179. color: #ff2a2a;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. &::before {
  184. content: '!';
  185. display: block;
  186. width: 22rpx;
  187. height: 22rpx;
  188. border: 1px solid #ff2a2a;
  189. border-radius: 50%;
  190. color: #ff2a2a;
  191. text-align: center;
  192. line-height: 22rpx;
  193. margin-right: 6rpx;
  194. }
  195. }
  196. }
  197. </style>