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. if (e.detail.userInfo) {
  90. let userInfo = e.detail.userInfo;
  91. this.sendData(e.detail);
  92. } else {
  93. /* 用户点击了拒绝 */
  94. this.cancelBind();
  95. }
  96. },
  97. // 获取用户的当前设置
  98. getSetting() {
  99. return new Promise(function (resolve, reject) {
  100. uni.getSetting({
  101. success: function (res) {
  102. if (res.authSetting["scope.userInfo"]) {
  103. resolve(true);
  104. } else {
  105. resolve(false);
  106. }
  107. },
  108. });
  109. }).catch((e) => {
  110. });
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="scss">
  116. .authGuide_container {
  117. .cont_top {
  118. padding: 119rpx 0 100rpx;
  119. font-size: 28rpx;
  120. text-align: center;
  121. .top_info {
  122. margin: 0 auto;
  123. }
  124. .logo {
  125. width: 120rpx;
  126. height: 120rpx;
  127. margin: 0 auto;
  128. }
  129. .title {
  130. margin: 30rpx 0;
  131. font-size: 39rpx;
  132. color: #000;
  133. }
  134. .info_detail {
  135. color: #b2b2b2;
  136. }
  137. }
  138. .cont_bottom {
  139. padding-left: 34rpx;
  140. .auth_tips {
  141. color: #333;
  142. margin-bottom: 30rpx;
  143. }
  144. .info_detail {
  145. color: #b2b2b2;
  146. }
  147. }
  148. .btn_box {
  149. display: flex;
  150. margin-top: 80rpx;
  151. justify-content: center;
  152. align-items: center;
  153. .infobutton {
  154. width: 216rpx;
  155. height: 72rpx;
  156. text-align: center;
  157. line-height: 72rpx;
  158. color: #fff;
  159. font-size: 34rpx;
  160. background: #07c160;
  161. border-radius: 4rpx;
  162. display: block;
  163. margin: 0;
  164. border: none;
  165. }
  166. .infobutton2 {
  167. background: rgba(0, 0, 0, 0.05);
  168. margin-right: 28rpx;
  169. color: #07c160;
  170. }
  171. }
  172. }
  173. </style>