s-title-block.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- 页面 -->
  2. <template>
  3. <view
  4. class="ss-title-wrap ss-flex ss-col-center"
  5. :class="[state.typeMap[data.location]]"
  6. :style="[elStyles]"
  7. >
  8. <view class="title-content">
  9. <view v-if="data.title.text" class="title-text" :style="[titleStyles]">{{
  10. data.title.text
  11. }}</view>
  12. <view v-if="data.subtitle.text" :style="[subtitleStyles]" class="sub-title-text">
  13. {{ data.subtitle.text }}
  14. </view>
  15. </view>
  16. <view v-if="data.more.show" class="more-box ss-flex ss-col-center">
  17. <view class="more-text">查看更多</view>
  18. <text class="_icon-forward"></text>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. /**
  24. *
  25. * 标题栏
  26. *
  27. * @property {String} title - 标题
  28. * @property {String} subTitle - 副标题
  29. * @property {Number} height - 高度
  30. * @property {String} Type = [left | right | center | between] - 样式
  31. *
  32. */
  33. import { computed, reactive } from 'vue';
  34. import sheep from '@/sheep';
  35. // 数据
  36. const state = reactive({
  37. typeMap: {
  38. left: 'ss-row-left',
  39. center: 'ss-row-center',
  40. },
  41. });
  42. // 接收参数
  43. const props = defineProps({
  44. data: {
  45. type: Object,
  46. default() {},
  47. },
  48. styles: {
  49. type: Object,
  50. default() {},
  51. },
  52. height: {
  53. type: Number,
  54. default: 100,
  55. },
  56. });
  57. // 组件样式
  58. const elStyles = {
  59. background: `url(${sheep.$url.cdn(props.data.src)}) no-repeat top center / 100% auto`,
  60. height: props.styles.height + 'px',
  61. fontStyle: props.data.title.other.includes('italic') ? 'italic' : 'normal',
  62. fontWeight: props.data.title.other.includes('bold') ? 'bold' : '',
  63. };
  64. // 标题样式
  65. const titleStyles = {
  66. color: props.data.title.color,
  67. fontSize: props.data.title.textFontSize + 'px',
  68. textAlign: props.data.location,
  69. marginLeft: props.data.skew + 'px',
  70. };
  71. // 副标题
  72. const subtitleStyles = {
  73. color: props.data.subtitle.color,
  74. fontSize: props.data.subtitle.textFontSize + 'px',
  75. textAlign: props.data.location,
  76. fontStyle: props.data.subtitle.other.includes('italic') ? 'italic' : 'normal',
  77. fontWeight: props.data.subtitle.other.includes('bold') ? 'bold' : '',
  78. };
  79. </script>
  80. <style lang="scss" scoped>
  81. .ss-title-wrap {
  82. height: 80rpx;
  83. position: relative;
  84. .title-content {
  85. .title-text {
  86. font-size: 30rpx;
  87. color: #333;
  88. }
  89. .sub-title-text {
  90. font-size: 22rpx;
  91. color: #999;
  92. }
  93. }
  94. .more-box {
  95. white-space: nowrap;
  96. font-size: 22rpx;
  97. color: #999;
  98. position: absolute;
  99. top: 50%;
  100. transform: translateY(-50%);
  101. right: 20rpx;
  102. }
  103. }
  104. </style>