领峰UI库,封装一些经常使用到的组件,自定义样式,模块化js函数,调用简单快速上手。
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.

176 lines
5.0 KiB

  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. <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" 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" class="text-orange">{{ agreement.title }}</text>
  33. <text>在小程序下单购买即表示您已默认同意</text>
  34. <text @click="enterAgree" class="text-orange">{{ 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. setTimeout(() => {
  89. this.$toBack();
  90. }, 1000);
  91. })
  92. }
  93. },
  94. // 获取用户信息
  95. getUserProfile(){
  96. uni.getUserProfile({
  97. desc: '您的信息将用于时空网显示',
  98. lang: 'zh_CN',
  99. complete: result => {
  100. console.log(result)
  101. if(result.errMsg == 'getUserProfile:ok'){
  102. let encryptedData = result.encryptedData;
  103. let iv = result.iv;
  104. let signature = result.signature;
  105. // let userInfo = uni.getStorageSync('userinfo') || {};
  106. this.$http(this.API.API_WECHAT_SETPROFILE, {
  107. encryptedData,
  108. iv,
  109. // token: userInfo.token // 已在公共参数传
  110. }).then(res => {
  111. console.log("更新用户信息", res);
  112. this.$msg('更新成功', {icon: 'success'});
  113. uni.setStorageSync('userinfo', res.data);
  114. setTimeout(() => {
  115. this.$toBack();
  116. }, 1000);
  117. })
  118. }
  119. }
  120. });
  121. }
  122. }
  123. }
  124. </script>
  125. <style>
  126. page{
  127. overflow: hidden;
  128. }
  129. </style>
  130. <style lang="scss" scoped="scoped">
  131. .box{
  132. padding: 60rpx 32rpx;
  133. width: 750rpx;
  134. height: auto;
  135. box-sizing: border-box;
  136. position: relative;
  137. .img{
  138. width: 180rpx;
  139. height: 180rpx;
  140. border-radius: 50%;
  141. }
  142. .btn{
  143. background-color: #09BB07;
  144. color: #FFFFFF;
  145. width: 100%;
  146. height: 88rpx;
  147. border-radius: 42rpx;
  148. font-size: 32rpx;
  149. line-height: 88rpx;
  150. margin-top: 80rpx;
  151. }
  152. }
  153. .fixed-bottom{
  154. position: fixed;
  155. bottom: 60rpx;
  156. left: 0;
  157. padding: 0 32rpx;
  158. .highlight{
  159. color: #1e90ff;
  160. }
  161. }
  162. .mask{
  163. position: absolute;
  164. bottom: 46rpx;
  165. left: 0;
  166. width: 100%;
  167. height: 190rpx;
  168. }
  169. .display-inline-block{
  170. display: inline-block;
  171. }
  172. </style>