authorization.vue 3.4 KB

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