|
@@ -10,17 +10,29 @@ export default defineEventHandler<EventHandlerRequest, Promise<IResponse<CommonP
|
|
|
const page = query.page as string;
|
|
const page = query.page as string;
|
|
|
const pageSize = query.pageSize as string;
|
|
const pageSize = query.pageSize as string;
|
|
|
const channelId = query.channelId as string;
|
|
const channelId = query.channelId as string;
|
|
|
|
|
+ const includeChilds = query.includeChilds === 'true';
|
|
|
if (!channelId)
|
|
if (!channelId)
|
|
|
return createErrorResponse('分类ID不能为空');
|
|
return createErrorResponse('分类ID不能为空');
|
|
|
- const articles = await DB.table('pr_cms_archives')
|
|
|
|
|
- .whereNull('deletetime')
|
|
|
|
|
- .where('channel_id', channelId)
|
|
|
|
|
- .where('status', 'normal')
|
|
|
|
|
- .orderBy('weigh', 'desc')
|
|
|
|
|
- .orderBy('publishtime', 'desc')
|
|
|
|
|
- .orderBy('createtime', 'desc')
|
|
|
|
|
- .orderBy('id', 'asc')
|
|
|
|
|
- .paginate(Number(page), Number(pageSize));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const dbquery = DB.table('pr_cms_archives')
|
|
|
|
|
+ .whereNull('deletetime')
|
|
|
|
|
+ .where('status', 'normal')
|
|
|
|
|
+ .orderBy('weigh', 'desc')
|
|
|
|
|
+ .orderBy('publishtime', 'desc')
|
|
|
|
|
+ .orderBy('createtime', 'desc')
|
|
|
|
|
+ .orderBy('id', 'asc');
|
|
|
|
|
+
|
|
|
|
|
+ if (includeChilds) {
|
|
|
|
|
+ const childChannels = await DB.table('pr_cms_channel')
|
|
|
|
|
+ .where('parent_id', channelId)
|
|
|
|
|
+ .select('id')
|
|
|
|
|
+ .get();
|
|
|
|
|
+ dbquery.whereIn('channel_id', [channelId, ...childChannels.map(item => item.id)]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dbquery.where('channel_id', channelId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const articles = await dbquery.paginate(Number(page), Number(pageSize));
|
|
|
if (!articles)
|
|
if (!articles)
|
|
|
return createErrorResponse('文章不存在');
|
|
return createErrorResponse('文章不存在');
|
|
|
return createSuccessResponse(articles);
|
|
return createSuccessResponse(articles);
|