s-menu-grid.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!-- 装修基础组件:宫格导航 -->
  2. <template>
  3. <view :style="[bgStyle, { marginLeft: `${data.space}px` }]">
  4. <uni-grid :showBorder="Boolean(data.border)" :column="data.column">
  5. <uni-grid-item v-for="(item, index) in data.list" :key="index" @tap="sheep.$router.go(item.url)">
  6. <view class="grid-item-box ss-flex ss-flex-col ss-row-center ss-col-center">
  7. <view class="img-box">
  8. <view class="tag-box" v-if="item.badge.show"
  9. :style="[{ background: item.badge.bgColor, color: item.badge.textColor }]">
  10. {{ item.badge.text }}
  11. </view>
  12. <image class="menu-image" :src="sheep.$url.cdn(item.iconUrl)"></image>
  13. </view>
  14. <view class="title-box ss-flex ss-flex-col ss-row-center ss-col-center">
  15. <view class="grid-text" :style="[{ color: item.titleColor }]">
  16. {{ item.title }}
  17. </view>
  18. <view class="grid-tip" :style="[{ color: item.subtitleColor }]">
  19. {{ item.subtitle }}
  20. </view>
  21. </view>
  22. </view>
  23. </uni-grid-item>
  24. </uni-grid>
  25. </view>
  26. </template>
  27. <script setup>
  28. import sheep from '@/sheep';
  29. import {
  30. computed
  31. } from 'vue';
  32. const props = defineProps({
  33. // 装修数据
  34. data: {
  35. type: Object,
  36. default: () => ({}),
  37. },
  38. // 装修样式
  39. styles: {
  40. type: Object,
  41. default: () => ({}),
  42. },
  43. });
  44. // 设置背景样式
  45. const bgStyle = computed(() => {
  46. // 直接从 props.styles 解构
  47. const {
  48. bgType,
  49. bgImg,
  50. bgColor
  51. } = props.styles;
  52. // 根据 bgType 返回相应的样式
  53. return {
  54. background: bgType === 'img' ? `url(${bgImg}) no-repeat top center / 100% 100%` : bgColor
  55. };
  56. });
  57. </script>
  58. <style lang="scss" scoped>
  59. .menu-image {
  60. width: 24px;
  61. height: 24px;
  62. }
  63. .grid-item-box {
  64. flex: 1;
  65. display: flex;
  66. flex-direction: column;
  67. align-items: center;
  68. justify-content: center;
  69. height: 100%;
  70. .img-box {
  71. position: relative;
  72. .tag-box {
  73. position: absolute;
  74. z-index: 2;
  75. top: 0;
  76. right: 0;
  77. font-size: 2em;
  78. line-height: 1;
  79. padding: 0.4em 0.6em 0.3em;
  80. transform: scale(0.4) translateX(0.5em) translatey(-0.6em);
  81. transform-origin: 100% 0;
  82. border-radius: 200rpx;
  83. white-space: nowrap;
  84. }
  85. }
  86. .title-box {
  87. .grid-tip {
  88. font-size: 24rpx;
  89. white-space: nowrap;
  90. text-align: center;
  91. }
  92. }
  93. }
  94. </style>