authorization.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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" 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. ...mapMutations(['wxLogin']),
  47. getUserProfile(){
  48. const self = this
  49. // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
  50. wx.getUserProfile({
  51. desc: '采美采购商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  52. success(res) {
  53. self.wxLogin(res.userInfo)
  54. uni.login({
  55. provider: 'weixin',
  56. scopes: 'auth_user',
  57. success(loginres) {
  58. console.log('新API',loginres)
  59. self.WxGetUserInfo()
  60. },
  61. fail(err) {
  62. self.$util.msg(err, 2000)
  63. }
  64. })
  65. },
  66. fail() {
  67. console.log('授权失败')
  68. self.$util.msg('授权失败', 2000)
  69. }
  70. })
  71. },
  72. Getuserinfo: function (e) {//微信授权(暂时弃用)
  73. if (e.detail.userInfo) {
  74. this.WxGetUserInfo()
  75. }else{
  76. this.$util.msg('授权失败',2000)
  77. }
  78. },
  79. undGetuserinfo(){
  80. this.hanldBackFn()
  81. },
  82. hanldNavigateBack(){
  83. this.hanldBackFn()
  84. },
  85. hanldBackFn(){
  86. switch(this.authorizeType){
  87. case '0':
  88. this.$api.switchTabTo('/pages/tabBar/home/index')
  89. break;
  90. default:
  91. uni.navigateBack({delta: 1})
  92. }
  93. },
  94. WxGetUserInfo(){
  95. let self = this
  96. wx.getUserInfo({
  97. success: res => {
  98. wxLogin.wxLoginAuthorize()
  99. switch(self.authorizeType){
  100. case '0':
  101. self.$api.switchTabTo('/pages/tabBar/home/index')
  102. break;
  103. case '1':
  104. self.$api.navigateTo('/pages/login/login')
  105. break;
  106. case '2':
  107. self.$api.navigateTo('/pages/login/register')
  108. break;
  109. case '3':
  110. self.$api.navigateTo('/pages/login/logincode')
  111. break;
  112. default:
  113. setTimeout(()=>{
  114. uni.navigateBack({delta: 1});
  115. },2000)
  116. }
  117. }
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. .login{
  125. width: 100%;
  126. height: auto;
  127. .model-warp.none{
  128. display: none;
  129. }
  130. .model-warp.show{
  131. display: block;
  132. }
  133. .login-main{
  134. width: 100%;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. height: auto;
  139. padding:200rpx 0 0 0;
  140. .logo{
  141. width: 200rpx;
  142. height: 170rpx;
  143. display: block;
  144. }
  145. .logo-text{
  146. font-size: $font-size-40;
  147. line-height: 40rpx;
  148. color:$color-system;
  149. margin-top: 40rpx;
  150. }
  151. }
  152. .login-content{
  153. width: 580rpx;
  154. margin: 95rpx auto;
  155. line-height: 40rpx;
  156. font-size: $font-size-24;
  157. color: #666666;
  158. text-align: justify;
  159. }
  160. .login-form{
  161. width: 702rpx;
  162. height: auto;
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. margin: 0 auto;
  167. .login-btn{
  168. width: 630rpx;
  169. height: 80rpx;
  170. border-radius: 40rpx;
  171. font-size: $font-size-32;
  172. line-height: 80rpx;
  173. color: #FFFFFF;
  174. text-align: center;
  175. background: linear-gradient(135deg,rgba(4,190,2,1) 0%,rgba(4,183,2,1) 100%);
  176. display: flex;
  177. flex-direction: column;
  178. align-items: center;
  179. &.back{
  180. height: 76rpx;
  181. background: #FFFFFF;
  182. border: 1px solid #08A267;
  183. color: #08A267;
  184. margin-top: 30rpx;
  185. }
  186. }
  187. }
  188. }
  189. </style>