auth.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view>
  3. <u-popup :show="authShow" mode="bottom">
  4. <view class="auth-wrap">
  5. <view class="tip">为了正常使用功能,请授权用户信息。</view>
  6. <button :loading="authIng" @click="getInfo()" type="default">授权</button>
  7. </view>
  8. </u-popup>
  9. </view>
  10. </template>
  11. <script>
  12. import $http from '../../utils/request.js'
  13. export default {
  14. name: "auth",
  15. props: {
  16. authShow: {
  17. type: Boolean,
  18. default: true
  19. },
  20. authToken: {
  21. type: String,
  22. default: ''
  23. },
  24. authMobile: {
  25. type: String,
  26. default: ''
  27. }
  28. },
  29. data() {
  30. return {
  31. authIng: false
  32. };
  33. },
  34. methods: {
  35. getInfo() {
  36. let _this = this
  37. if (this.authIng) {
  38. return
  39. }
  40. _this.authIng = true
  41. uni.getUserProfile({
  42. desc: '用于填充用户默认信息',
  43. success(info) {
  44. uni.login({
  45. success(res) {
  46. $http.post('/api/v1/mp/user/wxauth', {
  47. ...{
  48. identity: 1,
  49. code: res.code
  50. },
  51. ...info.userInfo
  52. }).then(res => {
  53. _this.authIng = false
  54. if (res.code === 0) {
  55. uni.$u.toast('授权成功');
  56. _this.authIng = false
  57. _this.$emit('close')
  58. }
  59. }).catch(() => {
  60. _this.authIng = false
  61. })
  62. }
  63. })
  64. },
  65. fail() {
  66. _this.authIng = false
  67. }
  68. })
  69. },
  70. getBaseInfo() {
  71. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  72. if (res.code == 0) {
  73. uni.setStorageSync('userInfo', res.data)
  74. }
  75. })
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .auth-wrap {
  82. /* #ifndef MP-ALIPAY */
  83. padding: 32rpx 32rpx 50rpx;
  84. /* #endif */
  85. /* #ifdef MP-ALIPAY */
  86. padding: 32rpx 32rpx 0;
  87. /* #endif */
  88. /deep/ button {
  89. line-height: 76rpx;
  90. font-size: 28rpx;
  91. height: 76rpx;
  92. color: #fff;
  93. background-color: $uni-bg-color;
  94. border: none;
  95. border-radius: 100rpx;
  96. }
  97. }
  98. .tip {
  99. padding: 50rpx 16rpx;
  100. font-size: 26rpx;
  101. color: #333;
  102. }
  103. </style>