logincode.vue 9.6 KB

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