s-live-card.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view>
  3. <!-- md卡片:竖向,一行放两个,图上内容下 -->
  4. <view v-if="size === 'md'" class="md-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
  5. <view class="icon-box ss-flex">
  6. <image class="icon" :src="state.liveStatus[data.status].img"></image>
  7. <view class="title ss-m-l-16">{{ state.liveStatus[data.status].title }}</view>
  8. </view>
  9. <image class="md-img-box" :src="sheep.$url.cdn(data.feeds_img)" referrerpolicy="no-referrer"></image>
  10. <view class="md-goods-content">
  11. <view class="md-goods-title ss-line-1" :style="[{ color: titleColor }]">
  12. {{ data.name }}
  13. </view>
  14. <view class="md-goods-subtitle ss-m-t-14 ss-line-1" :style="[{ color: subTitleColor }]">
  15. 主播:{{ data.anchor_name }}
  16. </view>
  17. </view>
  18. </view>
  19. <!-- sl卡片:竖向型,一行放一个,图片上内容下边 -->
  20. <view v-if="size === 'sl'" class="sl-goods-card ss-flex-col" :style="[elStyles]" @tap="onClick">
  21. <view class="icon-box ss-flex">
  22. <image class="icon" :src="state.liveStatus[data.status].img"></image>
  23. <view class="title ss-m-l-16">{{ state.liveStatus[data.status].title }}</view>
  24. </view>
  25. <image class="sl-img-box" :src="sheep.$url.cdn(data.feeds_img)" referrerpolicy="no-referrer"></image>
  26. <view class="sl-goods-content">
  27. <view class="sl-goods-title ss-line-1" :style="[{ color: titleColor }]">
  28. {{ data.name }}
  29. </view>
  30. <view class="sl-goods-subtitle ss-m-t-14 ss-line-1" :style="[{ color: subTitleColor }]">
  31. 主播:{{ data.anchor_name }}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script setup>
  38. import { computed, reactive } from 'vue';
  39. import sheep from '@/sheep';
  40. /**
  41. * 直播卡片
  42. *
  43. * @property {String} img - 图片
  44. * @property {String} title - 标题
  45. * @property {Number} titleWidth = 0 - 标题宽度,默认0,单位rpx
  46. * @property {String} skuText - 规格
  47. * @property {String | Number} score - 佣金
  48. * @property {String | Number} price - 价格
  49. * @property {String | Number} originalPrice - 单购价
  50. * @property {String} priceColor - 价格颜色
  51. * @property {Number | String} num - 数量
  52. *
  53. */
  54. const props = defineProps({
  55. goodsFields: {
  56. type: [Array, Object],
  57. default() {
  58. return {};
  59. },
  60. },
  61. tagStyle: {
  62. type: Object,
  63. default: {},
  64. },
  65. data: {
  66. type: Object,
  67. default: {},
  68. },
  69. size: {
  70. type: String,
  71. default: 'sl',
  72. },
  73. background: {
  74. type: String,
  75. default: '',
  76. },
  77. topRadius: {
  78. type: Number,
  79. default: 0,
  80. },
  81. bottomRadius: {
  82. type: Number,
  83. default: 0,
  84. },
  85. titleColor: {
  86. type: String,
  87. default: '#333',
  88. },
  89. subTitleColor: {
  90. type: String,
  91. default: '#999999',
  92. },
  93. });
  94. // 组件样式
  95. const elStyles = computed(() => {
  96. return {
  97. background: props.background,
  98. 'border-top-left-radius': props.topRadius + 'px',
  99. 'border-top-right-radius': props.topRadius + 'px',
  100. 'border-bottom-left-radius': props.bottomRadius + 'px',
  101. 'border-bottom-right-radius': props.bottomRadius + 'px',
  102. };
  103. });
  104. const state = reactive({
  105. liveStatus: {
  106. 101: {
  107. img: sheep.$url.static('/static/images/living.png'),
  108. title: '直播中',
  109. },
  110. 102: {
  111. img: sheep.$url.static('/static/images/start.png'),
  112. title: '未开始',
  113. },
  114. 103: {
  115. img: sheep.$url.static('/static/images/ended.png'),
  116. title: '已结束',
  117. },
  118. },
  119. });
  120. const emits = defineEmits(['click', 'getHeight']);
  121. const onClick = () => {
  122. emits('click');
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. // md
  127. .md-goods-card {
  128. overflow: hidden;
  129. width: 100%;
  130. height: 424rpx;
  131. position: relative;
  132. z-index: 1;
  133. background-color: $white;
  134. .icon-box {
  135. position: absolute;
  136. left: 20rpx;
  137. top: 10rpx;
  138. width: 136rpx;
  139. height: 40rpx;
  140. background: rgba(#000000, 0.5);
  141. border-radius: 20rpx;
  142. z-index: 1;
  143. .icon {
  144. width: 40rpx;
  145. height: 40rpx;
  146. border-radius: 20rpx 0px 20rpx 20rpx;
  147. }
  148. .title {
  149. font-size: 24rpx;
  150. font-weight: 500;
  151. color: #ffffff;
  152. }
  153. }
  154. .md-goods-content {
  155. position: absolute;
  156. left: 0;
  157. bottom: 0;
  158. padding: 20rpx;
  159. width: 100%;
  160. background: linear-gradient(360deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.02) 100%);
  161. }
  162. .md-img-box {
  163. width: 100%;
  164. height: 100%;
  165. object-fit: cover;
  166. }
  167. .md-goods-title {
  168. font-size: 26rpx;
  169. color: #333;
  170. width: 100%;
  171. }
  172. .md-goods-subtitle {
  173. font-size: 24rpx;
  174. font-weight: 400;
  175. color: #999999;
  176. }
  177. }
  178. .sl-goods-card {
  179. overflow: hidden;
  180. position: relative;
  181. z-index: 1;
  182. width: 100%;
  183. height: 400rpx;
  184. background-color: $white;
  185. .icon-box {
  186. position: absolute;
  187. left: 20rpx;
  188. top: 10rpx;
  189. width: 136rpx;
  190. height: 40rpx;
  191. background: rgba(#000000, 0.5);
  192. border-radius: 20rpx;
  193. z-index: 1;
  194. .icon {
  195. width: 40rpx;
  196. height: 40rpx;
  197. border-radius: 20rpx 0px 20rpx 20rpx;
  198. }
  199. .title {
  200. font-size: 24rpx;
  201. font-weight: 500;
  202. color: #ffffff;
  203. }
  204. }
  205. .sl-goods-content {
  206. position: absolute;
  207. left: 0;
  208. bottom: 0;
  209. padding: 20rpx;
  210. width: 100%;
  211. background: linear-gradient(360deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.02) 100%);
  212. }
  213. .sl-img-box {
  214. width: 100%;
  215. height: 100%;
  216. object-fit: cover;
  217. }
  218. .sl-goods-title {
  219. font-size: 26rpx;
  220. color: #333;
  221. width: 100%;
  222. }
  223. .sl-goods-subtitle {
  224. font-size: 24rpx;
  225. font-weight: 400;
  226. color: #999999;
  227. }
  228. }
  229. </style>