s-user-card.vue 4.0 KB

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