s-user-card.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <!-- 装修用户组件:用户卡片 -->
  2. <template>
  3. <view class="ss-user-info-wrap ss-p-t-50" :style="[bgStyle, { marginLeft: `${data.space}px` }]">
  4. <view class="ss-flex ss-col-center ss-row-between ss-m-b-20">
  5. <view class="left-box ss-flex ss-col-center ss-m-l-36">
  6. <view class="avatar-box ss-m-r-24">
  7. <image class="avatar-img" :src="
  8. isLogin
  9. ? sheep.$url.cdn(userInfo.avatar)
  10. : sheep.$url.static('/static/img/shop/default_avatar.png')"
  11. mode="aspectFill" @tap="sheep.$router.go('/pages/user/info')">
  12. </image>
  13. </view>
  14. <view>
  15. <view class="nickname-box ss-flex ss-col-center">
  16. <view class="nick-name ss-m-r-20">{{ userInfo?.nickname || nickname }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="right-box ss-m-r-52">
  21. <button class="ss-reset-button" @tap="showShareModal">
  22. <text class="sicon-qrcode"></text>
  23. </button>
  24. </view>
  25. </view>
  26. <!-- 提示绑定手机号 先隐藏 yudao 需要再修改 -->
  27. <view
  28. class="bind-mobile-box ss-flex ss-row-between ss-col-center"
  29. v-if="isLogin && !userInfo.mobile"
  30. >
  31. <view class="ss-flex">
  32. <text class="cicon-mobile-o" />
  33. <view class="mobile-title ss-m-l-20"> 点击绑定手机号确保账户安全</view>
  34. </view>
  35. <button class="ss-reset-button bind-btn" @tap="onBind">去绑定</button>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup>
  40. /**
  41. * 用户卡片
  42. *
  43. * @property {Number} leftSpace - 容器左间距
  44. * @property {Number} rightSpace - 容器右间距
  45. *
  46. * @property {String} avatar - 头像
  47. * @property {String} nickname - 昵称
  48. * @property {String} vip - 等级
  49. * @property {String} collectNum - 收藏数
  50. * @property {String} likeNum - 点赞数
  51. *
  52. *
  53. */
  54. import { computed } from 'vue';
  55. import sheep from '@/sheep';
  56. import {
  57. showShareModal,
  58. showAuthModal,
  59. } from '@/sheep/hooks/useModal';
  60. // 用户信息
  61. const userInfo = computed(() => sheep.$store('user').userInfo);
  62. console.log('用户信息', userInfo);
  63. // 是否登录
  64. const isLogin = computed(() => sheep.$store('user').isLogin);
  65. // 接收参数
  66. const props = defineProps({
  67. // 装修数据
  68. data: {
  69. type: Object,
  70. default: () => ({}),
  71. },
  72. // 装修样式
  73. styles: {
  74. type: Object,
  75. default: () => ({}),
  76. },
  77. // 头像
  78. avatar: {
  79. type: String,
  80. default: '',
  81. },
  82. nickname: {
  83. type: String,
  84. default: '请先登录',
  85. },
  86. vip: {
  87. type: [String, Number],
  88. default: '1',
  89. },
  90. collectNum: {
  91. type: [String, Number],
  92. default: '1',
  93. },
  94. likeNum: {
  95. type: [String, Number],
  96. default: '1',
  97. },
  98. });
  99. // 设置背景样式
  100. const bgStyle = computed(() => {
  101. // 直接从 props.styles 解构
  102. const { bgType, bgImg, bgColor } = props.styles;
  103. // 根据 bgType 返回相应的样式
  104. return {
  105. background: bgType === 'img'
  106. ? `url(${bgImg}) no-repeat top center / 100% 100%`
  107. : bgColor,
  108. };
  109. });
  110. // 绑定手机号
  111. function onBind() {
  112. showAuthModal('changeMobile');
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .ss-user-info-wrap {
  117. box-sizing: border-box;
  118. .avatar-box {
  119. width: 100rpx;
  120. height: 100rpx;
  121. border-radius: 50%;
  122. overflow: hidden;
  123. .avatar-img {
  124. width: 100%;
  125. height: 100%;
  126. }
  127. }
  128. .nick-name {
  129. font-size: 34rpx;
  130. font-weight: 400;
  131. color: #333333;
  132. line-height: normal;
  133. }
  134. .vip-img {
  135. width: 30rpx;
  136. height: 30rpx;
  137. }
  138. .sicon-qrcode {
  139. font-size: 40rpx;
  140. }
  141. }
  142. .bind-mobile-box {
  143. width: 100%;
  144. height: 84rpx;
  145. padding: 0 34rpx 0 44rpx;
  146. box-sizing: border-box;
  147. background: #ffffff;
  148. box-shadow: 0px -8rpx 9rpx 0px rgba(#e0e0e0, 0.3);
  149. .cicon-mobile-o {
  150. font-size: 30rpx;
  151. color: #ff690d;
  152. }
  153. .mobile-title {
  154. font-size: 24rpx;
  155. font-weight: 500;
  156. color: #ff690d;
  157. }
  158. .bind-btn {
  159. width: 100rpx;
  160. height: 50rpx;
  161. background: #ff6100;
  162. border-radius: 25rpx;
  163. font-size: 24rpx;
  164. font-weight: 500;
  165. color: #ffffff;
  166. }
  167. }
  168. </style>