s-title-block.vue 2.5 KB

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