authorization.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. // 缓存游客openid
  79. uni.setStorageSync('openid', error.data.openid)
  80. uni.reLaunch({
  81. url: '/pages/login/login'
  82. })
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss">
  89. .login {
  90. width: 100%;
  91. height: auto;
  92. .model-warp.none {
  93. display: none;
  94. }
  95. .model-warp.show {
  96. display: block;
  97. }
  98. .login-main {
  99. width: 100%;
  100. display: flex;
  101. flex-direction: column;
  102. align-items: center;
  103. height: auto;
  104. padding: 80rpx 0 0 0;
  105. .logo {
  106. width: 152rpx;
  107. height: 152rpx;
  108. display: block;
  109. border-radius: 50%;
  110. }
  111. .logo-text {
  112. font-size: $font-size-40;
  113. line-height: 40rpx;
  114. color: $color-system;
  115. margin-top: 40rpx;
  116. }
  117. }
  118. .login-content {
  119. width: 580rpx;
  120. margin: 70rpx auto;
  121. line-height: 48rpx;
  122. font-size: 26rpx;
  123. color: #666666;
  124. text-align: justify;
  125. }
  126. .login-form {
  127. width: 702rpx;
  128. height: auto;
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. margin: 0 auto;
  133. .login-btn {
  134. width: 600rpx;
  135. height: 90rpx;
  136. border-radius: 45rpx;
  137. font-size: $font-size-32;
  138. line-height: 80rpx;
  139. color: #ffffff;
  140. text-align: center;
  141. background: linear-gradient(135deg, rgba(4, 190, 2, 1) 0%, rgba(4, 183, 2, 1) 100%);
  142. display: flex;
  143. flex-direction: column;
  144. align-items: center;
  145. &.back {
  146. height: 76rpx;
  147. background: #ffffff;
  148. border: 1px solid #666;
  149. color: #666;
  150. margin-top: 30rpx;
  151. }
  152. }
  153. }
  154. }
  155. </style>