Files
akmon/UNIFIED_CONTENT_SYSTEM_GUIDE.md
2026-01-20 08:04:15 +08:00

311 lines
7.4 KiB
Markdown
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.
# 统一内容系统使用指南
## 概述
现在 `comindex.uvue` 页面已经改用统一的 `ak_contents` 表来管理业务项目,不再需要单独的 `ak_business_items` 表。这样做的好处包括:
1. **统一管理**: 所有内容(文章、业务项目、产品等)使用同一套表结构
2. **多语言支持**: 利用现有的多语言翻译系统
3. **功能复用**: 共享评论、收藏、分享等功能
4. **维护简化**: 减少重复的表结构和逻辑
## 表结构说明
### ak_contents 表
业务项目作为一种特殊的内容类型存储在 `ak_contents` 表中:
```sql
-- 关键字段说明
content_type = 'business_item' -- 标识为业务项目
title -- 业务项目标题
content_summary -- 业务项目描述
featured_image_url -- 业务项目图片
category_id -- 分类ID关联到业务分类
original_language -- 原始语言
status = 'published' -- 发布状态
view_count -- 浏览次数
published_at -- 发布时间
tags -- 标签数组
```
## 数据获取逻辑
### 1. 查询优化
使用连接查询获取分类信息,避免多次查询:
```typescript
const result = await supa
.from('ak_contents')
.select(`
id,
title,
content_summary,
featured_image_url,
published_at,
view_count,
status,
tags,
ak_content_categories!inner(name_key)
`)
.eq('status', 'published')
.eq('content_type', 'business_item')
.eq('original_language', currentLanguageCode.value)
.order('published_at', { ascending: false })
```
### 2. 多语言支持
根据用户选择的语言自动筛选对应语言的业务项目:
- `original_language = 'zh-CN'` - 简体中文
- `original_language = 'en'` - 英文
- `original_language = 'zh-TW'` - 繁体中文
- `original_language = 'ja'` - 日文
### 3. 数据转换
`ak_contents` 的字段映射到 `BusinessItem` 类型:
```typescript
const businessItem: BusinessItem = {
id: item.id,
title: item.title,
description: item.content_summary,
imageUrl: item.featured_image_url,
categoryName: item.ak_content_categories?.name_key,
publishTime: new Date(item.published_at).toLocaleDateString(),
viewCount: item.view_count,
loading: false
}
```
## 部署步骤
### 1. 运行初始化脚本
```bash
# 运行业务项目初始化脚本
psql -d your_database -f init_business_items.sql
```
### 2. 验证数据
```sql
-- 查看业务项目
SELECT * FROM public.vw_business_items;
-- 检查分类
SELECT * FROM public.ak_content_categories
WHERE name_key LIKE 'business.%';
-- 验证内容类型
SELECT content_type, COUNT(*)
FROM public.ak_contents
GROUP BY content_type;
```
### 3. 测试功能
- 访问公司首页,查看业务项目展示
- 切换语言,验证多语言业务项目
- 点击业务项目,测试详情页导航
## 内容管理
### 1. 添加新业务项目
```sql
INSERT INTO public.ak_contents (
title,
content_summary,
content_type,
category_id,
original_language,
status,
featured_image_url,
tags
) VALUES (
'新业务项目',
'项目描述...',
'business_item',
(SELECT id FROM ak_content_categories WHERE name_key = 'business.ai'),
'zh-CN',
'published',
'https://example.com/image.jpg',
ARRAY['标签1', '标签2']
);
```
### 2. 添加多语言版本
```sql
-- 先插入英文版本
INSERT INTO public.ak_contents (
title,
content_summary,
content_type,
category_id,
original_language,
status
) VALUES (
'AI Solutions',
'Comprehensive AI technology support...',
'business_item',
(SELECT id FROM ak_content_categories WHERE name_key = 'business.ai'),
'en',
'published'
);
```
### 3. 管理业务分类
```sql
-- 添加新的业务分类
INSERT INTO public.ak_content_categories (
name_key,
level,
ai_keywords,
sort_order
) VALUES (
'business.cybersecurity',
0,
ARRAY['网络安全', 'cybersecurity', '信息安全'],
9
);
```
## 页面路由更新
### 详情页导航
现在业务项目详情使用通用的内容详情页:
```typescript
// 旧的路由
url: `/pages/business/detail?id=${item.id}`
// 新的路由
url: `/pages/content/detail?id=${item.id}&type=business_item`
```
### 建议的页面结构
```
pages/
content/
detail.uvue -- 统一的内容详情页
list.uvue -- 内容列表页
info/
comindex.uvue -- 公司首页(业务项目展示)
index.uvue -- 信息首页
```
## 性能优化
### 1. 索引优化
确保以下索引存在:
```sql
CREATE INDEX IF NOT EXISTS idx_ak_contents_content_type ON ak_contents(content_type);
CREATE INDEX IF NOT EXISTS idx_ak_contents_language ON ak_contents(original_language);
CREATE INDEX IF NOT EXISTS idx_ak_contents_status ON ak_contents(status);
CREATE INDEX IF NOT EXISTS idx_ak_contents_published ON ak_contents(published_at DESC);
```
### 2. 查询优化
- 使用连接查询减少数据库请求次数
- 按语言筛选减少数据传输量
- 分页加载避免一次性加载过多数据
### 3. 缓存策略
- 分类数据可以缓存,减少重复查询
- 公司配置信息可以缓存到本地存储
- 热门业务项目可以预加载
## 扩展功能
基于统一的内容系统,可以轻松扩展以下功能:
### 1. 内容翻译
利用现有的 `ak_content_translations` 表:
```sql
-- 为业务项目添加翻译
INSERT INTO public.ak_content_translations (
content_id,
language_id,
translated_title,
translated_content,
translation_method
) VALUES (
'business-item-id',
'language-id',
'Translated Title',
'Translated Content',
'human'
);
```
### 2. 业务项目评论
使用 `ak_comments` 表:
```sql
-- 为业务项目添加评论
INSERT INTO public.ak_comments (
target_type,
target_id,
author_id,
content
) VALUES (
'content',
'business-item-id',
'user-id',
'这个业务解决方案很棒!'
);
```
### 3. 业务项目收藏
使用 `ak_content_favorites` 表:
```sql
-- 收藏业务项目
INSERT INTO public.ak_content_favorites (
user_id,
target_type,
target_id
) VALUES (
'user-id',
'content',
'business-item-id'
);
```
## 迁移指南
### 从 ak_business_items 迁移
如果之前使用过独立的业务项目表,可以这样迁移:
```sql
-- 迁移数据
INSERT INTO public.ak_contents (
title,
content_summary,
content_type,
featured_image_url,
view_count,
status,
original_language,
published_at
)
SELECT
title,
description,
'business_item',
image_url,
view_count,
'published',
'zh-CN',
created_at
FROM old_ak_business_items
WHERE status = 'active';
-- 删除旧表(谨慎操作)
-- DROP TABLE IF EXISTS old_ak_business_items;
```
## 总结
通过使用统一的 `ak_contents` 表来管理业务项目,我们实现了:
1.**数据结构统一**: 所有内容使用相同的表结构
2.**多语言支持**: 自动根据用户语言筛选内容
3.**功能集成**: 共享评论、收藏、分享等功能
4.**维护简化**: 减少重复代码和表结构
5.**扩展性强**: 易于添加新的内容类型和功能
这种设计模式可以应用到其他内容类型(如产品介绍、案例研究等),形成统一的内容管理系统。