authGuide.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. this.$db.set('access_token',token);
  41. })
  42. }
  43. });
  44. }
  45. },
  46. fail: (err) => {
  47. uni.login({
  48. success: result=> {
  49. User.wechatLog({
  50. Code:result.code
  51. }).then(res => {
  52. let token = res.Data.Authorization;
  53. this.$db.set('access_token',token);
  54. })
  55. }
  56. });
  57. }
  58. })
  59. },
  60. methods: {
  61. /* 拒绝返回上一页面 */
  62. cancelBind() {
  63. uni.navigateBack({
  64. delta: 1
  65. })
  66. },
  67. /* 传输unid 加密数据 */
  68. sendData(data) {
  69. User.sendInfo({
  70. EncryptedData: data.encryptedData,
  71. Iv: data.iv,
  72. RawData: data.rawData,
  73. Signature: data.signature
  74. }).then(res => {
  75. if(res.Ret === 200) {
  76. //console.log(app.globalData)
  77. /* 判断是否绑定过 未绑定去绑定 绑定过返回上一页面 */
  78. app.globalData.isBind && uni.redirectTo({
  79. url:'/pages/login/login'
  80. })
  81. !app.globalData.isBind && uni.navigateBack({
  82. delta:1
  83. })
  84. }
  85. })
  86. },
  87. //微信授权登录
  88. getUserInfo(e){
  89. console.log(e)
  90. if(e.detail.userInfo) {
  91. let userInfo = e.detail.userInfo;
  92. this.sendData(e.detail);
  93. }else {
  94. /* 用户点击了拒绝 */
  95. this.cancelBind();
  96. }
  97. // let that = this;
  98. // var p = this.getSetting();
  99. // p.then(function(isAuth) {
  100. // console.log('是否已经授权', isAuth);
  101. // if (isAuth) {
  102. // console.log('用户信息', e);
  103. // let userInfo = e.detail.userInfo;
  104. // that.sendData(e.detail);
  105. // } else {
  106. // /* 用户点击了拒绝 */
  107. // that.cancelBind();
  108. // }
  109. // });
  110. },
  111. //获取用户的当前设置
  112. getSetting() {
  113. return new Promise(function(resolve, reject) {
  114. uni.getSetting({
  115. success: function(res) {
  116. if (res.authSetting['scope.userInfo']) {
  117. resolve(true);
  118. } else {
  119. resolve(false);
  120. }
  121. },
  122. })
  123. }).catch((e) => {
  124. // console.log(e)
  125. });;
  126. },
  127. }
  128. }
  129. </script>
  130. <style lang="scss">
  131. .authGuide_container {
  132. .cont_top {
  133. padding: 119rpx 0 100rpx;
  134. font-size: 28rpx;
  135. text-align: center;
  136. .top_info{
  137. margin: 0 auto;
  138. }
  139. .logo {
  140. width: 120rpx;
  141. height: 120rpx;
  142. margin: 0 auto;
  143. }
  144. .title {
  145. margin: 30rpx 0;
  146. font-size: 39rpx;
  147. color: #000;
  148. }
  149. .info_detail {
  150. color: #B2B2B2;
  151. }
  152. }
  153. .cont_bottom {
  154. padding-left: 34rpx;
  155. .auth_tips {
  156. color: #333;
  157. margin-bottom: 30rpx;
  158. }
  159. .info_detail {
  160. color: #B2B2B2;
  161. }
  162. }
  163. .btn_box {
  164. display: flex;
  165. margin-top: 80rpx;
  166. justify-content: center;
  167. align-items: center;
  168. .infobutton {
  169. width: 216rpx;
  170. height: 72rpx;
  171. text-align: center;
  172. line-height: 72rpx;
  173. color: #fff;
  174. font-size: 34rpx;
  175. background: #07C160;
  176. border-radius: 4rpx;
  177. display: block;
  178. margin: 0;
  179. border:none;
  180. }
  181. .infobutton2 {
  182. background: rgba(0, 0, 0, 0.05);
  183. margin-right: 28rpx;
  184. color: #07C160;
  185. }
  186. }
  187. }
  188. </style>