| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <!--通用内容首页小分块组件-->
- <FlexCol width="100%">
- <!-- 分类 -->
- <template v-for="category in categoryDatas" :key="category.title">
- <HomeTitle
- :title="category.title"
- :showMore="category.showMore !== false"
- moreText="更多"
- @clickMore="category.morePage"
- />
- <template v-if="category.type === 'CalendarBlock'">
- <CalendarBlock />
- </template>
- <SimplePageContentLoader v-else-if="category.data" :loader="category.data" >
- <FlexCol>
- <template v-if="category.type === 'article'">
- <Box2LineRightShadow
- v-for="(item, i) in category.data.content.value"
- :key="i"
- :title="item.title"
- :desc="item.desc"
- :tags="(item.bottomTags as string[])"
- @click="category.detailsPage(item)"
- />
- </template>
- <template v-else-if="category.type === 'large-image2'">
- <scroll-view scroll-x>
- <FlexRow>
- <Box2LineLargeImageUserShadow
- v-for="(item, i) in category.data.content.value"
- classNames="width-2-3 mr-2"
- titleColor="title-text"
- fixSize
- title1
- :key="i"
- :title="item.title"
- :desc="item.desc"
- :image="item.image"
- :tags="(item.bottomTags as string[])"
- @click="category.detailsPage(item)"
- />
- </FlexRow>
- </scroll-view>
- </template>
- <template v-else-if="category.type === 'horizontal-large'">
- <scroll-view scroll-x>
- <view class="pb-3 pt-3 d-flex flex-row overflow-visible align-stretch">
- <Box2LineLargeImageUserShadow
- v-for="(item, i) in category.data.content.value"
- classNames="width-2-3 mr-2"
- titleColor="title-text"
- title1
- fixSize
- :key="i"
- :title="item.title"
- :desc="item.desc"
- :image="item.thumbnail || item.image"
- @click="category.detailsPage(item)"
- />
- </view>
- </scroll-view>
- </template>
- <template v-else-if="category.type === 'large-grid2'">
- <FlexRow wrap align="stretch" justify="space-between" overflow="visible">
- <Box2LineLargeImageUserShadow
- v-for="(item, i) in category.data.content.value"
- titleColor="title-text"
- width="calc(50% - 10rpx)"
- fixSize
- :key="i"
- :title="item.title"
- :desc="item.desc"
- :image="item.image"
- @click="category.detailsPage(item)"
- />
- </FlexRow>
- </template>
- <template v-else>
- <Box2LineImageRightShadow
- v-for="(item, i) in category.data.content.value"
- titleColor="title-text"
- fixSize
- :key="i"
- :title="item.title"
- :desc="item.desc"
- :image="item.image"
- :tags="(item.bottomTags as string[])"
- @click="category.detailsPage(item)"
- />
- </template>
- </FlexCol>
- </SimplePageContentLoader>
- </template>
- </FlexCol>
- </template>
- <script setup lang="ts">;
- import { type PropType } from 'vue';
- import { CommonContentApi, GetContentListItem, GetContentListParams } from '@/api/CommonContent';
- import { navCommonDetail, navCommonList, resolveCommonContentFormData, resolveCommonContentGetPageDetailUrlAuto, resolveCommonContentSolveProps, useHomeCommonCategoryBlock, type HomeCommonCategoryBlockProps, type IHomeCommonCategoryBlock } from './CommonContent';
- import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
- import { navTo } from '@/components/utils/PageAction';
- import { DateUtils } from '@imengyu/imengyu-utils';
- import HomeTitle from '@/pages/parts/HomeTitle.vue';
- import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
- import Box2LineImageRightShadow from '@/pages/parts/Box2LineImageRightShadow.vue';
- import Box2LineRightShadow from '@/pages/parts/Box2LineRightShadow.vue';
- import FlexCol from '@/components/layout/FlexCol.vue';
- import FlexRow from '@/components/layout/FlexRow.vue';
- import CalendarBlock from '@/pages/travel/calendar/block.vue';
- import Box2LineLargeImageUserShadow from '@/pages/parts/Box2LineLargeImageUserShadow.vue';
- import type { IHomeCommonCategoryListTabListDataSolve } from '../data/CommonCategoryDefine';
- export interface CategoryDefine {
- title: string;
- content: CommonContentApi|IHomeCommonCategoryBlock|HomeCommonCategoryBlockProps|null;
- type?: 'article'|'large-image2'|'horizontal-large'|'large-grid2'|'CalendarBlock'|undefined;
- detailsPage?: string;
- morePage?: string;
- dataSolve?: IHomeCommonCategoryListTabListDataSolve[];
- showMore?: boolean;
- }
- const props = defineProps({
- /**
- * 分类定义。仅支持初始化后立即使用,后续修改不会生效。
- */
- categoryDefine: {
- type: Array as PropType<CategoryDefine[]>,
- default: () => [],
- }
- });
- const categoryDatas = props.categoryDefine.map(item => {
- if (!item.content)
- return {
- ...item,
- detailsPage: () => {},
- morePage: () => {
- if (item.morePage) {
- navTo(item.morePage, {});
- }
- },
- data: null,
- };
- if (item.content instanceof CommonContentApi) {
- return {
- ...item,
- detailsPage: (dataItem: GetContentListItem) => {
- const id = dataItem.id;
- const content = item.content as CommonContentApi;
- if (item.detailsPage) {
- if (item.detailsPage === 'byContent')
- navTo(resolveCommonContentGetPageDetailUrlAuto(dataItem), { id });
- else
- navTo(item.detailsPage, { id });
- } else {
- navCommonDetail({
- id,
- mainBodyColumnId: content.mainBodyColumnId,
- modelId: content.modelId,
- })
- }
- },
- morePage: () => {
- const content = item.content as CommonContentApi;
- if (item.morePage) {
- navTo(item.morePage, {});
- } else {
- navCommonList({
- title: item.title,
- mainBodyColumnId: content.mainBodyColumnId,
- modelId: content.modelId,
- detailsPage: item.detailsPage,
- })
- }
- },
- data: useSimpleDataLoader(async () => {
- let res = (await (item.content as CommonContentApi)
- .getContentList(new GetContentListParams(), 1, 3))
- .list;
- return resolveCommonContentSolveProps(res, item.dataSolve || []);;
- })
- }
- } else {
- const block = item.content.type === 'CommonCategoryBlock' ?
- item.content :
- useHomeCommonCategoryBlock({
- ...item.content,
- dataSolve: item.dataSolve ?? [],
- });
- return {
- ...item,
- detailsPage: block.goDetail,
- morePage: block.goList,
- data: block.loader,
- }
- }
- });
- </script>
|