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