s-user-card.vue 4.0 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" @click="sheep.$router.go('/pages/user/info')">
  6. <view class="avatar-box ss-m-r-24">
  7. <image class="avatar-img" :src="
  8. isLogin
  9. ? (sheep.$url.cdn(userInfo?.avatar) ? sheep.$url.cdn(userInfo?.avatar): sheep.$url.static('/static/img/shop/default_avatar.png'))
  10. : sheep.$url.static('/static/img/shop/default_avatar.png')
  11. " mode="aspectFill"></image>
  12. </view>
  13. <view>
  14. <view class="nickname-box ss-flex ss-col-center">
  15. <view class="nick-name ss-m-r-20">{{ isLogin ? 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. // 是否登录
  65. const isLogin = computed(() => sheep.$store('user').isLogin);
  66. // 接收参数
  67. const props = defineProps({
  68. // 装修数据
  69. data: {
  70. type: Object,
  71. default: () => ({}),
  72. },
  73. // 装修样式
  74. styles: {
  75. type: Object,
  76. default: () => ({}),
  77. },
  78. // 头像
  79. avatar: {
  80. type: String,
  81. default: '',
  82. },
  83. nickname: {
  84. type: String,
  85. default: '请先登录',
  86. },
  87. vip: {
  88. type: [String, Number],
  89. default: '1',
  90. },
  91. collectNum: {
  92. type: [String, Number],
  93. default: '1',
  94. },
  95. likeNum: {
  96. type: [String, Number],
  97. default: '1',
  98. },
  99. });
  100. // 设置背景样式
  101. const bgStyle = computed(() => {
  102. // 直接从 props.styles 解构
  103. const { bgType, bgImg, bgColor } = props.styles;
  104. // 根据 bgType 返回相应的样式
  105. return {
  106. background: bgType === 'img'
  107. ? `url(${bgImg}) no-repeat top center / 100% 100%`
  108. : bgColor
  109. };
  110. });
  111. // 绑定手机号
  112. function onBind() {
  113. showAuthModal('changeMobile');
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .ss-user-info-wrap {
  118. box-sizing: border-box;
  119. .avatar-box {
  120. width: 100rpx;
  121. height: 100rpx;
  122. border-radius: 50%;
  123. overflow: hidden;
  124. .avatar-img {
  125. width: 100%;
  126. height: 100%;
  127. }
  128. }
  129. .nick-name {
  130. font-size: 34rpx;
  131. font-weight: 400;
  132. color: #333333;
  133. line-height: normal;
  134. }
  135. .vip-img {
  136. width: 30rpx;
  137. height: 30rpx;
  138. }
  139. .sicon-qrcode {
  140. font-size: 40rpx;
  141. }
  142. }
  143. .bind-mobile-box {
  144. width: 100%;
  145. height: 84rpx;
  146. padding: 0 34rpx 0 44rpx;
  147. box-sizing: border-box;
  148. background: #ffffff;
  149. box-shadow: 0px -8rpx 9rpx 0px rgba(#e0e0e0, 0.3);
  150. .cicon-mobile-o {
  151. font-size: 30rpx;
  152. color: #ff690d;
  153. }
  154. .mobile-title {
  155. font-size: 24rpx;
  156. font-weight: 500;
  157. color: #ff690d;
  158. }
  159. .bind-btn {
  160. width: 100rpx;
  161. height: 50rpx;
  162. background: #ff6100;
  163. border-radius: 25rpx;
  164. font-size: 24rpx;
  165. font-weight: 500;
  166. color: #ffffff;
  167. }
  168. }
  169. </style>