authorization.vue 4.6 KB

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