24cd9cef53
- uni-app Vue3 frontend with dark glassmorphism theme - 5 AI dimensions: Origin / Development / Current / Learning / Trend - AI Chat system prompt updated from geometry to AI - 23 AI knowledge articles initialized in DB - Trend API + cron job for daily news - Product pricing (Pro ¥19.9, VIP ¥39.9) - Pinia stores + API utilities - AGENTS.md documentation
219 lines
7.2 KiB
JavaScript
Executable File
219 lines
7.2 KiB
JavaScript
Executable File
require('dotenv').config({ path: require('path').resolve(__dirname, '../.env') })
|
|
const mongoose = require('mongoose')
|
|
const { Admin, ShopItem, Knowledge, Gallery } = require('../src/models')
|
|
|
|
/**
|
|
* 数据库初始化脚本
|
|
*/
|
|
async function initDatabase() {
|
|
try {
|
|
// 连接数据库
|
|
const mongoURI = process.env.MONGODB_URI
|
|
await mongoose.connect(mongoURI)
|
|
console.log('✅ 数据库连接成功')
|
|
|
|
// 1. 创建超级管理员
|
|
console.log('\n📋 创建超级管理员...')
|
|
const existingAdmin = await Admin.findOne({ username: 'admin' })
|
|
|
|
if (!existingAdmin) {
|
|
const admin = new Admin({
|
|
username: process.env.ADMIN_USERNAME || 'admin',
|
|
password: process.env.ADMIN_PASSWORD || 'admin123456',
|
|
email: process.env.ADMIN_EMAIL || 'admin@wdkj.com',
|
|
realName: '超级管理员',
|
|
role: 'super_admin',
|
|
permissions: ['*'],
|
|
status: 'active'
|
|
})
|
|
await admin.save()
|
|
console.log('✅ 超级管理员创建成功')
|
|
console.log(` 用户名: ${admin.username}`)
|
|
console.log(` 密码: ${process.env.ADMIN_PASSWORD || 'admin123456'}`)
|
|
} else {
|
|
console.log('⚠️ 管理员账户已存在')
|
|
}
|
|
|
|
// 2. 初始化商品
|
|
console.log('\n📋 初始化商品...')
|
|
const products = [
|
|
{
|
|
itemId: 'skin_quantum',
|
|
name: '量子线皮肤',
|
|
description: '一维世界专属皮肤,让你的线条闪耀量子光芒',
|
|
price: 6,
|
|
type: 'skin',
|
|
status: 'active',
|
|
sortOrder: 1
|
|
},
|
|
{
|
|
itemId: 'skin_hologram',
|
|
name: '全息面皮肤',
|
|
description: '二维世界专属皮肤,让你的图形绽放全息色彩',
|
|
price: 18,
|
|
type: 'skin',
|
|
status: 'active',
|
|
sortOrder: 2
|
|
},
|
|
{
|
|
itemId: 'skin_nebula',
|
|
name: '星云体皮肤',
|
|
description: '三维世界专属皮肤,让你的立方体流光溢彩',
|
|
price: 30,
|
|
type: 'skin',
|
|
status: 'active',
|
|
sortOrder: 3
|
|
},
|
|
{
|
|
itemId: 'no_ads',
|
|
name: '永久去广告',
|
|
description: '一键去除所有广告,享受纯净的维度探索之旅。',
|
|
price: 1200,
|
|
type: 'ad_free',
|
|
status: 'active',
|
|
sortOrder: 4
|
|
},
|
|
{
|
|
itemId: 'monthly_sub',
|
|
name: '星云月卡',
|
|
description: '尊享月度特权:全皮肤免费用、得分翻倍、专属身份标识。',
|
|
price: 1800,
|
|
type: 'vip',
|
|
duration: 30,
|
|
status: 'active',
|
|
sortOrder: 5
|
|
}
|
|
]
|
|
|
|
for (const product of products) {
|
|
const existing = await ShopItem.findOne({ itemId: product.itemId })
|
|
if (!existing) {
|
|
await ShopItem.create(product)
|
|
console.log(` ✅ ${product.name} 创建成功`)
|
|
} else {
|
|
console.log(` ⚠️ ${product.name} 已存在`)
|
|
}
|
|
}
|
|
|
|
// 3. 初始化知识库示例
|
|
console.log('\n📋 初始化知识库示例...')
|
|
const knowledgeList = [
|
|
{
|
|
title: '什么是维度?',
|
|
content: '维度是描述空间独立方向的参数。零维是点,一维是线,二维是面,三维是体。',
|
|
dim: 1,
|
|
category: 'concept',
|
|
tags: ['基础概念', '维度'],
|
|
status: 'approved',
|
|
sortOrder: 1
|
|
},
|
|
{
|
|
title: '一维世界:线的宇宙',
|
|
content: '一维世界只有长度这一个维度,就像一条无限延伸的直线。生活在一维世界的生物只能前进或后退。',
|
|
dim: 1,
|
|
category: 'concept',
|
|
tags: ['一维', '线'],
|
|
status: 'approved',
|
|
sortOrder: 2
|
|
},
|
|
{
|
|
title: '二维世界:平面王国',
|
|
content: '二维世界有长度和宽度两个维度,就像一张无限大的纸。平面国中的生物可以在平面上自由移动。',
|
|
dim: 2,
|
|
category: 'concept',
|
|
tags: ['二维', '平面'],
|
|
status: 'approved',
|
|
sortOrder: 1
|
|
},
|
|
{
|
|
title: '三维世界:立体空间',
|
|
content: '三维世界有长度、宽度和高度三个维度,这正是我们生活的世界。我们可以前后、左右、上下移动。',
|
|
dim: 3,
|
|
category: 'concept',
|
|
tags: ['三维', '立体'],
|
|
status: 'approved',
|
|
sortOrder: 1
|
|
}
|
|
]
|
|
|
|
for (const knowledge of knowledgeList) {
|
|
const existing = await Knowledge.findOne({ title: knowledge.title })
|
|
if (!existing) {
|
|
await Knowledge.create(knowledge)
|
|
console.log(` ✅ ${knowledge.title} 创建成功`)
|
|
} else {
|
|
console.log(` ⚠️ ${knowledge.title} 已存在`)
|
|
}
|
|
}
|
|
|
|
// 4. 初始化画廊示例作品
|
|
console.log('\n📋 初始化画廊示例作品...')
|
|
const galleryWorks = [
|
|
{
|
|
title: '一维·星点轨迹',
|
|
description: '在一维世界中,点动成线。这是我探索宇宙起点的轨迹记录。',
|
|
imageData: '/static/images/gallery_demo_dim1.png',
|
|
dim: 1,
|
|
openid: 'system_admin',
|
|
authorName: '系统管理员',
|
|
authorAvatar: '/static/images/default_avatar.png',
|
|
likeCount: 128,
|
|
tags: ['一维', '轨迹', '起点'],
|
|
status: 'approved',
|
|
createdAt: new Date()
|
|
},
|
|
{
|
|
title: '二维·星座图腾',
|
|
description: '连接星体,绘制出属于我的平面王国图腾。',
|
|
imageData: '/static/images/gallery_demo_dim2.png',
|
|
dim: 2,
|
|
openid: 'system_admin',
|
|
authorName: '星辰旅者',
|
|
authorAvatar: '/static/images/default_avatar.png',
|
|
likeCount: 96,
|
|
tags: ['二维', '星座', '图腾'],
|
|
status: 'approved',
|
|
createdAt: new Date()
|
|
},
|
|
{
|
|
title: '三维·流光立方',
|
|
description: '旋转的立方体展现了立体几何的魅力,色彩在空间中流动。',
|
|
imageData: '/static/images/gallery_demo_dim3.png',
|
|
dim: 3,
|
|
openid: 'system_admin',
|
|
authorName: '维度探索者',
|
|
authorAvatar: '/static/images/default_avatar.png',
|
|
likeCount: 215,
|
|
tags: ['三维', '立方体', '流光'],
|
|
status: 'approved',
|
|
createdAt: new Date()
|
|
}
|
|
]
|
|
|
|
for (const work of galleryWorks) {
|
|
const existing = await Gallery.findOne({ title: work.title })
|
|
if (!existing) {
|
|
await Gallery.create(work)
|
|
console.log(` ✅ ${work.title} 创建成功`)
|
|
} else {
|
|
console.log(` ⚠️ ${work.title} 已存在`)
|
|
}
|
|
}
|
|
|
|
console.log('\n✅ 数据库初始化完成!')
|
|
console.log('\n📝 管理员登录信息:')
|
|
console.log(` 用户名: ${process.env.ADMIN_USERNAME || 'admin'}`)
|
|
console.log(` 密码: ${process.env.ADMIN_PASSWORD || 'admin123456'}`)
|
|
|
|
} catch (error) {
|
|
console.error('❌ 初始化失败:', error)
|
|
} finally {
|
|
await mongoose.connection.close()
|
|
console.log('\n🔌 数据库连接已关闭')
|
|
process.exit(0)
|
|
}
|
|
}
|
|
|
|
// 执行初始化
|
|
initDatabase()
|