logincode.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. <input type="number"
  8. v-model="params.invitationCode"
  9. maxlength="6"
  10. class="input"
  11. placeholder="请输入邀请码"
  12. />
  13. </view>
  14. <view class="login-row" @click.stop="this.$api.navigateTo('/pages/login/register-select')"><text>免费注册</text></view>
  15. <view class="login-btn" @click.stop="goLogin">登录</view>
  16. <view class="login-btn-last" @click.stop="this.$api.navigateTo('/pages/login/login')">账号登录</view>
  17. </view>
  18. </template>
  19. <script>
  20. import authorize from '@/common/config/authorize.js'
  21. import wxLogin from "@/common/config/wxLogin.js"
  22. import {mapState,mapMutations } from 'vuex';
  23. export default{
  24. data() {
  25. return{
  26. params:{
  27. invitationCode:'',//获取用户登录的邀请码
  28. unionId:0,
  29. nickName:'',
  30. avatarUrl:'',
  31. },
  32. }
  33. },
  34. onLoad(option) {
  35. },
  36. computed: {
  37. ...mapState(['isWxAuthorize','isLoginType','isLoginProductId','isLoginOrderId'])
  38. },
  39. methods:{
  40. ...mapMutations(['login','wxLogin']),
  41. goLogin(){
  42. if( this.params.invitationCode == ''){
  43. this.$util.msg('请输入邀请码',2000)
  44. return
  45. }
  46. this.isUserInfo = false
  47. this.params.unionId = uni.getStorageSync('unionId')
  48. this.GetUserProfile()
  49. },
  50. GetUserProfile(){//获取用户微信个人信息
  51. const self = this
  52. wx.getUserProfile({
  53. desc: '采美采购商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  54. success(res) {
  55. console.log('微信获取用户信息新API',res)
  56. self.wxLogin(res.userInfo)
  57. self.params.nickName = res.userInfo.nickName
  58. self.params.avatarUrl = res.userInfo.avatarUrl
  59. self.BindingWechat(self.params)
  60. },
  61. fail() {
  62. self.$util.msg('授权失败', 2000)
  63. }
  64. })
  65. },
  66. BindingWechat(params){//邀请码登录并绑定微信
  67. this.UserService.InvitationCodeLogin(params)
  68. .then(response =>{
  69. wxLogin.wxLoginAuthorize()
  70. if(response.data.userIdentity === 3){
  71. setTimeout(()=>{
  72. this.$api.navigateTo('/supplier/pages/index/index')
  73. },1500)
  74. }else{
  75. setTimeout(()=>{
  76. switch(this.isLoginType){
  77. case 9:
  78. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  79. break;
  80. case 8:
  81. this.$api.navigateTo(`/pages/goods/product?id=${this.isLoginProductId}`)
  82. break;
  83. case 7:
  84. this.$api.navigateTo(`/pages/user/order/order-details?type=share&orderID=${this.isLoginOrderId}`)
  85. break;
  86. default:
  87. this.$api.switchTabTo('/pages/tabBar/user/user')
  88. }
  89. },1500)
  90. }
  91. })
  92. .catch(error =>{
  93. this.$util.msg(error.msg,2000)
  94. this.isUserInfo = false
  95. })
  96. },
  97. InitAuthorize(){ //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  98. wxLogin.wxLoginQuick()
  99. }
  100. },
  101. onShow() {
  102. this.$api.getStorage().then((resolve) =>{
  103. this.params.unionId = resolve.unionId ? resolve.unionId : 0
  104. })
  105. this.InitAuthorize()
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .login{
  111. width: 100%;
  112. height: auto;
  113. .model-warp.none{
  114. display: none;
  115. }
  116. .model-warp.show{
  117. display: block;
  118. }
  119. .login-main{
  120. width: 100%;
  121. display: flex;
  122. flex-direction: column;
  123. align-items: center;
  124. height: 189rpx;
  125. padding:60rpx 0 40rpx 0;
  126. margin-bottom: 70rpx;
  127. .logo{
  128. width:467rpx;
  129. height: 189rpx;
  130. display: block;
  131. }
  132. }
  133. .login-input{
  134. width: 600rpx;
  135. height: 88rpx;
  136. padding: 24rpx 0;
  137. margin: 0 auto;
  138. margin-bottom: 30rpx;
  139. background: #FFFFFF;
  140. position: relative;
  141. box-sizing: border-box;
  142. border-bottom: 1px solid #E1E1E1;
  143. .input{
  144. width: 100%;
  145. height: 100%;
  146. background: #FFFFFF;
  147. font-size: $font-size-28;
  148. line-height: 88rpx;
  149. color: #333333;
  150. }
  151. }
  152. .login-row{
  153. padding: 0 75rpx;
  154. font-size: $font-size-28;
  155. line-height: 40rpx;
  156. color: #E15616;
  157. margin-bottom: 48rpx;
  158. text-align: right;
  159. }
  160. .login-btn{
  161. width: 600rpx;
  162. height: 88rpx;
  163. border-radius: 44rpx;
  164. font-size: $font-size-28;
  165. line-height: 88rpx;
  166. color: #FFFFFF;
  167. margin: 0 auto;
  168. text-align: center;
  169. background: $btn-confirm;
  170. }
  171. .login-btn-last{
  172. width: 600rpx;
  173. height: 86rpx;
  174. border-radius: 44rpx;
  175. font-size: $font-size-28;
  176. line-height: 88rpx;
  177. color: $color-system;
  178. margin: 0 auto;
  179. text-align: center;
  180. border: 1px solid $color-system;
  181. margin-top: 20rpx;
  182. }
  183. .model-authorization{
  184. width: 100%;
  185. height: 100%;
  186. position: fixed;
  187. top: 0;
  188. left: 0;
  189. z-index: 999;
  190. .authorization{
  191. width: 518rpx;
  192. height: 320rpx;
  193. position: absolute;
  194. background: rgba(255,255,255,.7);
  195. left: 0;
  196. right: 0;
  197. bottom: 0;
  198. top: 0;
  199. margin: auto;
  200. .to-btn{
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. right: 0;
  205. bottom: 0;
  206. margin: auto;
  207. width: 70%;
  208. height: 88rpx;
  209. font-size: $font-size-28;
  210. line-height: 88rpx;
  211. color: #FFFFFF;
  212. text-align: center;
  213. border-radius: 44rpx;
  214. }
  215. }
  216. }
  217. }
  218. </style>