时空网前端
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.

162 lines
4.6 KiB

5 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/logo.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. <u-icon name="weixin-fill" color="#ffffff" size="60" class="lf-text-vertical"></u-icon>
  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. <u-icon name="weixin-fill" color="#ffffff" size="60" class="lf-text-vertical"></u-icon>
  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">
  27. <checkbox-group @change="checkboxChange" style="display: inline-block;">
  28. <checkbox class="lf-text-vertical" :checked="checked"></checkbox>
  29. </checkbox-group>
  30. <text class="lf-m-l-10 lf-font-24 lf-color-gray">
  31. <text>请认真阅读并同意</text>
  32. <text class="highlight" @click="enterAgree">时空网协议</text>
  33. <text>在小程序下单购买即表示您已默认同意</text>
  34. <text class="highlight" @click="enterAgree">时空网协议</text>
  35. <text>的所有条款</text>
  36. </text>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data(){
  43. return {
  44. checked: false, // 是否勾选协议
  45. isLogin: false, // 是否已登录
  46. userInfo: {},
  47. type: 'userinfo', // 页面授权类型 phone获取手机号 | userinfo获取用户信息
  48. }
  49. },
  50. onLoad(options){
  51. this.type = options.type || this.type;
  52. getApp().globalData.wxlogin().then(res => {
  53. this.userInfo = res;
  54. });
  55. },
  56. methods: {
  57. // 进入查看协议
  58. enterAgree(){
  59. console.log("查看协议");
  60. this.$url('/pages/agreement/agreement');
  61. },
  62. // 勾选协议发生变化
  63. checkboxChange(event){
  64. this.checked = event.detail.value.length > 0;
  65. },
  66. // 微信快捷登录获取手机号
  67. getPhoneNumber(event){
  68. console.log(event);
  69. if(event.detail.errMsg == 'getPhoneNumber:ok'){
  70. let encryptedData = event.detail.encryptedData;
  71. let iv = event.detail.iv;
  72. let userInfo = uni.getStorageSync('userinfo') || {};
  73. this.$http(this.API.API_WECHAT_SETPHONE, {
  74. encryptedData,
  75. iv,
  76. token: userInfo.token
  77. }).then(res => {
  78. console.log("更新手机号", res);
  79. this.$msg('更新成功', {icon: 'success'});
  80. uni.setStorageSync('userinfo', res.data);
  81. this.$toBack();
  82. })
  83. }
  84. },
  85. // 获取用户信息
  86. getUserProfile(){
  87. uni.getUserProfile({
  88. desc: '您的信息将用于时空网显示',
  89. lang: 'zh_CN',
  90. complete: result => {
  91. console.log(result)
  92. if(result.errMsg == 'getUserProfile:ok'){
  93. let encryptedData = result.encryptedData;
  94. let iv = result.iv;
  95. let signature = result.signature;
  96. let userInfo = uni.getStorageSync('userinfo') || {};
  97. this.$http(this.API.API_WECHAT_SETPROFILE, {
  98. encryptedData,
  99. iv,
  100. token: userInfo.token
  101. }).then(res => {
  102. console.log("更新用户信息", res);
  103. this.$msg('更新成功', {icon: 'success'});
  104. uni.setStorageSync('userinfo', res.data);
  105. this.$toBack();
  106. })
  107. }
  108. }
  109. });
  110. }
  111. }
  112. }
  113. </script>
  114. <style>
  115. page{
  116. overflow: hidden;
  117. }
  118. </style>
  119. <style lang="scss" scoped="scoped">
  120. .box{
  121. padding: 60rpx 32rpx;
  122. width: 750rpx;
  123. height: auto;
  124. box-sizing: border-box;
  125. position: relative;
  126. .img{
  127. width: 180rpx;
  128. height: 180rpx;
  129. border-radius: 50%;
  130. }
  131. .btn{
  132. background-color: #09BB07;
  133. color: #FFFFFF;
  134. width: 100%;
  135. height: 88rpx;
  136. border-radius: 42rpx;
  137. font-size: 32rpx;
  138. line-height: 88rpx;
  139. margin-top: 80rpx;
  140. }
  141. }
  142. .fixed-bottom{
  143. position: fixed;
  144. bottom: 60rpx;
  145. left: 0;
  146. padding: 0 32rpx;
  147. .highlight{
  148. color: #1e90ff;
  149. }
  150. }
  151. .mask{
  152. position: absolute;
  153. bottom: 46rpx;
  154. left: 0;
  155. width: 100%;
  156. height: 190rpx;
  157. }
  158. </style>