empower.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. },
  72. //api uni.login
  73. ipLogin() {
  74. var that = this;
  75. uni.showLoading({});
  76. uni.login({
  77. provider: 'weixin',
  78. success: function(loginRes) {
  79. // console.log(loginRes)
  80. that.wxCode = loginRes.code
  81. that.getWxOpenID()
  82. }
  83. });
  84. },
  85. getWxOpenID() {
  86. var that = this;
  87. this.$http('worldKeepCar/sys/getWxOpenID', {
  88. code: this.wxCode,
  89. }, 'GET').then(res => {
  90. // console.log(res)
  91. this.openID = res.data.openid;
  92. this.session_key = res.data.session_key;
  93. // console.log(this.openID)
  94. uni.setStorage({
  95. key: 'wxOpendata',
  96. data: res.data,
  97. success: function() {
  98. // that.ipLogin()
  99. uni.hideLoading();
  100. if (!that.type) {
  101. uni.switchTab({
  102. url: '../index/index'
  103. })
  104. } else {
  105. uni.redirectTo({
  106. url: 'login'
  107. })
  108. }
  109. }
  110. });
  111. })
  112. },
  113. }
  114. }
  115. </script>
  116. <style scoped>
  117. .euroImg {
  118. width: 440rpx;
  119. height: 360rpx;
  120. }
  121. .logoBox {
  122. text-align: center;
  123. padding-top: 160rpx;
  124. }
  125. .title1 {
  126. font-size: 30rpx;
  127. text-align: center;
  128. font-weight: bold;
  129. color: #3C3C3C;
  130. margin-top: 113rpx;
  131. }
  132. .title2 {
  133. font-size: 26rpx;
  134. text-align: center;
  135. color: #999999;
  136. margin: 20rpx 98rpx 80rpx;
  137. text-indent: 1em;
  138. }
  139. .wxlogin {
  140. width: 658rpx;
  141. height: 88rpx;
  142. background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%) #FF2400;
  143. border-radius: 10rpx;
  144. line-height: 88rpx;
  145. text-align: center;
  146. color: #FFFFFF;
  147. font-size: 30rpx;
  148. margin-top: 20rpx;
  149. }
  150. .title3 {
  151. width: 100vw;
  152. position: fixed;
  153. left: 0;
  154. bottom: 50rpx;
  155. font-size: 26rpx;
  156. text-align: center;
  157. color: #999999;
  158. }
  159. </style>