index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. uid: "",
  35. userInfo: {}
  36. };
  37. },
  38. onLoad(options) {
  39. this.shopId = options.shopId;
  40. this.uid = options.uid || '';
  41. let alipayuserinfo = localStorage.getItem("aliPayUserInfo")
  42. let wechatuserinfo = localStorage.getItem("weChatUserInfo")
  43. this.radiovalue = 1
  44. if (alipayuserinfo) {
  45. this.zfbLink()
  46. } else if (wechatuserinfo) {
  47. this.wxLink()
  48. }
  49. },
  50. methods: {
  51. login() {
  52. var userAgent = window.navigator.userAgent.toUpperCase();
  53. console.log(this.radiovalue);
  54. if (this.radiovalue == 1) {
  55. if (userAgent.indexOf('MICROMESSENGER') > 0) {
  56. this.wxLink()
  57. }
  58. if (userAgent.indexOf('ALIPAYCLIENT') > 0) {
  59. this.zfbLink()
  60. }
  61. } else {
  62. uni.$u.toast('请先同意用户授权!');
  63. }
  64. },
  65. zfbLink() {
  66. let url =
  67. `${requestConfig.zfb_request_url}?app_id=${requestConfig.zfb_appid}
  68. &scope=${requestConfig.zfb_scope}
  69. &redirect_uri=${encodeURIComponent(requestConfig.zfb_redirect_uri)}
  70. &state=STATE
  71. &shopId=${this.shopId}
  72. ${this.uid?'&uid='+this.uid:''}
  73. &type=zfb`
  74. console.log(url);
  75. window.location = url;
  76. },
  77. wxLink() {
  78. /*微信授权登录*/
  79. let redirect_uri = encodeURIComponent(requestConfig.wx_redirect_uri + '?shopId=' + this.shopId + '&uid=' +
  80. this.uid)
  81. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?
  82. appid=${requestConfig.wx_appid}
  83. &redirect_uri=${redirect_uri}
  84. &response_type=code
  85. &scope=snsapi_userinfo
  86. &state=STATE
  87. #wechat_redirect`;
  88. window.location = url;
  89. },
  90. },
  91. };
  92. </script>
  93. <style scoped lang="scss">
  94. .u-radio-group--row {
  95. justify-content: center;
  96. }
  97. .radioText {
  98. font-weight: 500;
  99. font-size: 24rpx;
  100. color: #999999;
  101. line-height: 34rpx;
  102. text-align: left;
  103. font-style: normal;
  104. }
  105. .login-main {
  106. background: url("../../static/images/back.png") no-repeat;
  107. background-size: 100% 100%;
  108. width: 100%;
  109. display: flex;
  110. flex-direction: column;
  111. justify-content: space-between;
  112. align-items: center;
  113. height: 100vh;
  114. }
  115. .login-contont-button {
  116. .btn {
  117. margin-top: 20px;
  118. width: 90%;
  119. height: 90rpx;
  120. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  121. border-radius: 44rpx;
  122. color: #fff;
  123. }
  124. }
  125. .login-contont {
  126. width: 100%;
  127. height: 50%;
  128. .login-contont-info {
  129. text-align: center;
  130. .text {
  131. margin-top: 10px;
  132. font-weight: 500;
  133. font-size: 28rpx;
  134. color: #999999;
  135. line-height: 40rpx;
  136. font-style: normal;
  137. }
  138. }
  139. }
  140. .radio {
  141. text-align: center;
  142. margin-top: 10px;
  143. }
  144. .login-main-content {
  145. text-align: center;
  146. padding-top: 100px;
  147. width: 100%;
  148. height: 50%;
  149. .img {
  150. width: 100px;
  151. height: 130px;
  152. }
  153. }
  154. </style>