article.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="pcPages" :style="warpCss">
  3. <div class="article-bos" :style="boxCss">
  4. <template v-for="(item, index) in dataList" :key="index">
  5. <div
  6. class="article-list hover-color"
  7. :style="dataCss"
  8. v-if="componentData.dataType == 2 && componentData.dataIds.length > 0 ? true : index < componentData.dataNumber"
  9. @click="onPath('/plan_info/project?id=' + item.id)"
  10. >
  11. <img :src="item.caseImage ? item.caseImage : figure" alt="" />
  12. <div class="caseTitle zi-hover">{{ item.caseTitle }}</div>
  13. <div class="projectBrief">{{ item.projectBrief }}</div>
  14. </div>
  15. </template>
  16. </div>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. import { onPath } from '@/utils/siteConfig';
  21. import { getServiceCaseList } from '@/api/home/diy';
  22. import figure from '@/assets/images/figure.png';
  23. const props = defineProps<{
  24. row?: any;
  25. datas?: any;
  26. }>();
  27. const componentData = props.row || {};
  28. const dataList = ref<any>([]);
  29. onMounted(() => {
  30. if (props.datas) {
  31. dataList.value = props.datas;
  32. } else {
  33. getDataList();
  34. }
  35. });
  36. const getDataList = () => {
  37. // 默认
  38. if (componentData.dataType == 1) {
  39. getServiceCaseList({ pageSize: 20 }).then((res) => {
  40. if (res.code == 200) {
  41. dataList.value = res.rows;
  42. }
  43. });
  44. } else {
  45. //手动选择
  46. if (componentData.dataIds.length > 0) {
  47. getServiceCaseList({ pageNum: 1, pageSize: 20, ids: componentData.dataIds.join(',') }).then((res) => {
  48. if (res.code == 200) {
  49. dataList.value = res.rows;
  50. }
  51. });
  52. }
  53. }
  54. };
  55. // 监听 componentData 变化,重新请求数据
  56. watch(
  57. () => componentData.dataType,
  58. () => {
  59. getDataList();
  60. }
  61. );
  62. watch(
  63. () => componentData.dataIds,
  64. () => {
  65. getDataList();
  66. },
  67. { deep: true } // 5. 数组变化需要 deep 监听
  68. );
  69. const warpCss = computed(() => {
  70. let style = '';
  71. style += 'position:relative;';
  72. //背景颜色
  73. if (componentData.pageStartBgColor) {
  74. if (componentData.pageStartBgColor && componentData.pageEndBgColor)
  75. style += `background:linear-gradient(${componentData.pageGradientAngle},${componentData.pageStartBgColor},${componentData.pageEndBgColor});`;
  76. else if (componentData.pageStartBgColor) style += `background: ${componentData.pageStartBgColor};`;
  77. else if (componentData.pageEndBgColor) style += `background: ${componentData.pageEndBgColor};`;
  78. }
  79. //背景图片
  80. if (componentData.componentBgUrl) {
  81. style += `background-image:url('${componentData.componentBgUrl}');`;
  82. style += 'background-size: cover;background-repeat: no-repeat;';
  83. }
  84. //边距
  85. if (componentData.padding) {
  86. if (componentData.padding.top > 0) {
  87. style += 'padding-top:' + componentData.padding.top + 'px' + ';';
  88. }
  89. if (componentData.padding.bottom > 0) {
  90. style += 'padding-bottom:' + componentData.padding.bottom + 'px' + ';';
  91. }
  92. style += 'padding-right:' + componentData.padding.both + 'px' + ';';
  93. style += 'padding-left:' + componentData.padding.both + 'px' + ';';
  94. }
  95. //圆角
  96. if (componentData.topRounded) style += 'border-top-left-radius:' + componentData.topRounded + 'px;';
  97. if (componentData.topRounded) style += 'border-top-right-radius:' + componentData.topRounded + 'px;';
  98. if (componentData.bottomRounded) style += 'border-bottom-left-radius:' + componentData.bottomRounded + 'px;';
  99. if (componentData.bottomRounded) style += 'border-bottom-right-radius:' + componentData.bottomRounded + 'px;';
  100. //间距
  101. if (componentData.margin) {
  102. if (componentData.margin.top > 0) {
  103. style += 'margin-top:' + componentData.margin.top + 'px' + ';';
  104. }
  105. if (componentData.margin.bottom > 0) {
  106. style += 'margin-bottom:' + componentData.margin.bottom + 'px' + ';';
  107. }
  108. }
  109. return style;
  110. });
  111. //组件样式
  112. const boxCss = computed(() => {
  113. let style = '';
  114. if (componentData.componentStartBgColor && componentData.componentEndBgColor)
  115. style += `background:linear-gradient(${componentData.componentGradientAngle},${componentData.componentStartBgColor},${componentData.componentEndBgColor});`;
  116. else if (componentData.componentStartBgColor) style += 'background-color:' + componentData.componentStartBgColor + ';';
  117. else if (componentData.componentEndBgColor) style += 'background-color:' + componentData.componentEndBgColor + ';';
  118. return style;
  119. });
  120. //样式
  121. const dataCss = computed(() => {
  122. let style = '';
  123. //背景颜色
  124. if (componentData.backgroundColor) style += 'background-color:' + componentData.backgroundColor + ';';
  125. //圆角
  126. if (componentData.boxTopRounded) style += 'border-top-left-radius:' + componentData.boxTopRounded + 'px;';
  127. if (componentData.boxTopRounded) style += 'border-top-right-radius:' + componentData.boxTopRounded + 'px;';
  128. if (componentData.boxBottomRounded) style += 'border-bottom-left-radius:' + componentData.boxBottomRounded + 'px;';
  129. if (componentData.boxBottomRounded) style += 'border-bottom-right-radius:' + componentData.boxBottomRounded + 'px;';
  130. //投影
  131. if (componentData.border == 2 && componentData.borderColor) style += 'box-shadow:' + componentData.borderColor + ' 0px 0px 5px';
  132. //描边
  133. if (componentData.border == 3 && componentData.borderColor) style += 'border:' + componentData.borderColor + ' 1px solid;';
  134. return style;
  135. });
  136. </script>
  137. <style lang="scss" scoped>
  138. .pcPages {
  139. width: 100%;
  140. max-width: 1500px;
  141. min-width: 1200px;
  142. margin: 0 auto;
  143. .article-bos {
  144. width: 100%;
  145. display: flex;
  146. flex-wrap: wrap;
  147. gap: 15px;
  148. .article-list {
  149. flex: 0 0 calc((100% - 45px) / 4);
  150. width: 0;
  151. overflow: hidden;
  152. cursor: pointer;
  153. background-color: #ffffff;
  154. border-radius: 5px;
  155. .caseTitle {
  156. font-size: 14px;
  157. color: #333333;
  158. height: 20px;
  159. overflow: hidden;
  160. white-space: nowrap;
  161. text-overflow: ellipsis;
  162. width: 100%;
  163. margin: 5px 0;
  164. padding: 0 15px;
  165. }
  166. .projectBrief {
  167. font-size: 12px;
  168. color: #666666;
  169. height: 50px;
  170. display: -webkit-box;
  171. -webkit-line-clamp: 3;
  172. line-clamp: 3;
  173. /* 添加标准属性 */
  174. -webkit-box-orient: vertical;
  175. overflow: hidden;
  176. text-overflow: ellipsis;
  177. width: 100%;
  178. padding: 0 15px;
  179. margin-bottom: 15px;
  180. }
  181. img {
  182. width: 100%;
  183. height: 165px;
  184. }
  185. // flex: 0 0 calc((100% - ${(componentData.number - 1) * 10}px);
  186. }
  187. }
  188. }
  189. </style>