index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="login-main">
  3. <!-- Logo区域 -->
  4. <view class="logo-wrap">
  5. <image class="logo-img" src="../../static/images/logo.png" mode="aspectFit"></image>
  6. <text class="logo-title">天枢云</text>
  7. </view>
  8. <view>
  9. <!-- 授权说明区域 -->
  10. <view class="auth-info-wrap">
  11. <text class="auth-title">请确认以下信息并授权登录</text>
  12. <text class="auth-desc">获取您的信息(你的头像、信息等)</text>
  13. </view>
  14. <!-- 按钮区域 -->
  15. <view class="btn-wrap">
  16. <button class="auth-btn" @click="login">授权登录</button>
  17. </view>
  18. <!-- 协议单选框 -->
  19. <view class="agreement-wrap">
  20. <u-radio-group v-model="radiovalue">
  21. <u-radio value="1" size="30" name="1" iconSize="25" activeColor="#409EFF">
  22. <text class="agreement-text">授权同意《用户服务协议》和《隐私协议》</text>
  23. </u-radio>
  24. </u-radio-group>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import ap from "../../static/zfb.js"
  31. import {
  32. requestConfig
  33. } from "@/app.config.js";
  34. export default {
  35. data() {
  36. return {
  37. ap: ap,
  38. // 默认勾选协议,匹配参考图
  39. radiovalue: 1,
  40. shopId: "",
  41. uid: "",
  42. userInfo: {}
  43. };
  44. },
  45. onLoad(options) {
  46. this.shopId = options.shopId;
  47. this.uid = options.uid || '';
  48. let alipayuserinfo = localStorage.getItem("aliPayUserInfo")
  49. let wechatuserinfo = localStorage.getItem("weChatUserInfo")
  50. if (alipayuserinfo) {
  51. this.zfbLink()
  52. } else if (wechatuserinfo) {
  53. this.wxLink()
  54. }
  55. },
  56. methods: {
  57. login() {
  58. console.log(this.radiovalue);
  59. var userAgent = window.navigator.userAgent.toUpperCase();
  60. if (this.radiovalue == 1) {
  61. if (userAgent.indexOf('MICROMESSENGER') > 0) {
  62. this.wxLink()
  63. }
  64. if (userAgent.indexOf('ALIPAYCLIENT') > 0) {
  65. this.zfbLink()
  66. }
  67. } else {
  68. uni.$u.toast('请先同意用户授权!');
  69. }
  70. },
  71. zfbLink() {
  72. let url =
  73. `${requestConfig.zfb_request_url}?app_id=${requestConfig.zfb_appid}
  74. &scope=${requestConfig.zfb_scope}
  75. &redirect_uri=${encodeURIComponent(requestConfig.zfb_redirect_uri)}
  76. &state=STATE
  77. &shopId=${this.shopId}
  78. ${this.uid ? '&uid=' + this.uid : ''}
  79. &type=zfb`
  80. console.log(url);
  81. window.location = url;
  82. },
  83. wxLink() {
  84. /*微信授权登录*/
  85. let redirect_uri = encodeURIComponent(requestConfig.wx_redirect_uri + '?shopId=' + this.shopId + '&uid=' +
  86. this.uid)
  87. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?
  88. appid=${requestConfig.wx_appid}
  89. &redirect_uri=${redirect_uri}
  90. &response_type=code
  91. &scope=snsapi_userinfo
  92. &state=STATE
  93. #wechat_redirect`;
  94. window.location = url;
  95. },
  96. },
  97. };
  98. </script>
  99. <style scoped lang="scss">
  100. /* 全局页面容器 */
  101. .login-main {
  102. width: 100%;
  103. min-height: 100vh;
  104. background-color: #ffffff;
  105. display: flex;
  106. flex-direction: column;
  107. align-items: center;
  108. padding: 0 40rpx;
  109. box-sizing: border-box;
  110. justify-content: space-around;
  111. }
  112. /* Logo区域 */
  113. .logo-wrap {
  114. margin-top: 180rpx;
  115. display: flex;
  116. flex-direction: column;
  117. align-items: center;
  118. margin-bottom: 160rpx;
  119. .logo-img {
  120. width: 160rpx;
  121. height: 160rpx;
  122. margin-bottom: 30rpx;
  123. }
  124. .logo-title {
  125. font-size: 48rpx;
  126. font-weight: 500;
  127. color: #333333;
  128. line-height: 64rpx;
  129. }
  130. }
  131. /* 授权说明区域 */
  132. .auth-info-wrap {
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. margin-bottom: 60rpx;
  137. .auth-title {
  138. font-size: 32rpx;
  139. font-weight: 500;
  140. color: #333333;
  141. line-height: 44rpx;
  142. margin-bottom: 16rpx;
  143. }
  144. .auth-desc {
  145. font-size: 28rpx;
  146. color: #999999;
  147. line-height: 40rpx;
  148. }
  149. }
  150. /* 按钮区域 */
  151. .btn-wrap {
  152. width: 100%;
  153. margin-bottom: 40rpx;
  154. .auth-btn {
  155. width: 100%;
  156. height: 90rpx;
  157. line-height: 90rpx;
  158. background: linear-gradient(90deg, #66B1FF 0%, #1677FF 100%);
  159. border-radius: 45rpx;
  160. border: none;
  161. color: #ffffff;
  162. font-size: 32rpx;
  163. font-weight: 500;
  164. padding: 0;
  165. }
  166. }
  167. /* 协议区域 */
  168. .agreement-wrap {
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. .agreement-text {
  173. font-size: 28rpx;
  174. color: #999999;
  175. line-height: 40rpx;
  176. }
  177. }
  178. /* 单选框样式适配 */
  179. .u-radio-group--row {
  180. justify-content: center;
  181. }
  182. </style>