'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; };