loginType.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="pages">
  3. <view class="page-bg-wrap">
  4. <image :src="$getimg+'loginType-bg.png'" class="page-bg" mode="widthFix"></image>
  5. </view>
  6. <view class="login-out">
  7. <view class="login-wrap" v-if="!hasLogin">
  8. <view class="login-item" open-type="getUserInfo" @getuserinfo="personLogin">
  9. <view class="login-item-icon">
  10. <text class="iconfont icon-gerenyonghu"></text>
  11. </view>
  12. <view class="login-item-text">个人用户</view>
  13. <button type="default" class="wxlogin-btn" open-type="getUserInfo" @getuserinfo="personLogin">登录</button>
  14. </view>
  15. <view class="login-item" @click="companyLogin">
  16. <view class="login-item-icon">
  17. <text class="iconfont icon-qiyeyonghu"></text>
  18. </view>
  19. <view class="login-item-text">企业用户</view>
  20. </view>
  21. </view>
  22. <view class="getphone" v-if="hasLogin&&havePhone==false">
  23. <button type="default" class="getPhoneNumber" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">绑定手机号</button>
  24. <view class="tip">
  25. 为获取更好的服务,请绑定手机号
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { mapState, mapMutations } from 'vuex';
  33. export default {
  34. data() {
  35. return {
  36. $getimg:this.$getimg,
  37. backUrl:'',
  38. havePhone:false,
  39. }
  40. },
  41. computed: {
  42. ...mapState(['hasLogin', 'userInfo'])
  43. },
  44. onShow() {
  45. console.log('this.hasLogin',this.hasLogin);
  46. if(this.hasLogin){
  47. uni.switchTab({
  48. url:'../index/index',
  49. fail: (err) => {
  50. console.log(err)
  51. }
  52. })
  53. }
  54. },
  55. onLoad(options) {
  56. this.backUrl = options.backUrl;
  57. },
  58. methods: {
  59. ...mapMutations(['login','upInfo']),
  60. personLogin(e){
  61. let serf = this;
  62. let userinfo = e.detail;
  63. // console.log('e',e);
  64. uni.login({
  65. provider:'weixin',
  66. success(res){
  67. let code = res.code;
  68. // console.log('loginres',res);
  69. let params = {
  70. code:code,
  71. encryptedData:userinfo.encryptedData,
  72. iv:userinfo.iv,
  73. rawData:userinfo.rawData,
  74. };
  75. serf.$api.http.post(serf.config.apiBaseurl+"/carbon-h5/wechat/app/login",params).then(res=>{
  76. console.log('res',res)
  77. if(res.data.code == 1){
  78. serf.$api.msg(res.data.msg);
  79. return false;
  80. };
  81. serf.login(res.data.retBody);
  82. serf.upInfo();
  83. uni.getStorage({
  84. key: 'userInfo',
  85. success: function (res) {
  86. // console.log('userInfo',res.data);
  87. if(res.data.phone){
  88. serf.havePhone = true;
  89. }else{
  90. return;
  91. }
  92. }
  93. });
  94. if(serf.backUrl == '' || !serf.backUrl){
  95. uni.switchTab({
  96. url: '/pages/usercenter/usercenter'
  97. })
  98. }else{
  99. uni.navigateTo({
  100. url:serf.backUrl
  101. })
  102. }
  103. })
  104. },
  105. })
  106. },
  107. onGetPhoneNumber(e){
  108. let serf = this;
  109. let userinfo = e.detail;
  110. let token = uni.getStorageSync('accessToken').accessToken;
  111. console.log('token',token);
  112. console.log('e',e);
  113. uni.login({
  114. provider:'weixin',
  115. success(res){
  116. let code = res.code;
  117. console.log('loginres',res);
  118. let params = {
  119. code:code,
  120. encryptedData:userinfo.encryptedData,
  121. iv:userinfo.iv,
  122. rawData:userinfo.rawData,
  123. }
  124. serf.$api.http.post(serf.config.apiBaseurl+"/carbon-h5/wechat/app/login/phone",params,{
  125. header: {
  126. Accept:'application/json',
  127. Authorization: 'Bearer '+ token, //注意Bearer后面有一空格
  128. },
  129. }).then(res=>{
  130. serf.upInfo();
  131. let userKey = uni.getStorageSync('userInfo');
  132. if(serf.backUrl == '' || !serf.backUrl){
  133. uni.switchTab({
  134. url: '/pages/usercenter/usercenter'
  135. })
  136. }else{
  137. uni.navigateTo({
  138. url:serf.backUrl
  139. })
  140. }
  141. })
  142. }
  143. })
  144. },
  145. companyLogin(){
  146. uni.navigateTo({
  147. url:'/pages/login/companyLogin'
  148. })
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. /* @import url("./index.css"); */
  155. .login-out{position: fixed;left: 0;right: 0;bottom: 144rpx;}
  156. .login-wrap{display: flex;align-items: center;text-align: center;}
  157. .login-item{flex: 1;position: relative;}
  158. .login-item-icon{display: flex;margin: 0 auto 14rpx;align-items: center;justify-content: center;width: 151rpx;height: 151rpx;border-radius: 50%;background: linear-gradient(139deg, #43D394 0%, #18C197 100%);}
  159. .login-item-icon .iconfont{color: #fff;font-size: 64rpx;}
  160. .login-item-text{font-size: 28rpx;color: #666;line-height: 40rpx;}
  161. .wxlogin-btn{position: absolute;left: 0;top: 0;right: 0;bottom: 0;opacity: 0;}
  162. .getPhoneNumber{margin: 0 24rpx;}
  163. .getphone .tip{text-align: center;margin: 24rpx;font-size: 24rpx;color: #666;}
  164. </style>