empower.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="container" >
  3. <view v-if="!wxOpendata&&isload">
  4. <view class="logoBox">
  5. <image src="../../static/img/euro.png" mode="" class="euroImg"></image>
  6. </view>
  7. <view class="title1">请完成微信授权以继续使用</view>
  8. <button class="wxlogin" @click="wxgologin">授权微信用户信息</button>
  9. <view class="title2" @click="goIndex">取消授权</view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. wxdata:'',
  18. wxCode:'',
  19. openID:'',
  20. session_key:'',
  21. wxPhoneData:'',
  22. type:'',
  23. wxOpendata:'',
  24. isload:false,
  25. }
  26. },
  27. onLoad(opt) {
  28. this.type=opt.type;
  29. this.wxOpendata=uni.getStorageSync("wxOpendata");
  30. if( this.wxOpendata){
  31. uni.switchTab({
  32. url:'../index/index'
  33. })
  34. }else{
  35. this.isload=true;
  36. }
  37. },
  38. methods: {
  39. goIndex(){
  40. uni.switchTab({
  41. url:'../index/index'
  42. })
  43. },
  44. //api uni.getUserProfile
  45. wxgologin(){
  46. var that=this;
  47. uni.getUserProfile({
  48. lang:'zh_CN',
  49. desc:'登录',
  50. success:(res)=>{
  51. console.log(res);
  52. that.wxdata=res;
  53. uni.setStorage({
  54. key: 'wxdata',
  55. data: res,
  56. success: function () {
  57. that.ipLogin()
  58. }
  59. });
  60. },
  61. fail:(res)=>{
  62. console.log(res)
  63. }
  64. });
  65. },
  66. //api uni.login
  67. ipLogin(){
  68. var that=this;
  69. uni.showLoading({ });
  70. uni.login({
  71. provider: 'weixin',
  72. success: function (loginRes) {
  73. // console.log(loginRes)
  74. that.wxCode=loginRes.code
  75. that.getWxOpenID()
  76. }
  77. });
  78. },
  79. getWxOpenID(){
  80. var that=this;
  81. this.$http('worldKeepCar/sys/getWxOpenID', {
  82. code:this.wxCode,
  83. },'GET').then(res => {
  84. // console.log(res)
  85. this.openID=res.data.openid;
  86. this.session_key=res.data.session_key;
  87. // console.log(this.openID)
  88. uni.setStorage({
  89. key: 'wxOpendata',
  90. data: res.data,
  91. success: function () {
  92. // that.ipLogin()
  93. uni.hideLoading();
  94. if(!that.type){
  95. uni.switchTab({
  96. url:'../index/index'
  97. })
  98. }else{
  99. uni.redirectTo({
  100. url:'login'
  101. })
  102. }
  103. }
  104. });
  105. })
  106. },
  107. }
  108. }
  109. </script>
  110. <style scoped>
  111. .euroImg{
  112. width: 290rpx;
  113. height: 266rpx;
  114. }
  115. .logoBox{
  116. text-align: center;
  117. padding-top: 160rpx;
  118. }
  119. .title1{
  120. font-size: 26rpx;
  121. text-align: center;
  122. color: #576B95;
  123. padding-top: 150rpx;
  124. }
  125. .wxlogin{
  126. width: 658rpx;
  127. height: 88rpx;
  128. background: linear-gradient(113deg, #FF630F 0%, #FF450F 100%);
  129. border-radius: 10rpx;
  130. line-height: 88rpx;
  131. text-align: center;
  132. color: #FFFFFF;
  133. font-size: 30rpx;
  134. margin-top: 20rpx;
  135. }
  136. .title2{
  137. width: 100vw;
  138. position: fixed;
  139. left: 0;
  140. bottom: 50rpx;
  141. font-size: 26rpx;
  142. text-align: center;
  143. color: #576B95;
  144. }
  145. </style>