authGuide.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="authGuide_container container">
  3. <view class="cont_top">
  4. <view class="top_info">
  5. <image src="@/static/img/logo.png" class="logo"></image>
  6. <text class="title">查研观向</text>
  7. <text class="info_detail">弘则弥道(上海)投资咨询有限公司</text>
  8. </view>
  9. </view>
  10. <view class="cont_bottom">
  11. <text class="auth_tips">该程序将获取以下授权:</text>
  12. <text class="info_detail">·获得您的公开信息(昵称、头像等)</text>
  13. </view>
  14. <!-- 授权按钮 -->
  15. <view class="btn_box">
  16. <button @click="cancelBind" class='infobutton infobutton2'>拒绝</button>
  17. <button open-type="getUserInfo" value="用户授权" @getuserinfo="getUserInfo" class='infobutton'>允许</button>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { User } from '@/config/api.js'
  23. let app = getApp();
  24. export default {
  25. data() {
  26. return {
  27. };
  28. },
  29. onLoad() {
  30. /* 校验session */
  31. uni.checkSession({
  32. success: res => {
  33. if(res.errMsg != 'checkSession:ok') {
  34. uni.login({
  35. success: result=> {
  36. User.wechatLog({
  37. Code:result.code
  38. }).then(res => {
  39. let token = res.Data.Authorization;
  40. set('access_token',token);
  41. })
  42. }
  43. });
  44. }
  45. }
  46. })
  47. },
  48. methods: {
  49. /* 拒绝返回上一页面 */
  50. cancelBind() {
  51. uni.navigateBack({
  52. delta: 1
  53. })
  54. },
  55. /* 传输unid 加密数据 */
  56. sendData(data) {
  57. User.sendInfo({
  58. EncryptedData: data.encryptedData,
  59. Iv: data.iv,
  60. RawData: data.rawData,
  61. Signature: data.signature
  62. }).then(res => {
  63. if(res.Ret === 200) {
  64. console.log(app.globalData)
  65. /* 判断是否绑定过 未绑定去绑定 绑定过返回上一页面 */
  66. app.globalData.isBind && uni.redirectTo({
  67. url:'/pages/login/login'
  68. })
  69. !app.globalData.isBind && uni.navigateBack({
  70. delta:1
  71. })
  72. }
  73. })
  74. },
  75. //微信授权登录
  76. getUserInfo(e){
  77. let that = this;
  78. var p = this.getSetting();
  79. p.then(function(isAuth) {
  80. // console.log('是否已经授权', isAuth);
  81. if (isAuth) {
  82. console.log('用户信息', e);
  83. let userInfo = e.detail.userInfo;
  84. that.sendData(e.detail);
  85. } else {
  86. /* 用户点击了拒绝 */
  87. that.cancelBind();
  88. }
  89. });
  90. },
  91. //获取用户的当前设置
  92. getSetting() {
  93. return new Promise(function(resolve, reject) {
  94. uni.getSetting({
  95. success: function(res) {
  96. if (res.authSetting['scope.userInfo']) {
  97. resolve(true);
  98. } else {
  99. resolve(false);
  100. }
  101. },
  102. })
  103. }).catch((e) => {
  104. // console.log(e)
  105. });;
  106. },
  107. }
  108. }
  109. </script>
  110. <style lang="scss">
  111. .authGuide_container {
  112. .cont_top {
  113. padding: 119rpx 0 100rpx;
  114. font-size: 28rpx;
  115. text-align: center;
  116. .top_info{
  117. margin: 0 auto;
  118. }
  119. .logo {
  120. width: 120rpx;
  121. height: 120rpx;
  122. margin: 0 auto;
  123. }
  124. .title {
  125. margin: 30rpx 0;
  126. font-size: 39rpx;
  127. color: #000;
  128. }
  129. .info_detail {
  130. color: #B2B2B2;
  131. }
  132. }
  133. .cont_bottom {
  134. padding-left: 34rpx;
  135. .auth_tips {
  136. color: #333;
  137. margin-bottom: 30rpx;
  138. }
  139. .info_detail {
  140. color: #B2B2B2;
  141. }
  142. }
  143. .btn_box {
  144. display: flex;
  145. margin-top: 80rpx;
  146. justify-content: center;
  147. align-items: center;
  148. .infobutton {
  149. width: 216rpx;
  150. height: 72rpx;
  151. text-align: center;
  152. line-height: 72rpx;
  153. color: #fff;
  154. font-size: 34rpx;
  155. background: #07C160;
  156. border-radius: 4rpx;
  157. display: block;
  158. margin: 0;
  159. border:none;
  160. }
  161. .infobutton2 {
  162. background: rgba(0, 0, 0, 0.05);
  163. margin-right: 28rpx;
  164. color: #07C160;
  165. }
  166. }
  167. }
  168. </style>