authorization.vue 4.8 KB

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