authorization.vue 4.0 KB

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