s-title-block.vue 2.4 KB

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