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

172 lines
4.9 KiB

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/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 lf-flex" v-show="agreement.title">
  27. <checkbox-group @change="checkboxChange" style="display: inline-block;">
  28. <checkbox class="lf-text-vertical" :checked="checked"></checkbox>
  29. </checkbox-group>
  30. <view class="lf-m-l-10 lf-font-24 lf-color-gray" style="display: inline-block;">
  31. <text>请认真阅读并同意</text>
  32. <text @click="enterAgree" style="color: #5c6ed1;">{{ agreement.title }}</text>
  33. <text>在小程序下单购买即表示您已默认同意</text>
  34. <text @click="enterAgree" style="color: #5c6ed1;">{{ agreement.title }}</text>
  35. <text>的所有条款</text>
  36. </view>
  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. agreement: {} // 协议
  49. }
  50. },
  51. onLoad(options){
  52. this.type = options.type || this.type;
  53. this.getAgree();
  54. getApp().globalData.wxlogin().then(res => {
  55. this.userInfo = res;
  56. });
  57. },
  58. methods: {
  59. // 获取协议
  60. getAgree(){
  61. this.$http(this.API.API_WXLOGIN_VIEW).then(res => {
  62. this.agreement = res.data.agreement;
  63. })
  64. },
  65. // 进入查看协议
  66. enterAgree(){
  67. this.$url('/pages/agreement/agreement?id='+ this.agreement.article_id);
  68. },
  69. // 勾选协议发生变化
  70. checkboxChange(event){
  71. this.checked = event.detail.value.length > 0;
  72. },
  73. // 微信快捷登录获取手机号
  74. getPhoneNumber(event){
  75. console.log(event);
  76. if(event.detail.errMsg == 'getPhoneNumber:ok'){
  77. let encryptedData = event.detail.encryptedData;
  78. let iv = event.detail.iv;
  79. let userInfo = uni.getStorageSync('userinfo') || {};
  80. this.$http(this.API.API_WECHAT_SETPHONE, {
  81. encryptedData,
  82. iv,
  83. token: userInfo.token
  84. }).then(res => {
  85. console.log("更新手机号", res);
  86. this.$msg('更新成功', {icon: 'success'});
  87. uni.setStorageSync('userinfo', res.data);
  88. this.$toBack();
  89. })
  90. }
  91. },
  92. // 获取用户信息
  93. getUserProfile(){
  94. uni.getUserProfile({
  95. desc: '您的信息将用于时空网显示',
  96. lang: 'zh_CN',
  97. complete: result => {
  98. console.log(result)
  99. if(result.errMsg == 'getUserProfile:ok'){
  100. let encryptedData = result.encryptedData;
  101. let iv = result.iv;
  102. let signature = result.signature;
  103. let userInfo = uni.getStorageSync('userinfo') || {};
  104. this.$http(this.API.API_WECHAT_SETPROFILE, {
  105. encryptedData,
  106. iv,
  107. token: userInfo.token
  108. }).then(res => {
  109. console.log("更新用户信息", res);
  110. this.$msg('更新成功', {icon: 'success'});
  111. uni.setStorageSync('userinfo', res.data);
  112. this.$toBack();
  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. </style>