navigation.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="pcPages">
  3. <div class="carousel-bos" :style="warpCss" v-if="componentData.styleType == 3">
  4. <el-carousel :height="170 * componentData.count + (componentData.count == 2 ? 10 : 0) + 'px'" :autoplay="false" arrow="always">
  5. <el-carousel-item v-for="(item1, index1) in dataList" :key="index1" class="w100% h100%">
  6. <div class="carousel-list">
  7. <div v-for="(item, index) in item1" :key="index" class="data-list flex-column-center" :style="boxCss">
  8. <div :style="titleCss">{{ item.title || '' }}</div>
  9. <div :style="subtitleCss" class="mt-[2px] mb-[12px]">{{ item.subtitle || '' }}</div>
  10. <el-image
  11. class="img"
  12. :src="item.imageUrl ? item.imageUrl : figure"
  13. :fit="item.imgType == 1 ? 'fill' : item.imgType == 2 ? 'contain' : 'cover'"
  14. :style="componentData.imageRadius ? { borderRadius: componentData.imageRadius + 'px' } : {}"
  15. />
  16. </div>
  17. </div>
  18. </el-carousel-item>
  19. </el-carousel>
  20. </div>
  21. <div v-else :style="warpCss" class="data-bos">
  22. <div v-for="(item, index) in componentData.navlList" :key="index" class="data-list flex-column-center" :style="boxCss">
  23. <div :style="titleCss">{{ item.title || '' }}</div>
  24. <div :style="subtitleCss" class="mt-[2px] mb-[12px]">{{ item.subtitle || '' }}</div>
  25. <el-image
  26. class="img"
  27. :src="item.imageUrl ? item.imageUrl : figure"
  28. :fit="item.imgType == 1 ? 'fill' : item.imgType == 2 ? 'contain' : 'cover'"
  29. :style="componentData.imageRadius ? { borderRadius: componentData.imageRadius + 'px' } : {}"
  30. />
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script lang="ts" setup>
  36. import usePcdiyStore from '@/store/modules/pcdiy';
  37. import figure from '@/assets/images/figure.png';
  38. const diyStore = usePcdiyStore();
  39. const props = defineProps<{
  40. index: number; // 确保声明 index 为可选属性
  41. }>();
  42. const componentData = diyStore.componentList[props.index];
  43. const dataList = computed(() => {
  44. const chunkSize = componentData.number * componentData.count;
  45. const result = [];
  46. for (let i = 0; i < componentData.navlList.length; i += chunkSize) {
  47. const chunk = componentData.navlList.slice(i, i + chunkSize);
  48. result.push(chunk);
  49. }
  50. return result;
  51. });
  52. const warpCss = computed(() => {
  53. let style = '';
  54. style += 'position:relative;';
  55. //背景颜色
  56. if (componentData.pageStartBgColor) {
  57. if (componentData.pageStartBgColor && componentData.pageEndBgColor)
  58. style += `background:linear-gradient(${componentData.pageGradientAngle},${componentData.pageStartBgColor},${componentData.pageEndBgColor});`;
  59. else if (componentData.pageStartBgColor) style += `background: ${componentData.pageStartBgColor};`;
  60. else if (componentData.pageEndBgColor) style += `background: ${componentData.pageEndBgColor};`;
  61. }
  62. //边距
  63. if (componentData.padding) {
  64. if (componentData.padding.top > 0) {
  65. style += 'padding-top:' + componentData.padding.top + 'px' + ';';
  66. }
  67. if (componentData.padding.bottom > 0) {
  68. style += 'padding-bottom:' + componentData.padding.bottom + 'px' + ';';
  69. }
  70. style += 'padding-right:' + componentData.padding.both + 'px' + ';';
  71. style += 'padding-left:' + componentData.padding.both + 'px' + ';';
  72. if (componentData.styleType == 1) style += 'flex-wrap:wrap' + ';';
  73. }
  74. return style;
  75. });
  76. //组件样式
  77. const boxCss = computed(() => {
  78. let style = '';
  79. if (componentData.componentStartBgColor && componentData.componentEndBgColor)
  80. style += `background:linear-gradient(${componentData.componentGradientAngle},${componentData.componentStartBgColor},${componentData.componentEndBgColor});`;
  81. else if (componentData.componentStartBgColor) style += 'background-color:' + componentData.componentStartBgColor + ';';
  82. else if (componentData.componentEndBgColor) style += 'background-color:' + componentData.componentEndBgColor + ';';
  83. if (componentData.number) style += 'flex:' + `0 0 calc((100% - ${(componentData.number - 1) * 10}px) / ${componentData.number})` + ';';
  84. //圆角
  85. if (componentData.topRounded) style += 'border-top-left-radius:' + componentData.topRounded + 'px;';
  86. if (componentData.topRounded) style += 'border-top-right-radius:' + componentData.topRounded + 'px;';
  87. if (componentData.bottomRounded) style += 'border-bottom-left-radius:' + componentData.bottomRounded + 'px;';
  88. if (componentData.bottomRounded) style += 'border-bottom-right-radius:' + componentData.bottomRounded + 'px;';
  89. return style;
  90. });
  91. // 标题样式
  92. const titleCss = computed(() => {
  93. let style = '';
  94. if (componentData.titleColor) style += 'color:' + componentData.titleColor + ';';
  95. if (componentData.titleSize) style += 'font-size:' + componentData.titleSize + 'px;';
  96. if (componentData.titleWeight) style += 'font-weight:' + componentData.titleWeight + ';';
  97. return style;
  98. });
  99. // 副标题样式
  100. const subtitleCss = computed(() => {
  101. let style = '';
  102. if (componentData.subtitleColor) style += 'color:' + componentData.subtitleColor + ';';
  103. if (componentData.subtitleSize) style += 'font-size:' + componentData.subtitleSize + 'px;';
  104. return style;
  105. });
  106. </script>
  107. <style lang="scss" scoped>
  108. .pcPages {
  109. width: 1200px;
  110. margin: 0 auto;
  111. .data-bos {
  112. display: flex;
  113. gap: 10px;
  114. width: 100%;
  115. overflow-x: auto;
  116. .data-list {
  117. min-height: 170px;
  118. .img {
  119. height: 80px;
  120. width: 80px;
  121. }
  122. }
  123. }
  124. .carousel-bos {
  125. .carousel-list {
  126. width: 100%;
  127. height: 100%;
  128. display: flex;
  129. gap: 10px;
  130. flex-wrap: wrap;
  131. .data-list {
  132. height: 170px;
  133. .img {
  134. height: 80px;
  135. width: 80px;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. </style>