CommonCategoryHome.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. <template v-if="category.type === 'CalendarBlock'">
  13. <CalendarBlock />
  14. </template>
  15. <SimplePageContentLoader v-else-if="category.data" :loader="category.data" >
  16. <FlexCol>
  17. <template v-if="category.type === 'article'">
  18. <Box2LineRightShadow
  19. v-for="(item, i) in category.data.content.value"
  20. :key="i"
  21. :title="item.title"
  22. :desc="item.desc"
  23. :tags="(item.bottomTags as string[])"
  24. @click="category.detailPage(item)"
  25. />
  26. </template>
  27. <template v-else-if="category.type === 'large-image2'">
  28. <scroll-view scroll-x>
  29. <FlexRow>
  30. <Box2LineLargeImageUserShadow
  31. v-for="(item, i) in category.data.content.value"
  32. classNames="width-2-3 mr-2"
  33. titleColor="title-text"
  34. fixSize
  35. title1
  36. :key="i"
  37. :title="item.title"
  38. :desc="item.desc"
  39. :image="item.image"
  40. :tags="(item.bottomTags as string[])"
  41. @click="category.detailPage(item)"
  42. />
  43. </FlexRow>
  44. </scroll-view>
  45. </template>
  46. <template v-else-if="category.type === 'horizontal-large'">
  47. <scroll-view scroll-x>
  48. <view class="pb-3 pt-3 d-flex flex-row overflow-visible align-stretch">
  49. <Box2LineLargeImageUserShadow
  50. v-for="(item, i) in category.data.content.value"
  51. classNames="width-2-3 mr-2"
  52. titleColor="title-text"
  53. title1
  54. fixSize
  55. :key="i"
  56. :title="item.title"
  57. :desc="item.desc"
  58. :image="item.thumbnail || item.image"
  59. @click="category.detailPage(item)"
  60. />
  61. </view>
  62. </scroll-view>
  63. </template>
  64. <template v-else-if="category.type === 'large-grid2'">
  65. <FlexRow wrap align="stretch" justify="space-between" overflow="visible">
  66. <Box2LineLargeImageUserShadow
  67. v-for="(item, i) in category.data.content.value"
  68. titleColor="title-text"
  69. width="calc(50% - 10rpx)"
  70. fixSize
  71. :key="i"
  72. :title="item.title"
  73. :desc="item.desc"
  74. :image="item.image"
  75. @click="category.detailPage(item)"
  76. />
  77. </FlexRow>
  78. </template>
  79. <template v-else>
  80. <Box2LineImageRightShadow
  81. v-for="(item, i) in category.data.content.value"
  82. titleColor="title-text"
  83. fixSize
  84. :key="i"
  85. :title="item.title"
  86. :desc="item.desc"
  87. :image="item.image"
  88. :tags="(item.bottomTags as string[])"
  89. @click="category.detailPage(item)"
  90. />
  91. </template>
  92. </FlexCol>
  93. </SimplePageContentLoader>
  94. </template>
  95. </FlexCol>
  96. </template>
  97. <script setup lang="ts">;
  98. import { type PropType } from 'vue';
  99. import { CommonContentApi, GetContentListItem, GetContentListParams } from '@/api/CommonContent';
  100. import { navCommonDetail, navCommonList, resolveCommonContentFormData, resolveCommonContentGetPageDetailUrlAuto, useHomeCommonCategoryBlock, type HomeCommonCategoryBlockProps, type IHomeCommonCategoryBlock } from './CommonContent';
  101. import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
  102. import { navTo } from '@/components/utils/PageAction';
  103. import { DateUtils } from '@imengyu/imengyu-utils';
  104. import HomeTitle from '@/pages/parts/HomeTitle.vue';
  105. import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
  106. import Box2LineImageRightShadow from '@/pages/parts/Box2LineImageRightShadow.vue';
  107. import Box2LineRightShadow from '@/pages/parts/Box2LineRightShadow.vue';
  108. import FlexCol from '@/components/layout/FlexCol.vue';
  109. import FlexRow from '@/components/layout/FlexRow.vue';
  110. import CalendarBlock from '@/pages/travel/calendar/block.vue';
  111. import Box2LineLargeImageUserShadow from '@/pages/parts/Box2LineLargeImageUserShadow.vue';
  112. export interface CategoryDefine {
  113. title: string;
  114. content: CommonContentApi|IHomeCommonCategoryBlock|HomeCommonCategoryBlockProps|null;
  115. type?: 'article'|'large-image2'|'horizontal-large'|'large-grid2'|'CalendarBlock'|undefined;
  116. detailPage?: string;
  117. morePage?: string;
  118. noFrom?: boolean;
  119. showMore?: boolean;
  120. }
  121. const props = defineProps({
  122. /**
  123. * 分类定义。仅支持初始化后立即使用,后续修改不会生效。
  124. */
  125. categoryDefine: {
  126. type: Array as PropType<CategoryDefine[]>,
  127. default: () => [],
  128. }
  129. });
  130. const categoryDatas = props.categoryDefine.map(item => {
  131. if (!item.content)
  132. return {
  133. ...item,
  134. detailPage: () => {},
  135. morePage: () => {
  136. if (item.morePage) {
  137. navTo(item.morePage, {});
  138. }
  139. },
  140. data: null,
  141. };
  142. if (item.content instanceof CommonContentApi) {
  143. return {
  144. ...item,
  145. detailPage: (dataItem: GetContentListItem) => {
  146. const id = dataItem.id;
  147. const content = item.content as CommonContentApi;
  148. if (item.detailPage) {
  149. if (item.detailPage === 'byContent')
  150. navTo(resolveCommonContentGetPageDetailUrlAuto(dataItem), { id });
  151. else
  152. navTo(item.detailPage, { id });
  153. } else {
  154. navCommonDetail({
  155. id,
  156. mainBodyColumnId: content.mainBodyColumnId,
  157. modelId: content.modelId,
  158. })
  159. }
  160. },
  161. morePage: () => {
  162. const content = item.content as CommonContentApi;
  163. if (item.morePage) {
  164. navTo(item.morePage, {});
  165. } else {
  166. navCommonList({
  167. title: item.title,
  168. mainBodyColumnId: content.mainBodyColumnId,
  169. modelId: content.modelId,
  170. detailsPage: item.detailPage,
  171. })
  172. }
  173. },
  174. data: useSimpleDataLoader(async () => {
  175. let res = (await (item.content as CommonContentApi)
  176. .getContentList(new GetContentListParams(), 1, 3))
  177. .list;
  178. if (!item.noFrom)
  179. res = resolveCommonContentFormData(res);
  180. else
  181. res.forEach(p => {
  182. if (!p.desc)
  183. p.desc = DateUtils.formatDate(p.publishAt, 'YYYY-MM-dd');
  184. })
  185. return res;
  186. })
  187. }
  188. } else {
  189. const block = item.content.type === 'CommonCategoryBlock' ?
  190. item.content :
  191. useHomeCommonCategoryBlock({
  192. ...item.content,
  193. resolveData: item.noFrom ? undefined : resolveCommonContentFormData,
  194. });
  195. return {
  196. ...item,
  197. detailPage: block.goDetail,
  198. morePage: block.goList,
  199. data: block.loader,
  200. }
  201. }
  202. });
  203. </script>