s-title-block.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!-- 装修商品组件:标题栏 -->
  2. <template>
  3. <view class="ss-title-wrap ss-flex ss-col-center" :class="[state.typeMap[data.textAlign]]" :style="[bgStyle, { marginLeft: `${data.space}px` }]">
  4. <view class="title-content">
  5. <!-- 主标题 -->
  6. <view v-if="data.title" class="title-text" :style="[titleStyles]">{{ data.title }}</view>
  7. <!-- 副标题 -->
  8. <view v-if="data.description" :style="[descStyles]" class="sub-title-text">{{ data.description }}</view>
  9. </view>
  10. <!-- 查看更多 -->
  11. <view v-if="data.more?.show" class="more-box ss-flex ss-col-center" @tap="sheep.$router.go(data.more.url)"
  12. :style="{color: data.descriptionColor}">
  13. <view class="more-text" v-if="data.more.type !== 'icon'">{{ data.more.text }} </view>
  14. <text class="_icon-forward" v-if="data.more.type !== 'text'"></text>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. /**
  20. * 标题栏
  21. */
  22. import {
  23. reactive,
  24. computed
  25. } from 'vue';
  26. import sheep from '@/sheep';
  27. // 数据
  28. const state = reactive({
  29. typeMap: {
  30. left: 'ss-row-left',
  31. center: 'ss-row-center',
  32. },
  33. });
  34. // 接收参数
  35. const props = defineProps({
  36. // 装修数据
  37. data: {
  38. type: Object,
  39. default: () => ({}),
  40. },
  41. // 装修样式
  42. styles: {
  43. type: Object,
  44. default: () => ({}),
  45. },
  46. });
  47. // 设置背景样式
  48. const bgStyle = computed(() => {
  49. // 直接从 props.styles 解构
  50. const {
  51. bgType,
  52. bgImg,
  53. bgColor
  54. } = props.styles;
  55. // 根据 bgType 返回相应的样式
  56. return {
  57. background: bgType === 'img' ? `url(${bgImg}) no-repeat top center / 100% 100%` : bgColor
  58. };
  59. });
  60. // 标题样式
  61. const titleStyles = {
  62. color: props.data.titleColor,
  63. fontSize: `${props.data.titleSize}px`,
  64. textAlign: props.data.textAlign
  65. };
  66. // 副标题
  67. const descStyles = {
  68. color: props.data.descriptionColor,
  69. textAlign: props.data.textAlign,
  70. fontSize: `${props.data.descriptionSize}px`,
  71. fontWeight: `${props.data.descriptionWeight}px`,
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. .ss-title-wrap {
  76. height: 80rpx;
  77. position: relative;
  78. .title-content {
  79. .title-text {
  80. font-size: 30rpx;
  81. color: #333;
  82. }
  83. .sub-title-text {
  84. font-size: 22rpx;
  85. color: #999;
  86. }
  87. }
  88. .more-box {
  89. white-space: nowrap;
  90. font-size: 22rpx;
  91. color: #999;
  92. position: absolute;
  93. top: 50%;
  94. transform: translateY(-50%);
  95. right: 20rpx;
  96. }
  97. }
  98. </style>