|
@@ -0,0 +1,494 @@
|
|
|
|
|
+import type { ListData, RequestData } from '../utils/request'
|
|
|
|
|
+import type { HeritageItem } from './heritage-content'
|
|
|
|
|
+import { cached } from '../utils/cache'
|
|
|
|
|
+import { normalizeMediaUrl } from '../utils/media'
|
|
|
|
|
+import { MAIN_BODY_ID, normalizeList, request } from '../utils/request'
|
|
|
|
|
+
|
|
|
|
|
+export { API_BASE_URL, MAIN_BODY_ID } from '../utils/request'
|
|
|
|
|
+
|
|
|
|
|
+// 地图点位和村落列表变化很少,缓存 5 分钟,文旅页与村镇列表页之间复用;下拉刷新会跳过缓存。
|
|
|
|
|
+const STATIC_LIST_CACHE_TTL = 5 * 60 * 1000
|
|
|
|
|
+
|
|
|
|
|
+// ID 来自后台「内容模型管理」:ID 是主体栏目 ID,模型 ID 是内容模型 ID。
|
|
|
|
|
+export const HERITAGE_COLUMNS = [
|
|
|
|
|
+ { key: 'projects', label: '非遗项目', modelId: 2, columnId: 2, icon: 'ph:mask-happy-duotone', unit: '项' },
|
|
|
|
|
+ { key: 'inheritors', label: '非遗传承人', modelId: 7, columnId: 38, icon: 'ph:user-focus-duotone', unit: '人' },
|
|
|
|
|
+ { key: 'units', label: '非遗保护单位', modelId: 17, columnId: 259, icon: 'ph:columns-duotone', unit: '家' },
|
|
|
|
|
+ { key: 'centers', label: '非遗传习中心(所)', modelId: 17, columnId: 221, icon: 'ph:storefront-duotone', unit: '处' },
|
|
|
|
|
+] as const
|
|
|
|
|
+
|
|
|
|
|
+export const HOME_CULTURE_COLUMNS = [
|
|
|
|
|
+ { key: 'news', label: '最新资讯', modelId: 18, columnId: '', icon: 'ph:newspaper-clipping-duotone' },
|
|
|
|
|
+ { key: 'areas', label: '重点区域', modelId: 17, columnId: '435', icon: 'ph:shield-check-duotone' },
|
|
|
|
|
+ { key: 'relics', label: '文物古迹', modelId: 1, columnId: '1', icon: 'ph:building-duotone' },
|
|
|
|
|
+ { key: 'experience', label: '传承体验', modelId: 18, columnId: '434', icon: 'ph:hand-heart-duotone' },
|
|
|
|
|
+ // 栏目 ID 为 0 时查询研究模型下的全部内容。
|
|
|
|
|
+ { key: 'research', label: '理论研究', modelId: 19, columnId: '0', icon: 'ph:books-duotone' },
|
|
|
|
|
+ { key: 'achievements', label: '特色成果', modelId: 18, columnId: '425', icon: 'ph:trophy-duotone' },
|
|
|
|
|
+ { key: 'workshops', label: '非遗工坊', modelId: 17, columnId: '404', icon: 'ph:house-line-duotone' },
|
|
|
|
|
+] as const
|
|
|
|
|
+
|
|
|
|
|
+export type HomeCultureKey = typeof HOME_CULTURE_COLUMNS[number]['key']
|
|
|
|
|
+
|
|
|
|
|
+export interface NewsColumn {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ name: string
|
|
|
|
|
+ modelId: number
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export type HeritageKey = typeof HERITAGE_COLUMNS[number]['key']
|
|
|
|
|
+export interface CategoryOption {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ name: string
|
|
|
|
|
+ pid: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface ApiCategory {
|
|
|
|
|
+ id: number | string
|
|
|
|
|
+ pid: number | string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ status?: string
|
|
|
|
|
+ children?: ApiCategory[]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface CategoryData {
|
|
|
|
|
+ region_list?: ApiCategory[]
|
|
|
|
|
+ level_list?: ApiCategory[]
|
|
|
|
|
+ ich_type_list?: ApiCategory[]
|
|
|
|
|
+ cr_type_list?: ApiCategory[]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface ApiContent {
|
|
|
|
|
+ id: number | string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ thumbnail?: string | null
|
|
|
|
|
+ image?: string | null
|
|
|
|
|
+ desc?: string | null
|
|
|
|
|
+ region?: number | string | null
|
|
|
|
|
+ level?: number | string | null
|
|
|
|
|
+ ich_type?: number | string | null
|
|
|
|
|
+ region_text?: string
|
|
|
|
|
+ level_text?: string
|
|
|
|
|
+ ich_type_text?: string
|
|
|
|
|
+ ich_name?: string | null
|
|
|
|
|
+ column_name?: string
|
|
|
|
|
+ page?: string
|
|
|
|
|
+ publish_at?: string | null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+type ContentListData = ListData<ApiContent>
|
|
|
|
|
+
|
|
|
|
|
+export interface ContentDetail {
|
|
|
|
|
+ model_id: number
|
|
|
|
|
+ title: string
|
|
|
|
|
+ image: string
|
|
|
|
|
+ audio: string
|
|
|
|
|
+ video: string
|
|
|
|
|
+ flag_text: string
|
|
|
|
|
+ publish_at: string
|
|
|
|
|
+ content: string
|
|
|
|
|
+ images?: string[] | null
|
|
|
|
|
+ code?: string | null
|
|
|
|
|
+ age?: string | null
|
|
|
|
|
+ region?: string | number | null
|
|
|
|
|
+ level?: string | number | null
|
|
|
|
|
+ cr_type?: string | number | null
|
|
|
|
|
+ ich_type?: string | number | null
|
|
|
|
|
+ region_text?: string | null
|
|
|
|
|
+ level_text?: string | null
|
|
|
|
|
+ cr_type_text?: string | null
|
|
|
|
|
+ ich_type_text?: string | null
|
|
|
|
|
+ address?: string | null
|
|
|
|
|
+ guard?: number | string | null
|
|
|
|
|
+ heritage?: number | string | null
|
|
|
|
|
+ unit?: string | null
|
|
|
|
|
+ batch_text?: string | null
|
|
|
|
|
+ intro?: string | null
|
|
|
|
|
+ environment?: string | null
|
|
|
|
|
+ description?: string | null
|
|
|
|
|
+ desc?: string | null
|
|
|
|
|
+ value?: string | null
|
|
|
|
|
+ director?: string | null
|
|
|
|
|
+ protected_area?: string | null
|
|
|
|
|
+ inheritor?: string | null
|
|
|
|
|
+ zt_image?: string | null
|
|
|
|
|
+ sensor_schematic?: string | null
|
|
|
|
|
+ vr?: string | null
|
|
|
|
|
+ association_me_list?: ContentRelatedCollection
|
|
|
|
|
+ inheritors_list?: ContentRelatedCollection
|
|
|
|
|
+ ich_sites_list?: ContentRelatedCollection
|
|
|
|
|
+ works_list?: ContentRelatedCollection
|
|
|
|
|
+ other_level?: ContentRelatedCollection
|
|
|
|
|
+ nation?: string | null
|
|
|
|
|
+ gender?: number | string | null
|
|
|
|
|
+ gender_text?: string | null
|
|
|
|
|
+ date_birth?: string | null
|
|
|
|
|
+ prize?: string | null
|
|
|
|
|
+ association?: Record<string, unknown> | null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export type ContentRelatedCollection = Record<string, unknown>[] | Record<string, Record<string, unknown>> | null
|
|
|
|
|
+
|
|
|
|
|
+export interface CulturePlace extends ApiContent {
|
|
|
|
|
+ address?: string | null
|
|
|
|
|
+ longitude?: number | string | null
|
|
|
|
|
+ latitude?: number | string | null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface VillageItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ image: string
|
|
|
|
|
+ description: string
|
|
|
|
|
+ location: string
|
|
|
|
|
+ type: string
|
|
|
|
|
+ date: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface HomeBannerItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ image: string
|
|
|
|
|
+ tag: string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ subtitle: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface HomeNewsItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ image?: string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ subtitle: string
|
|
|
|
|
+ time: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface HomeRecommendItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ image: string
|
|
|
|
|
+ imageBg: string
|
|
|
|
|
+ tag: string
|
|
|
|
|
+ tagBg: string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ subtitle: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface HomeVolunteerItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ meta: string
|
|
|
|
|
+ actionText: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface InheritItem extends HeritageItem {
|
|
|
|
|
+ id: string
|
|
|
|
|
+ regionId: string
|
|
|
|
|
+ levelId: string
|
|
|
|
|
+ categoryId: string
|
|
|
|
|
+ page: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface InheritLists {
|
|
|
|
|
+ projects: InheritItem[]
|
|
|
|
|
+ inheritors: InheritItem[]
|
|
|
|
|
+ units: InheritItem[]
|
|
|
|
|
+ centers: InheritItem[]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface InheritResult {
|
|
|
|
|
+ lists: InheritLists
|
|
|
|
|
+ totals: Record<HeritageKey, number>
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export interface InheritFilters {
|
|
|
|
|
+ keyword: string
|
|
|
|
|
+ categoryId: string
|
|
|
|
|
+ levelId: string
|
|
|
|
|
+ districtId: string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function get<T>(path: string, data: RequestData): Promise<T> {
|
|
|
|
|
+ return request<T>(path, { data: { main_body_id: MAIN_BODY_ID, ...data } })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getContentDetail(id: string): Promise<ContentDetail> {
|
|
|
|
|
+ const data = await get<Partial<Omit<ContentDetail, 'model_id'>> & { model_id?: string | number | null }>('content/content/getContentDetail', { id })
|
|
|
|
|
+ if (!data || Array.isArray(data)) {
|
|
|
|
|
+ throw new Error('文章不存在或已下架')
|
|
|
|
|
+ }
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...data,
|
|
|
|
|
+ // 文档示例使用字符串,当前接口使用数字;统一后再按模型选择展示结构。
|
|
|
|
|
+ model_id: Number(data.model_id) || 0,
|
|
|
|
|
+ title: data.title?.trim() || '',
|
|
|
|
|
+ image: data.image?.trim() || '',
|
|
|
|
|
+ audio: data.audio?.trim() || '',
|
|
|
|
|
+ video: data.video?.trim() || '',
|
|
|
|
|
+ flag_text: data.flag_text?.trim() || '',
|
|
|
|
|
+ publish_at: data.publish_at?.trim() || '',
|
|
|
|
|
+ content: data.content?.trim() || '',
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getHomeBanners(): Promise<HomeBannerItem[]> {
|
|
|
|
|
+ interface ApiBanner {
|
|
|
|
|
+ id: number | string
|
|
|
|
|
+ title: string
|
|
|
|
|
+ image?: string | null
|
|
|
|
|
+ intro?: string | null
|
|
|
|
|
+ scene_text?: string | null
|
|
|
|
|
+ type_text?: string | null
|
|
|
|
|
+ }
|
|
|
|
|
+ const data = await get<ApiBanner[]>('content/banner_function/getIndexBanner', {})
|
|
|
|
|
+ return data.map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ image: normalizeMediaUrl(item.image),
|
|
|
|
|
+ tag: item.scene_text || item.type_text || '',
|
|
|
|
|
+ title: item.title || '',
|
|
|
|
|
+ subtitle: item.intro || '',
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getHomeRecommends(): Promise<HomeRecommendItem[]> {
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getFlagList', {
|
|
|
|
|
+ flag: 'recommend',
|
|
|
|
|
+ pageSize: 4,
|
|
|
|
|
+ })
|
|
|
|
|
+ return normalizeList(data, 1, 4).items.slice(0, 4).map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ image: normalizeMediaUrl(item.thumbnail || item.image),
|
|
|
|
|
+ imageBg: '#f2ebe3',
|
|
|
|
|
+ tag: item.column_name || '',
|
|
|
|
|
+ tagBg: 'rgba(159,55,40,0.85)',
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ subtitle: item.desc || '',
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function fetchAllCulturePlaces(): Promise<CulturePlace[]> {
|
|
|
|
|
+ const places: CulturePlace[] = []
|
|
|
|
|
+ const pageSize = 100
|
|
|
|
|
+ for (let page = 1; ; page++) {
|
|
|
|
|
+ // 栏目留空查询文化场所模型的全部栏目,分页拉全,避免只显示第一页点位。
|
|
|
|
|
+ const data = await get<ListData<CulturePlace>>('content/content/getContentList', {
|
|
|
|
|
+ model_id: 17,
|
|
|
|
|
+ main_body_column_id: '',
|
|
|
|
|
+ page,
|
|
|
|
|
+ pageSize,
|
|
|
|
|
+ })
|
|
|
|
|
+ const { items, total } = normalizeList(data, page, pageSize)
|
|
|
|
|
+ places.push(...items)
|
|
|
|
|
+ if (Array.isArray(data) ? items.length < pageSize : places.length >= total) {
|
|
|
|
|
+ return places
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!items.length) {
|
|
|
|
|
+ throw new Error('文化场所数据未加载完整,请重试')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export function getCulturePlaces(force = false): Promise<CulturePlace[]> {
|
|
|
|
|
+ return cached('culture-places', STATIC_LIST_CACHE_TTL, fetchAllCulturePlaces, force)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function fetchVillageList(): Promise<VillageItem[]> {
|
|
|
|
|
+ interface ApiVillage {
|
|
|
|
|
+ id: number | string
|
|
|
|
|
+ name: string
|
|
|
|
|
+ thumbnail?: string | null
|
|
|
|
|
+ images?: string[]
|
|
|
|
|
+ overview?: string | null
|
|
|
|
|
+ district?: string | null
|
|
|
|
|
+ township?: string | null
|
|
|
|
|
+ village_type_text?: string
|
|
|
|
|
+ enter_at?: string | null
|
|
|
|
|
+ }
|
|
|
|
|
+ // 该接口直接返回完整数组,不支持 page/pageSize,避免翻页重复同一批村落。
|
|
|
|
|
+ const data = await get<ApiVillage[]>('village/village/getList', {})
|
|
|
|
|
+ return data.map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ title: item.name,
|
|
|
|
|
+ image: normalizeMediaUrl(item.thumbnail || item.images?.[0]),
|
|
|
|
|
+ description: item.overview || '',
|
|
|
|
|
+ location: [item.district, item.township].filter(Boolean).join(' · '),
|
|
|
|
|
+ type: item.village_type_text || '',
|
|
|
|
|
+ date: item.enter_at?.split(' ')[0] || '',
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export function getVillageList(force = false): Promise<VillageItem[]> {
|
|
|
|
|
+ return cached('village-list', STATIC_LIST_CACHE_TTL, fetchVillageList, force)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getHomeVolunteers(): Promise<HomeVolunteerItem[]> {
|
|
|
|
|
+ // 后台主体栏目「组织介绍」ID 为 74,对应「志愿者联盟」模型 12。
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getContentList', {
|
|
|
|
|
+ model_id: 12,
|
|
|
|
|
+ main_body_column_id: 74,
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ pageSize: 3,
|
|
|
|
|
+ })
|
|
|
|
|
+ return normalizeList(data, 1, 3).items.slice(0, 3).map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ meta: item.desc || item.region_text || '',
|
|
|
|
|
+ actionText: '查看详情',
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getHomeNews(): Promise<HomeNewsItem[]> {
|
|
|
|
|
+ // 查询宣传资讯模型的全部栏目,不按推荐标记筛选。
|
|
|
|
|
+ const column = HOME_CULTURE_COLUMNS.find(column => column.key === 'news')!
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getContentList', {
|
|
|
|
|
+ model_id: column.modelId,
|
|
|
|
|
+ main_body_column_id: column.columnId,
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ pageSize: 4,
|
|
|
|
|
+ })
|
|
|
|
|
+ return normalizeList(data, 1, 4).items.slice(0, 4).map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ image: normalizeMediaUrl(item.thumbnail || item.image),
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ subtitle: item.desc || '',
|
|
|
|
|
+ time: item.publish_at?.split(' ')[0] || '',
|
|
|
|
|
+ }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getNewsColumns(): Promise<NewsColumn[]> {
|
|
|
|
|
+ interface Column {
|
|
|
|
|
+ id: number | string
|
|
|
|
|
+ name: string
|
|
|
|
|
+ model_id: number | string
|
|
|
|
|
+ }
|
|
|
|
|
+ const data = await get<Column[]>(
|
|
|
|
|
+ 'content/main_body_column/getColumnList',
|
|
|
|
|
+ { model_id: 18, main_body_column_id: 0 },
|
|
|
|
|
+ )
|
|
|
|
|
+ return data.map(item => ({ id: String(item.id), name: item.name, modelId: Number(item.model_id) }))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getNewsList(column: NewsColumn, keyword = '', page = 1, pageSize = 20) {
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getContentList', {
|
|
|
|
|
+ model_id: column.modelId,
|
|
|
|
|
+ main_body_column_id: column.id,
|
|
|
|
|
+ keywords: keyword.trim(),
|
|
|
|
|
+ page,
|
|
|
|
|
+ pageSize,
|
|
|
|
|
+ })
|
|
|
|
|
+ const { items, hasMore } = normalizeList(data, page, pageSize)
|
|
|
|
|
+ return {
|
|
|
|
|
+ items: items.map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ subtitle: item.desc || '',
|
|
|
|
|
+ time: item.publish_at?.split(' ')[0] || '',
|
|
|
|
|
+ })),
|
|
|
|
|
+ hasMore,
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getHomeCultureList(key: HomeCultureKey, keyword = '', page = 1, pageSize = 20) {
|
|
|
|
|
+ const column = HOME_CULTURE_COLUMNS.find(column => column.key === key)!
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getContentList', {
|
|
|
|
|
+ model_id: column.modelId,
|
|
|
|
|
+ main_body_column_id: column.columnId,
|
|
|
|
|
+ keywords: keyword.trim(),
|
|
|
|
|
+ page,
|
|
|
|
|
+ pageSize,
|
|
|
|
|
+ })
|
|
|
|
|
+ const { items, total, hasMore } = normalizeList(data, page, pageSize)
|
|
|
|
|
+ return {
|
|
|
|
|
+ items: items.map(item => ({
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ description: item.desc || '',
|
|
|
|
|
+ image: normalizeMediaUrl(item.thumbnail || item.image),
|
|
|
|
|
+ tag: item.column_name || '',
|
|
|
|
|
+ date: item.publish_at?.split(' ')[0] || '',
|
|
|
|
|
+ })),
|
|
|
|
|
+ total,
|
|
|
|
|
+ hasMore,
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function flattenCategories(items: ApiCategory[] = []): CategoryOption[] {
|
|
|
|
|
+ return items.flatMap((item) => {
|
|
|
|
|
+ if (item.status && item.status !== 'normal') {
|
|
|
|
|
+ return []
|
|
|
|
|
+ }
|
|
|
|
|
+ return [
|
|
|
|
|
+ { id: String(item.id), pid: String(item.pid), name: item.title.replace(/ |[\s├└│─]/g, '').trim() },
|
|
|
|
|
+ ...flattenCategories(item.children),
|
|
|
|
|
+ ]
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getInheritCategories() {
|
|
|
|
|
+ const data = await get<CategoryData>('content/category/getCategoryList', { is_tree: false })
|
|
|
|
|
+ const regions = flattenCategories(data.region_list)
|
|
|
|
|
+ const regionIds = new Set(regions.map(item => item.id))
|
|
|
|
|
+ return {
|
|
|
|
|
+ // 老文档将非遗门类放在 cr_type_list;只接受 pid=4,避免混入文物类型。
|
|
|
|
|
+ categories: flattenCategories(data.ich_type_list ?? data.cr_type_list?.filter(item => String(item.pid) === '4')),
|
|
|
|
|
+ levels: flattenCategories(data.level_list),
|
|
|
|
|
+ districts: regions.filter(item => !regionIds.has(item.pid)),
|
|
|
|
|
+ regions,
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function getColumn(column: typeof HERITAGE_COLUMNS[number], filters: InheritFilters, page = 1, pageSize = 4) {
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ model_id: column.modelId,
|
|
|
|
|
+ main_body_column_id: column.columnId,
|
|
|
|
|
+ page,
|
|
|
|
|
+ pageSize,
|
|
|
|
|
+ keywords: filters.keyword.trim(),
|
|
|
|
|
+ level: filters.levelId,
|
|
|
|
|
+ ich_type: filters.categoryId,
|
|
|
|
|
+ region: filters.districtId,
|
|
|
|
|
+ }
|
|
|
|
|
+ const data = await get<ContentListData>('content/content/getContentList', params)
|
|
|
|
|
+ return normalizeList(data, page, pageSize)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export function normalizeInheritItem(item: ApiContent, column: typeof HERITAGE_COLUMNS[number]): InheritItem {
|
|
|
|
|
+ const level = item.level_text || ''
|
|
|
|
|
+ const district = item.region_text || ''
|
|
|
|
|
+ const category = item.ich_type_text || ''
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: String(item.id),
|
|
|
|
|
+ name: item.title,
|
|
|
|
|
+ meta: [level, district, category].filter(Boolean).join(' · '),
|
|
|
|
|
+ desc: item.desc || item.ich_name || '',
|
|
|
|
|
+ image: normalizeMediaUrl(item.thumbnail || item.image),
|
|
|
|
|
+ icon: column.icon,
|
|
|
|
|
+ level,
|
|
|
|
|
+ district,
|
|
|
|
|
+ category,
|
|
|
|
|
+ regionId: item.region == null ? '' : String(item.region),
|
|
|
|
|
+ levelId: item.level == null ? '' : String(item.level),
|
|
|
|
|
+ categoryId: item.ich_type == null ? '' : String(item.ich_type),
|
|
|
|
|
+ page: item.page || '',
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getInheritList(key: HeritageKey, filters: InheritFilters, page = 1, pageSize = 20) {
|
|
|
|
|
+ const column = HERITAGE_COLUMNS.find(column => column.key === key)!
|
|
|
|
|
+ const result = await getColumn(column, filters, page, pageSize)
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...result,
|
|
|
|
|
+ items: result.items.map((item) => {
|
|
|
|
|
+ const normalized = normalizeInheritItem(item, column)
|
|
|
|
|
+ return { id: normalized.id, title: normalized.name, description: normalized.desc, image: normalized.image, tag: normalized.meta, date: item.publish_at?.split(' ')[0] || '' }
|
|
|
|
|
+ }),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export async function getInheritLists(filters: InheritFilters = { keyword: '', categoryId: '', levelId: '', districtId: '' }): Promise<InheritResult> {
|
|
|
|
|
+ const contents = await Promise.all(HERITAGE_COLUMNS.map(column => getColumn(column, filters)))
|
|
|
|
|
+ return {
|
|
|
|
|
+ lists: Object.fromEntries(HERITAGE_COLUMNS.map((column, index) => [
|
|
|
|
|
+ column.key,
|
|
|
|
|
+ contents[index].items.map(item => normalizeInheritItem(item, column)),
|
|
|
|
|
+ ])) as unknown as InheritLists,
|
|
|
|
|
+ totals: Object.fromEntries(HERITAGE_COLUMNS.map((column, index) => [column.key, contents[index].total])) as Record<HeritageKey, number>,
|
|
|
|
|
+ }
|
|
|
|
|
+}
|