index.vue 2.6 KB

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