球星卡微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
5.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <view class="lf-row-center lf-flex-column box">
  4. <!-- <image class="img" :src="userInfo.avatar" v-if="userInfo.avatar"></image> -->
  5. <!-- <image class="img" src="../../static/logo.png" v-else></image> -->
  6. <image class="img" src="@/static/mrtx.png" ></image>
  7. <view class="lf-m-t-30 lf-font-32" v-if="type == 'phone'">{{ userInfo.nickname || '游客用户' }}</view>
  8. <block v-if="type == 'userinfo'">
  9. <button class="btn" @click="getUserProfile">
  10. <text class="le lf-icon-weixin lf-font-60 lf-text-vertical"></text>
  11. <text class="lf-m-l-20">微信快捷登录</text>
  12. </button>
  13. <!-- <view class="lf-m-t-40 lf-font-28" @click="$toBack()">暂不绑定继续操作</view> -->
  14. <view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
  15. </block>
  16. <block v-else-if="type == 'phone'">
  17. <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  18. <text class="le lf-icon-weixin lf-font-60 lf-text-vertical"></text>
  19. <text class="lf-m-l-20">绑定手机号</text>
  20. </button>
  21. <!-- <view class="lf-m-t-40 lf-font-28" @click="$url('/pages/login/accountLogin')">使用手机号登录</view> -->
  22. <view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
  23. </block>
  24. </view>
  25. <!-- 服务条款 -->
  26. <view class="fixed-bottom lf-flex">
  27. <checkbox-group @change="checkboxChange" style="display: inline-block;">
  28. <checkbox class="lf-text-vertical" :checked="checked" value="agreement"></checkbox>
  29. </checkbox-group>
  30. <view class="lf-m-l-10 lf-font-24 lf-color-gray" style="display: inline-block; width: 612rpx; white-space: pre-wrap;">
  31. <text>请仔细阅读</text>
  32. <text @click="$url('/packages/article/article?type=privacy_agreement')" class="text-orange">用户隐私协议</text>
  33. <text>开始使用代表您已阅读并同意</text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { wxLogin } from '@/service/login.js'
  40. export default {
  41. data(){
  42. return {
  43. checked: false, // 是否勾选协议
  44. isLogin: false, // 是否已登录
  45. userInfo: {},
  46. type: 'userinfo', // 页面授权类型 phone获取手机号 | userinfo获取用户信息
  47. agreement: {}, // 协议
  48. code: ''
  49. }
  50. },
  51. onLoad(options){
  52. uni.login({
  53. complete: result => {
  54. if(result.errMsg == 'login:ok'){
  55. let code = result.code;
  56. this.code = code;
  57. }
  58. }
  59. })
  60. },
  61. methods: {
  62. // 勾选协议发生变化
  63. checkboxChange(event){
  64. console.log(event);
  65. this.checked = event.detail.value.length > 0;
  66. },
  67. // 微信快捷登录获取手机号
  68. getPhoneNumber(event){
  69. console.log(event);
  70. if(event.detail.errMsg == 'getPhoneNumber:ok'){
  71. let encryptedData = event.detail.encryptedData;
  72. let iv = event.detail.iv;
  73. // let userInfo = uni.getStorageSync('userInfo') || {};
  74. this.$http(this.API.API_WECHAT_SETPHONE, {
  75. encryptedData,
  76. iv,
  77. // token: userInfo.token // 已在公共参数传
  78. }).then(res => {
  79. console.log("更新手机号", res);
  80. this.$msg('更新成功', {icon: 'success'});
  81. uni.setStorageSync('userInfo', res.data);
  82. setTimeout(() => {
  83. this.$toBack();
  84. }, 1000);
  85. })
  86. }
  87. },
  88. // 获取用户信息
  89. getUserProfile(){
  90. uni.getUserProfile({
  91. desc: '您的信息将用于球星卡显示',
  92. lang: 'zh_CN',
  93. complete: async result => {
  94. console.log(result)
  95. if(result.errMsg == 'getUserProfile:ok'){
  96. let encryptedData = result.encryptedData;
  97. let iv = result.iv;
  98. let signature = result.signature;
  99. let res = await wxLogin({
  100. code: this.code,
  101. iv: iv,
  102. encryptedData: encryptedData
  103. });
  104. let user = {...res.data.datas.user, token: res.data.datas.token};
  105. uni.setStorageSync('userInfo', user);
  106. this.$msg('登录成功, 即将跳转...').then(() => {
  107. let loginRedirectPage = getApp().globalData.loginRedirectPage;
  108. if(loginRedirectPage){
  109. this.$url(loginRedirectPage, {type: 'redirect'});
  110. }else{
  111. this.$url('/pages/index/index', {type: 'launch'});
  112. }
  113. })
  114. }
  115. }
  116. });
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. page{
  123. overflow: hidden;
  124. }
  125. </style>
  126. <style lang="scss" scoped="scoped">
  127. .box{
  128. padding: 60rpx 32rpx;
  129. width: 750rpx;
  130. height: auto;
  131. box-sizing: border-box;
  132. position: relative;
  133. .img{
  134. width: 180rpx;
  135. height: 180rpx;
  136. border-radius: 50%;
  137. }
  138. .btn{
  139. background-color: #09BB07;
  140. color: #FFFFFF;
  141. width: 100%;
  142. height: 88rpx;
  143. border-radius: 42rpx;
  144. font-size: 32rpx;
  145. line-height: 88rpx;
  146. margin-top: 80rpx;
  147. }
  148. }
  149. .fixed-bottom{
  150. position: fixed;
  151. bottom: 60rpx;
  152. left: 0;
  153. padding: 0 32rpx;
  154. .highlight{
  155. color: #1e90ff;
  156. }
  157. }
  158. .mask{
  159. position: absolute;
  160. bottom: 46rpx;
  161. left: 0;
  162. width: 100%;
  163. height: 190rpx;
  164. }
  165. .display-inline-block{
  166. display: inline-block;
  167. }
  168. .text-orange{
  169. color: rgb(209, 161, 28);
  170. font-size: 28rpx;
  171. }
  172. </style>