本项目新增了移动端字体大小设置功能,允许用户选择四种字体大小:小(0)、中(1)、大(2)、超大(3)。
UserPreferenceuser_preferencesid: 主键IDuser_id: 关联用户ID(唯一索引)font_size: 字体大小设置(0-3)is_dark_mode: 深色模式开关(0/1)created_at, updated_at: 时间戳created_by, updated_by: 操作人IDGET /api/v1/user-preferences?filters={"userId":1}
POST /api/v1/user-preferences
{
"userId": 1,
"fontSize": 1,
"isDarkMode": 0
}
PUT /api/v1/user-preferences/{id}
{
"fontSize": 2
}
enum FontSizeType {
SMALL = 0, // 14px
MEDIUM = 1, // 16px (默认)
LARGE = 2, // 18px
EXTRA_LARGE = 3 // 20px
}
import { userPreferenceClient } from '@/client/api';
import { FontSizeType } from '@/server/modules/silver-users/user-preference.entity';
// 获取用户偏好设置
const response = await userPreferenceClient.$get({
query: { filters: JSON.stringify({ userId: userId }) }
});
// 创建偏好设置
await userPreferenceClient.$post({
json: {
userId: user.id,
fontSize: FontSizeType.LARGE,
isDarkMode: 0
}
});
// 更新偏好设置
await (userPreferenceClient as any)[preferenceId].$put({
json: { fontSize: FontSizeType.LARGE }
});
在ProfilePage.tsx中已经集成了字体大小设置功能:
--mobile-font-size控制全局字体大小| 枚举值 | 名称 | 实际大小 | 适用场景 |
|---|---|---|---|
| 0 | 小 | 14px | 视力良好用户 |
| 1 | 中 | 16px | 默认大小 |
| 2 | 大 | 18px | 一般视力需求 |
| 3 | 超大 | 20px | 视力不佳用户 |
# 运行数据库迁移
npm run db:migrate
# 或使用TypeORM同步
npm run dev
# 测试获取偏好设置
curl -X GET "http://localhost:3000/api/v1/user-preferences?filters=%7B%22userId%22%3A1%7D" \
-H "Authorization: Bearer YOUR_TOKEN"
# 测试创建偏好设置
curl -X POST http://localhost:3000/api/v1/user-preferences \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"userId": 1, "fontSize": 2, "isDarkMode": 0}'
is_dark_mode字段,可扩展深色模式支持