65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { createRequest } from '@/utils/request'
|
|
import type { ResponseStructure } from '@/utils/request'
|
|
|
|
// ==================== 类型定义 ====================
|
|
|
|
/** 图片资源 */
|
|
export interface ApiImage {
|
|
preview_url: string
|
|
file_name: string
|
|
id: number
|
|
}
|
|
|
|
/** 首页可点击链接项(轮播图 / 宫格导航共用) */
|
|
export interface HomeLinkItem {
|
|
id: number
|
|
title: string
|
|
image: ApiImage
|
|
link: string
|
|
status: number // 0: 启用
|
|
sort: number
|
|
link_type: number // 0: 跳转 link 链接; 1: 跳转分类页
|
|
category_id: number // link_type = 1 时携带的分类 ID
|
|
}
|
|
|
|
/** 首页活动项(结构与 HomeLinkItem 相同,额外多一个描述字段) */
|
|
export interface HomeActivityItem extends HomeLinkItem {
|
|
description: string
|
|
}
|
|
|
|
/** 首页数据 */
|
|
export interface HomeData {
|
|
carousel: HomeLinkItem[]
|
|
gridNav: HomeLinkItem[]
|
|
activity: HomeActivityItem[]
|
|
site_title: string
|
|
}
|
|
|
|
/** 分类链接项(结构与 HomeLinkItem 相同,但不含 link_type / category_id,均为纯链接) */
|
|
export type CategoryLinkItem = Omit<HomeLinkItem, 'link_type' | 'category_id'> & {
|
|
tag: string[]
|
|
}
|
|
|
|
// ==================== API ====================
|
|
|
|
/**
|
|
* 获取首页数据(无需登录)
|
|
*/
|
|
export async function getHomeData(): Promise<ResponseStructure<HomeData>> {
|
|
return createRequest<HomeData>({
|
|
url: '/api/home',
|
|
method: 'GET',
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取指定分类下的链接列表(无需登录)
|
|
* @param categoryId - 分类 ID
|
|
*/
|
|
export async function getCategoryLinks(categoryId: number): Promise<ResponseStructure<CategoryLinkItem[]>> {
|
|
return createRequest<CategoryLinkItem[]>({
|
|
url: `/api/category/${categoryId}`,
|
|
method: 'GET',
|
|
})
|
|
}
|