authorize.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="container login" :style="{ paddingTop: CustomBar + 'px' }">
  3. <view class="login-main">
  4. <image class="logo" :src="StaticUrl+'icon-logo@2x.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 class="login-btn use"
  13. type="primary"
  14. open-type="getUserInfo"
  15. size="small"
  16. @click="getUserProfile"
  17. lang="zh_CN">
  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. StaticUrl:this.$Static,
  32. nvabarData: {
  33. //顶部自定义导航
  34. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  35. showSearch: 0,
  36. title: '微信授权', // 导航栏 中间的标题
  37. haveBack: true,
  38. haveHome: false,
  39. textLeft: this.$store.state.isIphone
  40. },
  41. CustomBar: this.CustomBar, // 顶部导航栏高度
  42. authorizeType: ''
  43. }
  44. },
  45. onLoad(e) {
  46. this.authorizeType = e.type
  47. if (this.authorizeType == '4') {
  48. this.nvabarData.haveBack = false
  49. }
  50. },
  51. computed: {
  52. ...mapState(['hasLogin', 'userInfo'])
  53. },
  54. methods: {
  55. ...mapMutations(['wxLogin']),
  56. getUserProfile(){
  57. const self = this
  58. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
  59. wx.getUserProfile({
  60. desc: '采美采购商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  61. success(res) {
  62. console.log('新API',res)
  63. self.wxLogin(res.userInfo)
  64. uni.login({
  65. provider: 'weixin',
  66. scopes: 'auth_user',
  67. success(res) {
  68. self.WxGetUserInfo()
  69. },
  70. fail(err) {
  71. self.$util.msg(err, 2000)
  72. }
  73. })
  74. },
  75. fail() {
  76. self.$util.msg('授权失败', 2000)
  77. }
  78. })
  79. },
  80. Getuserinfo: function (e) {//微信授权(暂时弃用)
  81. if (e.detail.userInfo) {
  82. this.WxGetUserInfo()
  83. }else{
  84. this.$util.msg('授权失败',2000)
  85. }
  86. },
  87. undGetuserinfo(){
  88. this.hanldBackFn()
  89. },
  90. hanldNavigateBack(){
  91. this.hanldBackFn()
  92. },
  93. hanldBackFn(){
  94. switch(this.authorizeType){
  95. case '0':
  96. this.$api.switchTabTo('/pages/tabBar/home/index')
  97. break;
  98. default:
  99. uni.navigateBack({delta: 1})
  100. }
  101. },
  102. WxGetUserInfo(){
  103. let self = this
  104. wx.getUserInfo({
  105. success: res => {
  106. wxLogin.wxLoginAuthorize()
  107. switch(self.authorizeType){
  108. case '0':
  109. self.$api.switchTabTo('/pages/tabBar/home/index')
  110. break;
  111. case '1':
  112. self.$api.navigateTo('/pages/login/login')
  113. break;
  114. case '2':
  115. self.$api.navigateTo('/pages/login/register')
  116. break;
  117. case '3':
  118. self.$api.navigateTo('/pages/login/logincode')
  119. break;
  120. default:
  121. setTimeout(()=>{
  122. uni.navigateBack({delta: 1});
  123. },2000)
  124. }
  125. }
  126. })
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. .login {
  133. width: 100%;
  134. height: auto;
  135. .model-warp.none {
  136. display: none;
  137. }
  138. .model-warp.show {
  139. display: block;
  140. }
  141. .login-main {
  142. width: 100%;
  143. display: flex;
  144. flex-direction: column;
  145. align-items: center;
  146. height: auto;
  147. padding: 80rpx 0 0 0;
  148. .logo {
  149. width: 200rpx;
  150. height: 200rpx;
  151. display: block;
  152. }
  153. .logo-text {
  154. font-size: $font-size-40;
  155. line-height: 40rpx;
  156. color: $color-system;
  157. margin-top: 40rpx;
  158. }
  159. }
  160. .login-content {
  161. width: 580rpx;
  162. margin: 70rpx auto;
  163. line-height: 48rpx;
  164. font-size: 26rpx;
  165. color: #666666;
  166. text-align: justify;
  167. }
  168. .login-form {
  169. width: 702rpx;
  170. height: auto;
  171. display: flex;
  172. flex-direction: column;
  173. align-items: center;
  174. margin: 0 auto;
  175. .login-btn {
  176. width: 550rpx;
  177. height: 90rpx;
  178. border-radius: 45rpx;
  179. font-size: $font-size-32;
  180. line-height: 80rpx;
  181. color: #ffffff;
  182. text-align: center;
  183. background: linear-gradient(135deg, rgba(4, 190, 2, 1) 0%, rgba(4, 183, 2, 1) 100%);
  184. display: flex;
  185. flex-direction: column;
  186. align-items: center;
  187. &.back {
  188. height: 80rpx;
  189. background: #e1e1e1;
  190. border: 1px solid #FFFFFF;
  191. color: #FFFFFF;
  192. margin-top: 30rpx;
  193. }
  194. }
  195. }
  196. }
  197. </style>