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

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

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

145 lines
4.2 KiB
TypeScript

/**
* 检查数据库中的模板状态
*
* 只读操作,不会修改任何数据
*
* 使用方法:
* npx ts-node scripts/check-templates.ts
*/
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// 内置模板ID列表
const BUILTIN_TEMPLATE_IDS = [
'builtin-3dmax-material',
'builtin-psd-material',
'builtin-audio-material',
'builtin-video-material',
'builtin-model-material',
'builtin-other-material',
]
async function checkTemplates() {
console.log('=' .repeat(60))
console.log('数据库模板状态检查')
console.log('=' .repeat(60))
console.log()
try {
// 1. 检查所有模板
console.log('【1. 所有模板列表】')
const allTemplates = await prisma.uploadTemplate.findMany({
select: {
id: true,
name: true,
status: true,
materialType: true,
createdAt: true,
},
orderBy: { createdAt: 'asc' }
})
console.log(`总数: ${allTemplates.length} 个模板\n`)
if (allTemplates.length > 0) {
allTemplates.forEach((t, i) => {
const isBuiltin = t.id.startsWith('builtin-')
const tag = isBuiltin ? '[内置]' : '[自定义]'
console.log(` ${i + 1}. ${tag} ${t.id}`)
console.log(` 名称: ${t.name}`)
console.log(` 状态: ${t.status}`)
console.log(` 类型: ${t.materialType}`)
console.log()
})
} else {
console.log(' (无模板记录)\n')
}
// 2. 检查内置模板
console.log('【2. 内置模板检查】')
const existingBuiltinIds = new Set(
allTemplates.filter(t => t.id.startsWith('builtin-')).map(t => t.id)
)
console.log(`需要的内置模板: ${BUILTIN_TEMPLATE_IDS.length} 个`)
console.log(`已存在的内置模板: ${existingBuiltinIds.size} 个\n`)
BUILTIN_TEMPLATE_IDS.forEach(id => {
const exists = existingBuiltinIds.has(id)
const status = exists ? '✓ 存在' : '✗ 缺失'
console.log(` ${status} - ${id}`)
})
console.log()
// 3. 检查自定义模板
const customTemplates = allTemplates.filter(t => !t.id.startsWith('builtin-'))
console.log('【3. 自定义模板】')
console.log(`总数: ${customTemplates.length} 个\n`)
if (customTemplates.length > 0) {
customTemplates.forEach((t, i) => {
console.log(` ${i + 1}. ${t.name} (${t.id})`)
console.log(` 状态: ${t.status}, 类型: ${t.materialType}`)
})
} else {
console.log(' (无自定义模板)')
}
console.log()
// 4. 检查素材引用的模板
console.log('【4. 素材模板引用统计】')
const materialStats = await prisma.material.groupBy({
by: ['templateId'],
_count: { id: true },
where: { deletedAt: null }
})
console.log(`有 ${materialStats.length} 种不同的模板ID被素材引用\n`)
for (const stat of materialStats) {
const templateId = stat.templateId || '(无模板)'
const count = stat._count.id
// 检查模板是否存在
let status = ''
if (!stat.templateId) {
status = '⚠ 无模板ID'
} else if (existingBuiltinIds.has(stat.templateId)) {
status = '✓ 内置模板存在'
} else {
const exists = allTemplates.some(t => t.id === stat.templateId)
status = exists ? '✓ 自定义模板存在' : '✗ 模板不存在'
}
console.log(` ${templateId}: ${count} 个素材 - ${status}`)
}
console.log()
// 5. 总结
console.log('=' .repeat(60))
console.log('总结')
console.log('=' .repeat(60))
const missingBuiltin = BUILTIN_TEMPLATE_IDS.filter(id => !existingBuiltinIds.has(id))
if (missingBuiltin.length === 0) {
console.log('✓ 所有内置模板都已存在,无需修复')
} else {
console.log(`✗ 缺失 ${missingBuiltin.length} 个内置模板:`)
missingBuiltin.forEach(id => console.log(` - ${id}`))
console.log()
console.log('建议运行修复脚本: npx ts-node scripts/fix-missing-templates.ts')
}
} catch (error) {
console.error('检查失败:', error)
} finally {
await prisma.$disconnect()
}
}
// 执行检查
checkTemplates()