authGuide.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="authGuide_container container">
  3. <view class="cont_top">
  4. <view class="top_info">
  5. <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/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({allowDefault: true});
  24. export default {
  25. data() {
  26. return {};
  27. },
  28. onLoad() {
  29. /* 校验session */
  30. uni.checkSession({
  31. success: (res) => {
  32. if (res.errMsg != "checkSession:ok") {
  33. uni.login({
  34. success: (result) => {
  35. User.wechatLog({
  36. Code: result.code,
  37. }).then((res) => {
  38. let token = res.Data.Authorization;
  39. this.$db.set("access_token", token);
  40. });
  41. },
  42. });
  43. }
  44. },
  45. fail: (err) => {
  46. uni.login({
  47. success: (result) => {
  48. User.wechatLog({
  49. Code: result.code,
  50. }).then((res) => {
  51. let token = res.Data.Authorization;
  52. this.$db.set("access_token", token);
  53. });
  54. },
  55. });
  56. },
  57. });
  58. },
  59. methods: {
  60. /* 拒绝返回上一页面 */
  61. cancelBind() {
  62. uni.navigateBack({
  63. delta: 1,
  64. });
  65. },
  66. /* 传输unid 加密数据 */
  67. sendData(data) {
  68. User.sendInfo({
  69. EncryptedData: data.encryptedData,
  70. Iv: data.iv,
  71. RawData: data.rawData,
  72. Signature: data.signature,
  73. }).then((res) => {
  74. if (res.Ret === 200) {
  75. /* 判断是否绑定过 未绑定去绑定 绑定过返回上一页面 */
  76. this.$store.state.isBind &&
  77. uni.redirectTo({
  78. url: "/pageMy/login/login",
  79. });
  80. !this.$store.state.isBind &&
  81. 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. },
  98. //获取用户的当前设置
  99. getSetting() {
  100. return new Promise(function (resolve, reject) {
  101. uni.getSetting({
  102. success: function (res) {
  103. if (res.authSetting["scope.userInfo"]) {
  104. resolve(true);
  105. } else {
  106. resolve(false);
  107. }
  108. },
  109. });
  110. }).catch((e) => {
  111. // console.log(e)
  112. });
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="scss">
  118. .authGuide_container {
  119. .cont_top {
  120. padding: 119rpx 0 100rpx;
  121. font-size: 28rpx;
  122. text-align: center;
  123. .top_info {
  124. margin: 0 auto;
  125. }
  126. .logo {
  127. width: 120rpx;
  128. height: 120rpx;
  129. margin: 0 auto;
  130. }
  131. .title {
  132. margin: 30rpx 0;
  133. font-size: 39rpx;
  134. color: #000;
  135. }
  136. .info_detail {
  137. color: #b2b2b2;
  138. }
  139. }
  140. .cont_bottom {
  141. padding-left: 34rpx;
  142. .auth_tips {
  143. color: #333;
  144. margin-bottom: 30rpx;
  145. }
  146. .info_detail {
  147. color: #b2b2b2;
  148. }
  149. }
  150. .btn_box {
  151. display: flex;
  152. margin-top: 80rpx;
  153. justify-content: center;
  154. align-items: center;
  155. .infobutton {
  156. width: 216rpx;
  157. height: 72rpx;
  158. text-align: center;
  159. line-height: 72rpx;
  160. color: #fff;
  161. font-size: 34rpx;
  162. background: #07c160;
  163. border-radius: 4rpx;
  164. display: block;
  165. margin: 0;
  166. border: none;
  167. }
  168. .infobutton2 {
  169. background: rgba(0, 0, 0, 0.05);
  170. margin-right: 28rpx;
  171. color: #07c160;
  172. }
  173. }
  174. }
  175. </style>