新增文章模块封面图片功能,包括在数据传输对象、模型和服务中添加封面图片字段,并在推荐服务中更新文章卡片以显示封面图片。

This commit is contained in:
richarjiang
2025-08-14 16:03:27 +08:00
parent bc8a52852d
commit b4dfdcfe70
4 changed files with 15 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ export class ArticlesService {
title: dto.title,
publishedDate: dto.publishedDate as any,
htmlContent: dto.htmlContent,
coverImage: dto.coverImage,
});
return { code: ResponseCode.SUCCESS, message: 'success', data: article.toJSON() as ArticleVo };
}

View File

@@ -10,6 +10,9 @@ export class CreateArticleDto {
@ApiProperty({ description: 'HTML 富文本内容' })
htmlContent!: string;
@ApiProperty({ description: '封面图片' })
coverImage!: string;
}
export class QueryArticlesDto {
@@ -35,6 +38,7 @@ export interface ArticleVo {
publishedDate: string;
readCount: number;
htmlContent: string;
coverImage: string;
}
export type CreateArticleResponseDto = BaseResponseDto<ArticleVo>;

View File

@@ -19,6 +19,13 @@ export class Article extends Model {
})
declare title: string;
@Column({
type: DataType.TEXT,
allowNull: false,
comment: '封面图片',
})
declare coverImage: string;
@Column({
type: DataType.DATEONLY,
allowNull: false,

View File

@@ -14,11 +14,13 @@ export class RecommendationsService {
const limit = 10
// 取最新文章若干
const articlesRes = await this.articlesService.query({ page: 1, pageSize: limit } as any);
const articlesRes = await this.articlesService.query({ page: 1, pageSize: limit });
const articleCards: RecommendationCard[] = (articlesRes.data.list || []).map(a => ({
id: `article-${a.id}`,
type: RecommendationType.Article,
title: a.title,
coverUrl: a.coverImage,
html: a.htmlContent,
articleId: a.id,
extra: { publishedDate: a.publishedDate, readCount: a.readCount },
}));