- 新增 actionInbox 服务层(待办事项列表/线程查询) - consultation 服务扩展(会话详情/发送消息) - 多页面代码优化(profile/messages/health/article) - 新增 navigate 工具函数
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { api } from './request';
|
|
|
|
export interface Article {
|
|
id: string;
|
|
title: string;
|
|
summary?: string;
|
|
content?: string;
|
|
cover_image?: string;
|
|
category?: string;
|
|
category_id?: string;
|
|
category_name?: string;
|
|
tags?: { id: string; name: string }[];
|
|
published_at?: string;
|
|
author?: string;
|
|
view_count?: number;
|
|
status?: string;
|
|
}
|
|
|
|
export interface ArticleCategory {
|
|
id: string;
|
|
name: string;
|
|
parent_id?: string | null;
|
|
children?: ArticleCategory[];
|
|
}
|
|
|
|
/** 将后台返回的扁平分类数组构建为树形结构 */
|
|
export function buildCategoryTree(flat: ArticleCategory[]): ArticleCategory[] {
|
|
const map = new Map<string, ArticleCategory>();
|
|
const roots: ArticleCategory[] = [];
|
|
for (const c of flat) {
|
|
c.children = [];
|
|
map.set(c.id, c);
|
|
}
|
|
for (const c of flat) {
|
|
if (c.parent_id && map.has(c.parent_id)) {
|
|
map.get(c.parent_id)!.children!.push(c);
|
|
} else {
|
|
roots.push(c);
|
|
}
|
|
}
|
|
return roots;
|
|
}
|
|
|
|
export async function listArticles(params?: {
|
|
page?: number;
|
|
page_size?: number;
|
|
category_id?: string;
|
|
tag_id?: string;
|
|
keyword?: string;
|
|
}) {
|
|
return api.get<{ data: Article[]; total: number }>('/health/articles', {
|
|
page: params?.page ?? 1,
|
|
page_size: params?.page_size ?? 20,
|
|
status: 'published',
|
|
...params,
|
|
});
|
|
}
|
|
|
|
export async function getArticleDetail(id: string) {
|
|
return api.get<Article>(`/health/articles/${id}`);
|
|
}
|
|
|
|
/** 公开文章详情(无需认证) */
|
|
export async function getPublicArticleDetail(id: string) {
|
|
return api.get<Article>(`/public/articles/${id}`);
|
|
}
|
|
|
|
export async function listCategories() {
|
|
return api.get<ArticleCategory[]>('/health/article-categories');
|
|
}
|