empower.vue 3.0 KB

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