index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="login-main">
  3. <view class="login-main-content">
  4. <image class="img" src="../../static/images/logo.png" mode=""></image>
  5. </view>
  6. <view class="login-contont">
  7. <view class="login-contont-info">
  8. <h5>请确认以下信息并授权登录</h5>
  9. <view class="text">获取您的信息(你的头像、信息等)</view>
  10. </view>
  11. <view class="login-contont-button">
  12. <button class="btn" @click="login">授权登录</button>
  13. </view>
  14. <view class="radio">
  15. <u-radio-group v-model="radiovalue">
  16. <u-radio value="1" size="30" name="1" iconSize="25">
  17. <text class="radioText">授权同意《用户服务协议》 和《隐私协议》</text></u-radio>
  18. </u-radio-group>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import ap from "../../static/zfb.js"
  25. import {
  26. requestConfig
  27. } from "@/app.config.js";
  28. export default {
  29. data() {
  30. return {
  31. ap: ap,
  32. radiovalue: 0,
  33. shopId: "",
  34. userInfo: {}
  35. };
  36. },
  37. onLoad(options) {
  38. this.shopId = options.shopId;
  39. let userInfo = localStorage.getItem('userInfo');
  40. this.userInfo = JSON.parse(userInfo)
  41. if (this.userInfo) {
  42. this.radiovalue = 1
  43. this.login()
  44. }
  45. },
  46. methods: {
  47. login() {
  48. var userAgent = window.navigator.userAgent.toUpperCase();
  49. console.log(this.radiovalue);
  50. if (this.radiovalue == 1) {
  51. if (userAgent.indexOf('MICROMESSENGER') > 0) {
  52. this.wxLink()
  53. }
  54. if (userAgent.indexOf('ALIPAYCLIENT') > 0) {
  55. this.zfbLink()
  56. }
  57. } else {
  58. uni.$u.toast('请先同意用户授权!');
  59. }
  60. },
  61. zfbLink() {
  62. let url =
  63. `${requestConfig.zfb_request_url}?app_id=${requestConfig.zfb_appid}
  64. &scope=${requestConfig.zfb_scope}
  65. &redirect_uri=${encodeURIComponent(requestConfig.zfb_redirect_uri)}
  66. &state=STATE
  67. &shopId=${this.shopId}
  68. &type=zfb`
  69. window.location = url;
  70. },
  71. wxLink() {
  72. /*微信授权登录*/
  73. let redirect_uri = encodeURIComponent(requestConfig.wx_redirect_uri + '?shopId=' + this.shopId)
  74. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?
  75. appid=${requestConfig.wx_appid}
  76. &redirect_uri=${redirect_uri}
  77. &response_type=code
  78. &scope=snsapi_userinfo
  79. &state=STATE
  80. #wechat_redirect`;
  81. window.location = url;
  82. },
  83. },
  84. };
  85. </script>
  86. <style scoped lang="scss">
  87. .u-radio-group--row {
  88. justify-content: center;
  89. }
  90. .radioText {
  91. font-weight: 500;
  92. font-size: 24rpx;
  93. color: #999999;
  94. line-height: 34rpx;
  95. text-align: left;
  96. font-style: normal;
  97. }
  98. .login-main {
  99. background: url("../../static/images/back.png") no-repeat;
  100. background-size: 100% 100%;
  101. width: 100%;
  102. display: flex;
  103. flex-direction: column;
  104. justify-content: space-between;
  105. align-items: center;
  106. height: 100vh;
  107. }
  108. .login-contont-button {
  109. .btn {
  110. margin-top: 20px;
  111. width: 90%;
  112. height: 90rpx;
  113. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  114. border-radius: 44rpx;
  115. color: #fff;
  116. }
  117. }
  118. .login-contont {
  119. width: 100%;
  120. height: 50%;
  121. .login-contont-info {
  122. text-align: center;
  123. .text {
  124. margin-top: 10px;
  125. font-weight: 500;
  126. font-size: 28rpx;
  127. color: #999999;
  128. line-height: 40rpx;
  129. font-style: normal;
  130. }
  131. }
  132. }
  133. .radio {
  134. text-align: center;
  135. margin-top: 10px;
  136. }
  137. .login-main-content {
  138. text-align: center;
  139. padding-top: 100px;
  140. width: 100%;
  141. height: 50%;
  142. .img {
  143. width: 100px;
  144. height: 130px;
  145. }
  146. }
  147. </style>