empower.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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="title1">欢迎使用车蓝图养车小程序</view>
  8. <view class="title2">车蓝图养车为您的爱车提供全方面的功能支持 为保证您能正常使用,请以此授权微信和手机号</view>
  9. <button class="wxlogin" @click="wxgologin">授权微信用户信息</button>
  10. <view class="title3" @click="goIndex">取消授权</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. wxdata: '',
  19. wxCode: '',
  20. openID: '',
  21. session_key: '',
  22. wxPhoneData: '',
  23. type: '',
  24. wxOpendata: '',
  25. isload: false,
  26. souquan:true,
  27. }
  28. },
  29. onLoad(opt) {
  30. this.type = opt.type;
  31. this.wxOpendata = uni.getStorageSync("wxOpendata");
  32. if (this.wxOpendata) {
  33. uni.switchTab({
  34. url: '../index/index'
  35. })
  36. } else {
  37. this.isload = true;
  38. }
  39. },
  40. methods: {
  41. goIndex() {
  42. uni.switchTab({
  43. url: '../index/index'
  44. })
  45. },
  46. //api uni.getUserProfile
  47. wxgologin() {
  48. var that = this;
  49. if (that.souquan == false) {
  50. return
  51. }
  52. uni.getUserProfile({
  53. lang: 'zh_CN',
  54. desc: '登录',
  55. success: (res) => {
  56. console.log(res);
  57. that.wxdata = res;
  58. uni.setStorage({
  59. key: 'wxdata',
  60. data: res,
  61. success: function() {
  62. that.ipLogin()
  63. }
  64. });
  65. },
  66. fail: (res) => {
  67. console.log(res)
  68. }
  69. });
  70. that.souquan = false;
  71. setTimeout(function() {
  72. that.souquan = true;
  73. }, 2000);
  74. },
  75. //api uni.login
  76. ipLogin() {
  77. var that = this;
  78. uni.showLoading({});
  79. uni.login({
  80. provider: 'weixin',
  81. success: function(loginRes) {
  82. // console.log(loginRes)
  83. that.wxCode = loginRes.code
  84. that.getWxOpenID()
  85. }
  86. });
  87. },
  88. getWxOpenID() {
  89. var that = this;
  90. this.$http('worldKeepCar/sys/getWxOpenID', {
  91. code: this.wxCode,
  92. }, 'GET').then(res => {
  93. // console.log(res)
  94. this.openID = res.data.openid;
  95. this.session_key = res.data.session_key;
  96. // console.log(this.openID)
  97. uni.setStorage({
  98. key: 'wxOpendata',
  99. data: res.data,
  100. success: function() {
  101. // that.ipLogin()
  102. uni.hideLoading();
  103. if (!that.type) {
  104. uni.switchTab({
  105. url: '../index/index'
  106. })
  107. } else {
  108. uni.redirectTo({
  109. url: 'login'
  110. })
  111. }
  112. }
  113. });
  114. })
  115. },
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .euroImg {
  121. width: 440rpx;
  122. height: 360rpx;
  123. }
  124. .logoBox {
  125. text-align: center;
  126. padding-top: 160rpx;
  127. }
  128. .title1 {
  129. font-size: 30rpx;
  130. text-align: center;
  131. font-weight: bold;
  132. color: #3C3C3C;
  133. margin-top: 113rpx;
  134. }
  135. .title2 {
  136. font-size: 26rpx;
  137. text-align: center;
  138. color: #999999;
  139. margin: 20rpx 98rpx 80rpx;
  140. text-indent: 1em;
  141. }
  142. .wxlogin {
  143. width: 658rpx;
  144. height: 88rpx;
  145. background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%) #FF2400;
  146. border-radius: 10rpx;
  147. line-height: 88rpx;
  148. text-align: center;
  149. color: #FFFFFF;
  150. font-size: 30rpx;
  151. margin-top: 20rpx;
  152. }
  153. .title3 {
  154. width: 100vw;
  155. position: fixed;
  156. left: 0;
  157. bottom: 50rpx;
  158. font-size: 26rpx;
  159. text-align: center;
  160. color: #999999;
  161. }
  162. </style>