CommonCategoryHome.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.detailsPage(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.detailsPage(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.detailsPage(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.detailsPage(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.detailsPage(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, resolveCommonContentSolveProps, 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. import type { IHomeCommonCategoryListTabListDataSolve } from '../data/CommonCategoryDefine';
  113. export interface CategoryDefine {
  114. title: string;
  115. content: CommonContentApi|IHomeCommonCategoryBlock|HomeCommonCategoryBlockProps|null;
  116. type?: 'article'|'large-image2'|'horizontal-large'|'large-grid2'|'CalendarBlock'|undefined;
  117. detailsPage?: string;
  118. morePage?: string;
  119. dataSolve?: IHomeCommonCategoryListTabListDataSolve[];
  120. showMore?: boolean;
  121. }
  122. const props = defineProps({
  123. /**
  124. * 分类定义。仅支持初始化后立即使用,后续修改不会生效。
  125. */
  126. categoryDefine: {
  127. type: Array as PropType<CategoryDefine[]>,
  128. default: () => [],
  129. }
  130. });
  131. const categoryDatas = props.categoryDefine.map(item => {
  132. if (!item.content)
  133. return {
  134. ...item,
  135. detailsPage: () => {},
  136. morePage: () => {
  137. if (item.morePage) {
  138. navTo(item.morePage, {});
  139. }
  140. },
  141. data: null,
  142. };
  143. if (item.content instanceof CommonContentApi) {
  144. return {
  145. ...item,
  146. detailsPage: (dataItem: GetContentListItem) => {
  147. const id = dataItem.id;
  148. const content = item.content as CommonContentApi;
  149. if (item.detailsPage) {
  150. if (item.detailsPage === 'byContent')
  151. navTo(resolveCommonContentGetPageDetailUrlAuto(dataItem), { id });
  152. else
  153. navTo(item.detailsPage, { id });
  154. } else {
  155. navCommonDetail({
  156. id,
  157. mainBodyColumnId: content.mainBodyColumnId,
  158. modelId: content.modelId,
  159. })
  160. }
  161. },
  162. morePage: () => {
  163. const content = item.content as CommonContentApi;
  164. if (item.morePage) {
  165. navTo(item.morePage, {});
  166. } else {
  167. navCommonList({
  168. title: item.title,
  169. mainBodyColumnId: content.mainBodyColumnId,
  170. modelId: content.modelId,
  171. detailsPage: item.detailsPage,
  172. })
  173. }
  174. },
  175. data: useSimpleDataLoader(async () => {
  176. let res = (await (item.content as CommonContentApi)
  177. .getContentList(new GetContentListParams(), 1, 3))
  178. .list;
  179. return resolveCommonContentSolveProps(res, item.dataSolve || []);;
  180. })
  181. }
  182. } else {
  183. const block = item.content.type === 'CommonCategoryBlock' ?
  184. item.content :
  185. useHomeCommonCategoryBlock({
  186. ...item.content,
  187. dataSolve: item.dataSolve ?? [],
  188. });
  189. return {
  190. ...item,
  191. detailsPage: block.goDetail,
  192. morePage: block.goList,
  193. data: block.loader,
  194. }
  195. }
  196. });
  197. </script>