index.vue 3.5 KB

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