index.vue 3.6 KB

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