authorization.vue 4.0 KB

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