Files
competition-website/app/controller/carousel.js
WorkBuddy a303cf2d53 chore: 后端首次基线提交
运行必须源码:app/(controller/model/service/middleware/lib/utils/validate/router)、config/、database/(migrations/seeders/sql)、启动脚本、app/public/templates 模板。
已忽略运行非必须:node_modules/、logs/、run/、app/public 运行时上传数据、.env*、构建/缓存产物。
2026-08-17 12:25:42 +08:00

35 lines
958 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const Controller = require('egg').Controller;
/**
* 轮播图控制器 - CarouselController
*
* 负责首页轮播图的查询和展示。
*
* 主要接口:
* - GET /api/carousel : 获取启用的轮播图列表(按 sort_order 升序排列)
*/
class CarouselController extends Controller {
/**
* 获取轮播图列表
*
* 查询条件:enabled = 1(仅返回启用状态的轮播图)
* 排序规则:sort_order ASC(序号越小越靠前)
*/
async index() {
const { ctx } = this;
const list = await ctx.model.Carousel.findAll({
where: { enabled: true },
order: [
['sort_order', 'ASC'],
],
attributes: ['id', 'image_url', 'title', 'content', 'button_text', 'button_link', 'sort_order', 'link_url', 'enabled', 'created_at', 'updated_at'],
});
ctx.body = ctx.helper.success(list, '获取轮播图列表成功');
}
}
module.exports = CarouselController;