CommonCategoryHome.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <!--通用内容首页小分块组件-->
  3. <FlexCol width="100%">
  4. <!-- 分类 -->
  5. <template v-for="category in categoryDatas" :key="category.title">
  6. <HomeTitle
  7. :title="category.title"
  8. :showMore="category.showMore !== false"
  9. moreText="更多"
  10. @clickMore="category.morePage"
  11. />
  12. <SimplePageContentLoader :loader="category.data" >
  13. <FlexCol>
  14. <template v-if="category.type === 'article'">
  15. <Box2LineRightShadow
  16. v-for="(item, i) in category.data.content.value"
  17. :key="i"
  18. :title="item.title"
  19. :desc="item.desc"
  20. :tags="(item.bottomTags as string[])"
  21. @click="category.detailPage(item)"
  22. />
  23. </template>
  24. <template v-else-if="category.type === 'large-image2'">
  25. <scroll-view scroll-x>
  26. <FlexRow>
  27. <Box2LineLargeImageUserShadow
  28. v-for="(item, i) in category.data.content.value"
  29. classNames="width-2-3 mr-2"
  30. titleColor="title-text"
  31. fixSize
  32. title1
  33. :key="i"
  34. :title="item.title"
  35. :desc="item.desc"
  36. :image="item.image"
  37. :tags="(item.bottomTags as string[])"
  38. @click="category.detailPage(item)"
  39. />
  40. </FlexRow>
  41. </scroll-view>
  42. </template>
  43. <template v-else>
  44. <Box2LineImageRightShadow
  45. v-for="(item, i) in category.data.content.value"
  46. titleColor="title-text"
  47. fixSize
  48. :key="i"
  49. :title="item.title"
  50. :desc="item.desc"
  51. :image="item.image"
  52. :tags="(item.bottomTags as string[])"
  53. @click="category.detailPage(item)"
  54. />
  55. </template>
  56. </FlexCol>
  57. </SimplePageContentLoader>
  58. </template>
  59. </FlexCol>
  60. </template>
  61. <script setup lang="ts">;
  62. import HomeTitle from '@/pages/parts/HomeTitle.vue';
  63. import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
  64. import Box2LineImageRightShadow from '@/pages/parts/Box2LineImageRightShadow.vue';
  65. import Box2LineRightShadow from '@/pages/parts/Box2LineRightShadow.vue';
  66. import FlexCol from '@/components/layout/FlexCol.vue';
  67. import type { PropType } from 'vue';
  68. import { CommonContentApi, GetContentListItem, GetContentListParams } from '@/api/CommonContent';
  69. import { navCommonDetail, navCommonList, resolveCommonContentFormData, resolveCommonContentGetPageDetailUrlAuto, type IHomeCommonCategoryBlock } from './CommonContent';
  70. import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
  71. import { navTo } from '@/components/utils/PageAction';
  72. import { DateUtils } from '@imengyu/imengyu-utils';
  73. import FlexRow from '@/components/layout/FlexRow.vue';
  74. import Box2LineLargeImageUserShadow from '@/pages/parts/Box2LineLargeImageUserShadow.vue';
  75. export interface CategoryDefine {
  76. title: string;
  77. content: CommonContentApi|IHomeCommonCategoryBlock;
  78. type?: 'article'|'large-image2'|''|undefined;
  79. detailPage?: string;
  80. morePage?: string;
  81. noFrom?: boolean;
  82. showMore?: boolean;
  83. }
  84. const props = defineProps({
  85. categoryDefine: {
  86. type: Array as PropType<CategoryDefine[]>,
  87. default: () => [],
  88. }
  89. });
  90. const categoryDatas = props.categoryDefine.map(item => ({
  91. ...item,
  92. detailPage: (dataItem: GetContentListItem) => {
  93. const id = dataItem.id;
  94. if (item.content instanceof CommonContentApi) {
  95. if (item.detailPage) {
  96. if (item.detailPage === 'byContent')
  97. navTo(resolveCommonContentGetPageDetailUrlAuto(dataItem), { id });
  98. else
  99. navTo(item.detailPage, { id });
  100. } else {
  101. navCommonDetail({
  102. id,
  103. mainBodyColumnId: item.content.mainBodyColumnId,
  104. modelId: item.content.modelId,
  105. })
  106. }
  107. } else {
  108. item.content.goDetail(dataItem);
  109. }
  110. },
  111. morePage: () => {
  112. if (item.content instanceof CommonContentApi) {
  113. if (item.morePage) {
  114. navTo(item.morePage, {});
  115. } else {
  116. navCommonList({
  117. title: item.title,
  118. mainBodyColumnId: item.content.mainBodyColumnId,
  119. modelId: item.content.modelId,
  120. detailsPage: item.detailPage,
  121. })
  122. }
  123. } else {
  124. item.content.goList();
  125. }
  126. },
  127. data: item.content instanceof CommonContentApi ? useSimpleDataLoader(async () => {
  128. let res = (await (item.content as CommonContentApi)
  129. .getContentList(new GetContentListParams(), 1, 3))
  130. .list;
  131. if (!item.noFrom)
  132. res = resolveCommonContentFormData(res);
  133. else
  134. res.forEach(p => {
  135. if (!p.desc)
  136. p.desc = DateUtils.formatDate(p.publishAt, 'YYYY-MM-dd');
  137. })
  138. return res;
  139. }) : item.content.loader,
  140. }));
  141. </script>