index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="container">
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="微信授权"></u-navbar>
  4. <view class="flex login">
  5. <view class="flex login-image">
  6. <image src="../../static/logo.png" mode=""></image>
  7. <view class="login-image-txt">盲票</view>
  8. </view>
  9. <view class="login-txt">盲票将为您提供</view>
  10. <view class="login-title">商品兑换、盲票购买等服务 请先完成授权登录</view>
  11. <view class="login-btn">
  12. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信授权登录</button>
  13. </view>
  14. </view>
  15. <auth :auth-show="authShow" :auth-token="token" @close="authClose" />
  16. </view>
  17. </template>
  18. <script>
  19. import $http from '@/utils/request.js'
  20. import Auth from '../../components/auth/auth.vue'
  21. export default {
  22. components: {
  23. Auth
  24. },
  25. data() {
  26. return {
  27. authShow: false,
  28. token: '',
  29. };
  30. },
  31. methods: {
  32. getPhoneNumber(e) {
  33. let _this = this
  34. uni.showLoading({
  35. title: '登录中'
  36. });
  37. if (e.detail & e.detail.code) {
  38. $http.post('/api/v1/mp/user/wxauth/mobile', {
  39. ...e.detail,
  40. identity: 1,
  41. noToken: true
  42. }).then(res => {
  43. uni.hideLoading();
  44. if (res.code == 0) {
  45. uni.setStorageSync('token', res.token)
  46. _this.getBaseInfo()
  47. }
  48. }).catch(() => {
  49. uni.hideLoading();
  50. })
  51. }else{
  52. uni.login({
  53. success(res) {
  54. $http.post('/api/v1/mp/user/wxauth/mobile', {
  55. ...e.detail,
  56. loginCode: res.code,
  57. identity: 1,
  58. noToken: true
  59. }).then(res => {
  60. uni.hideLoading();
  61. if (res.code == 0) {
  62. uni.setStorageSync('token', res.token)
  63. _this.getBaseInfo()
  64. }
  65. }).catch(() => {
  66. uni.hideLoading();
  67. })
  68. }
  69. })
  70. }
  71. },
  72. // 关闭授权
  73. authClose() {
  74. this.authShow = false
  75. setTimeout(() => {
  76. uni.navigateBack({
  77. delta: 1
  78. })
  79. }, 500)
  80. },
  81. getBaseInfo() {
  82. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  83. uni.hideLoading();
  84. if (res.code == 0) {
  85. uni.setStorageSync('userInfo', res.data)
  86. if (res.data.openId) {
  87. uni.$u.toast('登录成功');
  88. setTimeout(() => {
  89. uni.navigateBack({
  90. delta: 1
  91. })
  92. }, 500)
  93. } else {
  94. this.authShow = true
  95. }
  96. }
  97. }).catch(() => {
  98. uni.hideLoading();
  99. })
  100. },
  101. }
  102. }
  103. </script>
  104. <style lang="scss" scoped>
  105. .container {
  106. height: 100vh;
  107. width: 100%;
  108. }
  109. .login {
  110. flex-direction: column;
  111. &-image {
  112. flex-direction: column;
  113. padding: 100rpx 0 200rpx;
  114. image {
  115. width: 164rpx;
  116. height: 164rpx;
  117. border-radius: 10rpx;
  118. margin-bottom: 14rpx;
  119. }
  120. &-txt {
  121. text-align: center;
  122. line-height: 40rpx;
  123. font-weight: bold;
  124. margin-bottom: 20rpx;
  125. font-size: 36rpx;
  126. }
  127. }
  128. &-txt {
  129. text-align: center;
  130. line-height: 40rpx;
  131. font-weight: bold;
  132. margin-bottom: 20rpx;
  133. }
  134. &-title {
  135. text-align: center;
  136. font-size: 24rpx;
  137. font-weight: normal;
  138. margin-bottom: 50rpx;
  139. }
  140. &-btn {
  141. button {
  142. width: 600rpx;
  143. height: 80rpx;
  144. line-height: 80rpx;
  145. border-radius: 40rpx;
  146. background-color: rgba(235, 112, 9, 100);
  147. color: rgba(255, 255, 255, 100);
  148. text-align: center;
  149. font-size: 28rpx;
  150. }
  151. }
  152. }
  153. </style>