furniture-3d-system-Wu/scripts/update-test-data.ts
WuYongJie ff41839238 feat: 实现Apple风格UI系统和产品上传功能
- 完整实现Apple HIG 2025设计系统
- 添加Modal弹窗组件(毛玻璃效果、流畅动画)
- 添加FileUpload文件上传组件(拖拽、批量上传、进度显示)
- 实现产品上传功能(支持DWG/GLB/GLTF文件)
- 优化产品列表展示(可折叠的产品+SKU结构)
- 实现Tab切换功能(3D模型管理、五金件、BOM、文档)
- 修复主题系统hydration错误
- 优化按钮和间距,符合Apple设计规范
- 添加分享页面的Apple风格重设计
- 创建测试数据脚本
2025-12-12 20:16:41 +08:00

138 lines
3.8 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.

/**
* 更新测试数据脚本
* 修复数据库中的测试产品数据,使其可以正常显示
*/
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
console.log('开始更新测试数据...')
// 获取所有产品
const products = await prisma.product.findMany({
include: {
skus: true,
assemblySteps: true,
shareLinks: true,
}
})
console.log(`找到 ${products.length} 个产品`)
// 更新每个产品
for (const product of products) {
console.log(`\n更新产品: ${product.modelNumber} - ${product.name}`)
// 确保产品有基本信息
await prisma.product.update({
where: { id: product.id },
data: {
description: product.description || `这是一款${product.name},采用现代设计理念,注重实用性和美观性的完美结合。`,
category: product.category || '家具',
thumbnailUrl: product.thumbnailUrl || '/placeholder-furniture.jpg',
}
})
// 如果产品没有 SKU,创建一个默认 SKU
if (product.skus.length === 0) {
console.log(' 创建默认 SKU...')
await prisma.productSKU.create({
data: {
productId: product.id,
skuCode: `${product.modelNumber}-DEFAULT`,
attributes: {
color: '原木色',
size: '标准尺寸',
material: '实木'
},
price: 2999.00,
costPrice: 1500.00,
stock: 100,
images: ['/placeholder-furniture.jpg'],
isActive: true,
}
})
} else {
// 更新现有 SKU
for (const sku of product.skus) {
console.log(` 更新 SKU: ${sku.skuCode}`)
await prisma.productSKU.update({
where: { id: sku.id },
data: {
images: sku.images.length > 0 ? sku.images : ['/placeholder-furniture.jpg'],
stock: sku.stock > 0 ? sku.stock : 50,
}
})
}
}
// 如果产品没有分享链接,创建一个
if (product.shareLinks.length === 0) {
console.log(' 创建分享链接...')
await prisma.shareLink.create({
data: {
productId: product.id,
token: `share-${product.modelNumber.toLowerCase()}-${Date.now()}`,
viewCount: Math.floor(Math.random() * 100),
}
})
}
// 如果产品没有装配步骤,创建一些示例步骤
if (product.assemblySteps.length === 0) {
console.log(' 创建示例装配步骤...')
const steps = [
{
order: 1,
title: '准备工作',
description: '检查所有配件是否齐全,准备好所需工具',
partIds: ['base'],
transform: { position: [0, 0, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
duration: 1000,
easing: 'ease-out',
},
{
order: 2,
title: '组装底座',
description: '将底座部件按照标记进行组装',
partIds: ['base', 'legs'],
transform: { position: [0, 0.5, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
duration: 1500,
easing: 'ease-in-out',
},
{
order: 3,
title: '安装主体',
description: '将主体部分固定到底座上',
partIds: ['main'],
transform: { position: [0, 1, 0], rotation: [0, 0, 0], scale: [1, 1, 1] },
duration: 2000,
easing: 'ease-out',
},
]
for (const step of steps) {
await prisma.assemblyStep.create({
data: {
productId: product.id,
...step,
}
})
}
}
}
console.log('\n✅ 测试数据更新完成!')
}
main()
.catch((e) => {
console.error('❌ 更新失败:', e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})