index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="flex container">
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="微信授权"></u-navbar>
  4. <view class="login">
  5. <view class="flex login-image">
  6. <view class="image"></view>
  7. </view>
  8. <view class="login-txt">呱呱刮</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. $http.post('/api/v1/mp/user/wxauth/mobile', {
  34. code: e.detail.code,
  35. identity: 1
  36. }).then(res => {
  37. if (res.code == 0) {
  38. uni.setStorageSync('token', res.token)
  39. this.getBaseInfo()
  40. }
  41. })
  42. },
  43. // 关闭授权
  44. authClose() {
  45. this.authShow = false
  46. setTimeout(() => {
  47. uni.navigateBack({
  48. delta: 1
  49. })
  50. }, 500)
  51. },
  52. getBaseInfo() {
  53. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  54. if (res.code == 0) {
  55. uni.setStorageSync('userInfo', res.data)
  56. if (res.data.openId) {
  57. uni.$u.toast('登录成功');
  58. setTimeout(() => {
  59. uni.navigateBack({
  60. delta: 1
  61. })
  62. }, 500)
  63. } else {
  64. this.authShow = true
  65. }
  66. }
  67. })
  68. },
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .container {
  74. height: 100vh;
  75. width: 100%;
  76. flex-direction: column;
  77. }
  78. .login {
  79. &-image {
  80. .image {
  81. width: 164rpx;
  82. height: 164rpx;
  83. border-radius: 10rpx;
  84. margin-bottom: 14rpx;
  85. background-color: $uni-bg-color;
  86. }
  87. }
  88. &-txt {
  89. text-align: center;
  90. line-height: 40rpx;
  91. font-weight: bold;
  92. margin-bottom: 20rpx;
  93. }
  94. &-title {
  95. text-align: center;
  96. font-size: 24rpx;
  97. font-weight: normal;
  98. margin-bottom: 50rpx;
  99. }
  100. &-btn {
  101. button {
  102. width: 570rpx;
  103. height: 60rpx;
  104. line-height: 60rpx;
  105. border-radius: 30rpx;
  106. background-color: rgba(235, 112, 9, 100);
  107. color: rgba(255, 255, 255, 100);
  108. text-align: center;
  109. font-size: 28rpx;
  110. }
  111. }
  112. }
  113. </style>