authorization.vue 4.8 KB

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