Files
competition-website/app/model/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

105 lines
2.5 KiB
JavaScript
Raw 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';
/**
* 轮播图模型 - Carousel
*
* 存储首页轮播图信息,支持标题、排序和启用/禁用控制。
* 表名:carousel
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE, TEXT } = app.Sequelize;
const Carousel = app.model.define('carousel', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '轮播图唯一标识',
},
// 图片 URL 地址(可为空时前端回退渐变背景)
image_url: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '图片 URL 地址(可为空回退渐变)',
},
// 轮播图标题
title: {
type: STRING(200),
allowNull: true,
comment: '轮播图标题',
},
// 富文本正文(HTML,由 wangEditor 生成,前端 v-html 渲染)
content: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '富文本正文(HTML)',
},
// 按钮文字(为空则不显示按钮)
button_text: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '按钮文字(为空则不显示按钮)',
},
// 按钮链接(内部路由如 /activate,或外部 http(s):// 链接)
button_link: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '按钮链接(内部路由/外部URL)',
},
// 排序序号(越小越靠前)
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序序号',
},
// 点击跳转链接
link_url: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '点击跳转链接',
},
// 是否启用
enabled: {
type: BOOLEAN,
allowNull: false,
defaultValue: true,
comment: '是否启用',
},
// 记录创建时间
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
// 记录更新时间
updated_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
tableName: 'carousel',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['sort_order'],
},
{
fields: ['enabled'],
},
],
});
return Carousel;
};