logincode.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <image class="logo" src="https://static.caimei365.com/app/img/icon/logo@2x.png" mode=""></image>
  5. </view>
  6. <view class="login-input">
  7. <keyInput borderValueColor="#E1E1E1" borderActiveColor="#E1E1E1" ref="vcodeInputRef" @vcodeInput="keyInput"
  8. @vcodeChange="keyInputChangeHandle" sum="6">
  9. </keyInput>
  10. </view>
  11. <button class="login-btn" @click.stop="goLogin" :class="isDisabled ? 'disabled' : ''"
  12. :disabled="isDisabled">邀请码登录</button>
  13. <view class="login-tips">
  14. 邀请码是采美平台为了方便机构内成员互相邀请并快速注册采美账号推出的一项邀请机制。机构成员在任一渠道(包括采美365网站和微信“采美采购商城”小程序)注册了采美账号,该成员可在其个人中心添加其他机构成员,系统自动为每一个成员生成邀请码。其他成员使用邀请码可直接登录“采美采购商城”小程序。
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import authorize from '@/common/config/authorize.js'
  20. import wxLogin from '@/common/config/wxLogin.js'
  21. import { mapState, mapMutations } from 'vuex'
  22. import keyInput from '@/components/uni-keyinput/uni-keyinput'
  23. export default {
  24. components: {
  25. keyInput
  26. },
  27. data() {
  28. return {
  29. params: {
  30. invitationCode: '', //获取用户登录的邀请码
  31. unionId: 0,
  32. nickName: '',
  33. avatarUrl: '',
  34. },
  35. }
  36. },
  37. onLoad(option) {
  38. },
  39. computed: {
  40. ...mapState(['isWxAuthorize', 'isLoginType', 'isLoginOrderId']),
  41. isDisabled() { // 邀请码长度是否符合要求
  42. return this.params.invitationCode.trim().length < 6
  43. },
  44. },
  45. methods: {
  46. ...mapMutations(['login', 'wxLogin']),
  47. goLogin() {
  48. if (this.params.invitationCode == '') {
  49. this.$util.msg('请输入邀请码', 2000)
  50. return
  51. }
  52. this.isUserInfo = false
  53. this.params.unionId = uni.getStorageSync('unionId')
  54. // 友盟埋点邀请码确认登录点击事件
  55. if (process.env.NODE_ENV != 'development') {
  56. this.$uma.trackEvent('Um_Event_InvitationCode', {
  57. Um_Key_PageName: '邀请码登录',
  58. Um_Key_SourcePage: '邀请码页面',
  59. })
  60. }
  61. this.GetUserProfile()
  62. },
  63. navigatorRegirst(url) {
  64. // 友盟埋点注册入口点击事件
  65. if (process.env.NODE_ENV != 'development') {
  66. this.$uma.trackEvent('Um_Event_zhuce', {
  67. Um_Key_PageName: '立即注册',
  68. Um_Key_SourcePage: '个人中心',
  69. })
  70. }
  71. this.$api.navigateTo(url)
  72. },
  73. GetUserProfile() { //获取用户微信个人信息
  74. const self = this
  75. wx.getUserProfile({
  76. desc: '采美采购商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  77. success(res) {
  78. console.log('微信获取用户信息新API', res)
  79. self.wxLogin(res.userInfo)
  80. self.params.nickName = res.userInfo.nickName
  81. self.params.avatarUrl = res.userInfo.avatarUrl
  82. self.BindingWechat(self.params)
  83. },
  84. fail() {
  85. self.$util.msg('授权失败', 2000)
  86. }
  87. })
  88. },
  89. async BindingWechat(params) {
  90. //绑定微信并登陆
  91. try {
  92. await this.UserService.InvitationCodeLogin(params)
  93. const url = uni.getStorageSync('LOGIN_REDIRECT_URL')
  94. wxLogin.wxLoginAuthorize()
  95. setTimeout(() => {
  96. if (url) {
  97. if (url.indexOf('tabBar') > -1) {
  98. uni.switchTabTo(url)
  99. } else {
  100. this.$api.reLaunch(url)
  101. }
  102. } else {
  103. if (this.userIdentity === 3) {
  104. this.$api.navigateTo('/pages/supplier/index/index')
  105. } else {
  106. this.$api.switchTabTo('/pages/tabBar/user/user')
  107. }
  108. }
  109. uni.removeStorageSync('LOGIN_REDIRECT_URL')
  110. }, 1000)
  111. } catch (error) {
  112. this.$util.msg(error.msg, 2000)
  113. this.isUserInfo = false
  114. }
  115. },
  116. keyInput(val) { // 输入框输入介绍
  117. // this.params.invitationCode = val
  118. console.log(val)
  119. },
  120. keyInputChangeHandle(val) { // 输入框输入事件
  121. this.params.invitationCode = val
  122. // console.log(val)
  123. },
  124. setFocus() { // 控制组件获取焦点
  125. this.$refs.VcodeInput.setFocus()
  126. },
  127. setBlur() { // 控制组件失去焦点
  128. this.$refs.VcodeInput.setBlur()
  129. },
  130. clearValue() { // 清除已输入
  131. this.$refs.VcodeInput.clearValue()
  132. },
  133. InitAuthorize() { //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  134. wxLogin.wxLoginQuick()
  135. }
  136. },
  137. onShow() {
  138. this.$api.getStorage().then((resolve) => {
  139. this.params.unionId = resolve.unionId ? resolve.unionId : 0
  140. })
  141. this.InitAuthorize()
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .login {
  147. width: 100%;
  148. height: auto;
  149. .model-warp.none {
  150. display: none;
  151. }
  152. .model-warp.show {
  153. display: block;
  154. }
  155. .login-main {
  156. width: 100%;
  157. display: flex;
  158. flex-direction: column;
  159. align-items: center;
  160. height: 284rpx;
  161. padding: 60rpx 0 40rpx 0;
  162. margin-bottom: 70rpx;
  163. .logo {
  164. width: 611rpx;
  165. height: 284rpx;
  166. display: block;
  167. }
  168. }
  169. .login-input {
  170. width: 600rpx;
  171. height: 88rpx;
  172. padding: 24rpx 0;
  173. margin: 30rpx auto;
  174. margin-bottom: 30rpx;
  175. background: #FFFFFF;
  176. position: relative;
  177. }
  178. .login-row {
  179. padding: 0 75rpx;
  180. font-size: $font-size-28;
  181. line-height: 40rpx;
  182. color: #FF5B00;
  183. margin-bottom: 48rpx;
  184. text-align: right;
  185. }
  186. .login-btn {
  187. width: 600rpx;
  188. height: 88rpx;
  189. border-radius: 44rpx;
  190. font-size: $font-size-28;
  191. line-height: 88rpx;
  192. color: #FFFFFF;
  193. margin: 0 auto;
  194. text-align: center;
  195. background: $btn-confirm;
  196. &.disabled {
  197. background: #E1E1E1;
  198. }
  199. }
  200. .login-btn-last {
  201. width: 600rpx;
  202. height: 86rpx;
  203. border-radius: 44rpx;
  204. font-size: $font-size-28;
  205. line-height: 88rpx;
  206. color: $color-system;
  207. margin: 0 auto;
  208. text-align: center;
  209. border: 1px solid $color-system;
  210. margin-top: 20rpx;
  211. }
  212. .login-tips {
  213. width: 100%;
  214. height: auto;
  215. margin-top: 80rpx;
  216. box-sizing: border-box;
  217. padding: 0 75rpx;
  218. line-height: 44rpx;
  219. font-size: $font-size-20;
  220. color: #fea785;
  221. text-align: justify;
  222. text-indent: 40rpx;
  223. }
  224. .model-authorization {
  225. width: 100%;
  226. height: 100%;
  227. position: fixed;
  228. top: 0;
  229. left: 0;
  230. z-index: 999;
  231. .authorization {
  232. width: 518rpx;
  233. height: 320rpx;
  234. position: absolute;
  235. background: rgba(255, 255, 255, .7);
  236. left: 0;
  237. right: 0;
  238. bottom: 0;
  239. top: 0;
  240. margin: auto;
  241. .to-btn {
  242. position: absolute;
  243. top: 0;
  244. left: 0;
  245. right: 0;
  246. bottom: 0;
  247. margin: auto;
  248. width: 70%;
  249. height: 88rpx;
  250. font-size: $font-size-28;
  251. line-height: 88rpx;
  252. color: #FFFFFF;
  253. text-align: center;
  254. border-radius: 44rpx;
  255. }
  256. }
  257. }
  258. }
  259. </style>