packServer/backend/database/migrations/20261107120000-create-doc-tables.js
liufumingren 78cee0fe1a feat(doc): 首页登录分流 + 文档站(简易 CMS / 静态 HTML / sitemap)
- 首页:`/` 未登录原地显示登录页(不再跳 /login),已登录直接进 `/dashboard`;
  看板路由由 `/` 迁到 `/dashboard`,侧边栏「首页」与无权限回跳同步;
  桌面端「工具 → 打开配置页」的 `/?token=` 免登录仍然可用
- 文档站:`/doc/**` 由后端整站生成静态 HTML(顶部分类 tab 全局切换、左侧栏目 → 内容页、
  右侧本页目录);`/sitemap.txt` 新链接追加到末尾,下架 / 删除的会被清理
- 平台管理 · 文档管理(`/admin/doc`):分类 / 栏目 / 内容页(Markdown)简易 CMS,
  内容页有编辑表单与列表,保存后自动重生成目录与静态页面
- 登录页右下角、顶栏(登录后)、看板右上角新增进入文档站的链接
- 部署:nginx 模板为 `/doc`、`/doc/`、`/sitemap.txt` 增加反代(否则会落到 SPA 回退);
  Vite dev server 增加同名代理;`middleware/frontend.js` 排除这些路径
- 登录页插画改为内联 SVG(沿用工作区已有的未提交改动)
- 测试:新增 Markdown 渲染单测;后端 218 个用例通过,前端 typecheck / build 通过

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 20:33:46 +08:00

128 lines
6.4 KiB
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';
/**
* 文档站(简易 CMS):doc_categories / doc_sections / doc_articles
*
* 层级:分类(顶部 tab)→ 栏目(侧边栏分组)→ 内容页(Markdown)。
* 内容保存后由 `service/docSite` 渲染成 `/doc/**` 下的**静态 HTML**,并维护 `/sitemap.txt`。
*
* 迁移里先放一页「欢迎使用」,保证文档站一上线就有内容(也方便部署后自测)。
*/
module.exports = {
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, TINYINT, INTEGER, TEXT, DATE } = Sequelize;
await queryInterface.createTable('doc_categories', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false },
code: { type: STRING(32), allowNull: false, unique: true, comment: 'URL 片段(/doc/<code>/)' },
name: { type: STRING(64), allowNull: false, comment: '分类名称(tab 文案)' },
description: { type: STRING(255), allowNull: true, comment: '分类说明(可选)' },
sort: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '排序(小的在前)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1 展示 0 隐藏' },
created_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
updated_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
deleted_at: { type: DATE, allowNull: true },
}, { comment: '文档分类表' });
await queryInterface.addIndex('doc_categories', [ 'status', 'sort' ], { name: 'idx_doc_categories_status_sort' });
await queryInterface.createTable('doc_sections', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false },
category_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属分类 doc_categories.id' },
name: { type: STRING(64), allowNull: false, comment: '栏目名称(侧边栏分组标题)' },
sort: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '排序(小的在前)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1 展示 0 隐藏' },
created_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
updated_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
deleted_at: { type: DATE, allowNull: true },
}, { comment: '文档栏目表' });
await queryInterface.addIndex('doc_sections', [ 'category_id', 'sort' ], { name: 'idx_doc_sections_category_sort' });
await queryInterface.createTable('doc_articles', {
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false },
category_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属分类(冗余,列表用)' },
section_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属栏目 doc_sections.id' },
title: { type: STRING(128), allowNull: false, comment: '标题' },
slug: { type: STRING(64), allowNull: false, comment: 'URL 片段' },
summary: { type: STRING(255), allowNull: true, comment: '摘要' },
content: { type: TEXT('medium'), allowNull: true, comment: '正文(Markdown)' },
sort: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '栏目内排序(小的在前)' },
status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1 发布 0 草稿' },
created_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
updated_at: { type: DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') },
deleted_at: { type: DATE, allowNull: true },
}, { comment: '文档内容页表' });
await queryInterface.addIndex('doc_articles', [ 'category_id', 'section_id', 'sort' ], { name: 'idx_doc_articles_tree' });
await queryInterface.addIndex('doc_articles', [ 'category_id', 'slug' ], { name: 'idx_doc_articles_slug' });
const now = new Date();
await queryInterface.bulkInsert('doc_categories', [{
code: 'guide',
name: '使用指南',
description: '从创建主体到看板查看,一步步把系统跑起来',
sort: 10,
status: 1,
created_at: now,
updated_at: now,
}]);
const [ categories ] = await queryInterface.sequelize.query(
'SELECT id FROM doc_categories WHERE code = ? LIMIT 1',
{ replacements: [ 'guide' ] },
);
const categoryId = categories && categories[0] ? categories[0].id : null;
if (!categoryId) return;
await queryInterface.bulkInsert('doc_sections', [{
category_id: categoryId,
name: '快速开始',
sort: 10,
status: 1,
created_at: now,
updated_at: now,
}]);
const [ sections ] = await queryInterface.sequelize.query(
'SELECT id FROM doc_sections WHERE category_id = ? ORDER BY id ASC LIMIT 1',
{ replacements: [ categoryId ] },
);
const sectionId = sections && sections[0] ? sections[0].id : null;
if (!sectionId) return;
await queryInterface.bulkInsert('doc_articles', [{
category_id: categoryId,
section_id: sectionId,
title: '欢迎使用云仓视频溯源',
slug: 'welcome',
summary: '文档站已经跑起来了,这里的内容都能在「平台管理 → 文档管理」里维护。',
content: [
'# 欢迎使用云仓视频溯源',
'',
'这里是由**平台管理 → 文档管理**维护的静态文档站:',
'',
'- 顶部 tab 是「分类」,点一下就能切换;',
'- 左侧是分类下的「栏目 → 内容页」;',
'- 文章保存后会自动重新生成 HTML 与目录,并把新链接追加到 `/sitemap.txt`。',
'',
'## 下一步',
'',
'1. 在「文档管理」里新建分类 / 栏目 / 内容页;',
'2. 回到本站刷新,就能看到刚发布的内容;',
'3. 需要撤下某篇时,把状态改成「草稿」即可(页面和 sitemap 都会移除)。',
].join('\n'),
sort: 10,
status: 1,
created_at: now,
updated_at: now,
}]);
},
async down(queryInterface) {
await queryInterface.dropTable('doc_articles');
await queryInterface.dropTable('doc_sections');
await queryInterface.dropTable('doc_categories');
},
};