authorization.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="container login" :style="{ paddingTop: CustomBar + 'px' }">
  3. <view class="login-main">
  4. <image class="logo" src="../../static/ws/logo.png" mode="widthFix"></image>
  5. </view>
  6. <view class="login-content">
  7. <text
  8. >您暂未授权采美采购小程序获取您的信息,将无法正常使用小程序的功能。如需正常使用,请点击“授权”按钮,并允许头像、昵称等信息的授权。</text
  9. >
  10. </view>
  11. <view class="login-form">
  12. <button
  13. class="login-btn use"
  14. type="primary"
  15. size="small"
  16. open-type="getUserInfo"
  17. lang="zh_CN"
  18. @getuserinfo="getuserinfo"
  19. >
  20. 微信授权
  21. </button>
  22. <view class="login-btn back" @tap="undGetuserinfo">取消</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { mapState, mapMutations } from 'vuex'
  28. import authorize from '@/common/config/authorize.js'
  29. import wxLogin from '@/common/config/wxLogin.js'
  30. export default {
  31. data() {
  32. return {
  33. nvabarData: {
  34. //顶部自定义导航
  35. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  36. showSearch: 0,
  37. title: '微信授权', // 导航栏 中间的标题
  38. haveBack: true,
  39. haveHome: false,
  40. textLeft: this.$store.state.isIphone
  41. },
  42. CustomBar: this.CustomBar, // 顶部导航栏高度
  43. authorizeType: ''
  44. }
  45. },
  46. onLoad(e) {
  47. this.authorizeType = e.type
  48. if (this.authorizeType == '4') {
  49. this.nvabarData.haveBack = false
  50. }
  51. },
  52. computed: {
  53. ...mapState(['hasLogin', 'userInfo'])
  54. },
  55. methods: {
  56. getuserinfo(e) {
  57. //微信授权
  58. if (e.detail.userInfo) {
  59. this.checkedUser()
  60. } else {
  61. this.$util.msg('授权失败', 2000)
  62. }
  63. },
  64. undGetuserinfo() {
  65. uni.navigateBack({ delta: 1 })
  66. },
  67. // 用户验证
  68. async checkedUser() {
  69. const wechatCode = await authorize.getCode('weixin')
  70. // 用户是否填写了邀请码
  71. const res = await this.UserService.userInfoLogin({ code: wechatCode }).catch((error)=>{
  72. console.log('登录失败')
  73. uni.reLaunch({
  74. url: '/pages/index/index'
  75. })
  76. })
  77. if (res.code !== 0) {
  78. return uni.showToast({
  79. title: '账号未注册',
  80. success() {
  81. uni.reLaunch({
  82. url: '/pages/login/login'
  83. })
  84. }
  85. })
  86. }
  87. console.log('授权登录成功')
  88. uni.reLaunch({
  89. url: '/pages/index/index'
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. .login {
  97. width: 100%;
  98. height: auto;
  99. .model-warp.none {
  100. display: none;
  101. }
  102. .model-warp.show {
  103. display: block;
  104. }
  105. .login-main {
  106. width: 100%;
  107. display: flex;
  108. flex-direction: column;
  109. align-items: center;
  110. height: auto;
  111. padding: 80rpx 0 0 0;
  112. .logo {
  113. width: 152rpx;
  114. height: 152rpx;
  115. display: block;
  116. border-radius: 50%;
  117. }
  118. .logo-text {
  119. font-size: $font-size-40;
  120. line-height: 40rpx;
  121. color: $color-system;
  122. margin-top: 40rpx;
  123. }
  124. }
  125. .login-content {
  126. width: 580rpx;
  127. margin: 70rpx auto;
  128. line-height: 48rpx;
  129. font-size: 26rpx;
  130. color: #666666;
  131. text-align: justify;
  132. }
  133. .login-form {
  134. width: 702rpx;
  135. height: auto;
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. margin: 0 auto;
  140. .login-btn {
  141. width: 600rpx;
  142. height: 90rpx;
  143. border-radius: 45rpx;
  144. font-size: $font-size-32;
  145. line-height: 80rpx;
  146. color: #ffffff;
  147. text-align: center;
  148. background: linear-gradient(135deg, rgba(4, 190, 2, 1) 0%, rgba(4, 183, 2, 1) 100%);
  149. display: flex;
  150. flex-direction: column;
  151. align-items: center;
  152. &.back {
  153. height: 76rpx;
  154. background: #ffffff;
  155. border: 1px solid #666;
  156. color: #666;
  157. margin-top: 30rpx;
  158. }
  159. }
  160. }
  161. }
  162. </style>