WuYongJie 63ec6b7dfb fix: 修复排行榜按钮消失、tag排序和输入框浅色模式问题
1. 排行榜悬浮窗关闭后小按钮消失问题
   - 修复面板居中模式关闭时按钮位置错误
   - 保存并恢复按钮的居中状态

2. 首页tag按钮按素材数量排序
   - 添加按素材数量降序排序逻辑

3. 上传弹窗输入框浅色模式文字不可见
   - 添加 text-slate-900 确保浅色模式下文字可见
   - 添加 placeholder 样式确保占位符正确显示
2025-12-14 21:41:29 +08:00

96 lines
3.1 KiB
TypeScript
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.

/**
* 模板列表 API
*
* 获取所有启用的模板列表(包括预制模板和自定义模板)
* 用于首页TAG筛选
*/
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
// 预制模板配置
const BUILTIN_TEMPLATE_KEYS = [
'3dmax-material',
'psd-material',
'audio-material',
'video-material',
'model-material',
'other-material',
]
const BUILTIN_TEMPLATE_NAMES: Record<string, string> = {
'3dmax-material': '3DMAX 素材模板',
'psd-material': 'PSD 素材模板',
'audio-material': '音频素材模板',
'video-material': '视频素材模板',
'model-material': '模特素材模板',
'other-material': '其他素材模板',
}
function createBuiltinTemplate(key: string) {
return {
id: `builtin-${key}`,
name: BUILTIN_TEMPLATE_NAMES[key] || key,
isBuiltin: true,
}
}
export async function GET() {
try {
// 获取启用的预制模板列表
let enabledBuiltinTemplates: string[] = []
const ALL_BUILTIN_KEYS = BUILTIN_TEMPLATE_KEYS // 所有预制模板key
try {
// 使用原始 SQL 查询,避免字段不存在时的错误
const settings = await prisma.$queryRaw<Array<{ enabledBuiltinTemplates?: string | null }>>`
SELECT "enabledBuiltinTemplates" FROM "system_settings" LIMIT 1
`
if (settings[0]?.enabledBuiltinTemplates) {
const parsed = JSON.parse(settings[0].enabledBuiltinTemplates)
if (Array.isArray(parsed) && parsed.length > 0) {
enabledBuiltinTemplates = parsed
}
// 如果为空数组或null,表示全部启用,enabledBuiltinTemplates保持为空数组
}
// 如果字段不存在或为null,表示全部启用,enabledBuiltinTemplates保持为空数组
} catch (error) {
// 字段不存在或解析失败,表示全部启用
console.error('Failed to parse enabledBuiltinTemplates:', error)
}
// 获取所有启用的自定义模板(排除内置模板,内置模板由代码生成)
const customTemplates = await prisma.uploadTemplate.findMany({
where: {
status: 'active',
// 排除内置模板(builtin-开头的模板由系统自动创建,不应重复显示)
NOT: {
id: { startsWith: 'builtin-' },
},
},
select: {
id: true,
name: true,
},
orderBy: { updatedAt: 'desc' },
})
// 生成所有预制模板,只包含启用的
// 如果 enabledBuiltinTemplates 为空数组,表示全部启用
const builtinTemplates = BUILTIN_TEMPLATE_KEYS
.filter(key => enabledBuiltinTemplates.length === 0 || enabledBuiltinTemplates.includes(key))
.map(key => createBuiltinTemplate(key))
// 合并预制模板和自定义模板,预制模板在前
const allTemplates = [
...builtinTemplates,
...customTemplates.map(t => ({ ...t, isBuiltin: false })),
]
return NextResponse.json(allTemplates)
} catch (error) {
console.error('Error fetching templates:', error)
return NextResponse.json({ error: '获取模板列表失败' }, { status: 500 })
}
}