备份:修复前完整项目快照 2026-04-19
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, 'company_finance.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('开始初始化用户数据...');
|
||||
|
||||
// 插入默认用户数据
|
||||
const users = [
|
||||
{
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
password: 'admin123',
|
||||
name: '系统管理员',
|
||||
role: 'admin',
|
||||
email: 'admin@example.com',
|
||||
phone: '13800138000',
|
||||
created_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: 'user',
|
||||
password: 'user123',
|
||||
name: '普通用户',
|
||||
role: 'user',
|
||||
email: 'user@example.com',
|
||||
phone: '13900139000',
|
||||
created_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
];
|
||||
|
||||
let completed = 0;
|
||||
|
||||
users.forEach(user => {
|
||||
db.run(
|
||||
`INSERT OR REPLACE INTO users (id, username, password, name, role, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[user.id, user.username, user.password, user.name, user.role, user.created_at, user.updated_at],
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error(`插入用户 ${user.username} 失败:`, err.message);
|
||||
} else {
|
||||
console.log(`✓ 成功插入用户 ${user.username}`);
|
||||
}
|
||||
|
||||
completed++;
|
||||
if (completed === users.length) {
|
||||
console.log('\n用户数据初始化完成!');
|
||||
|
||||
// 检查用户数据
|
||||
db.get('SELECT COUNT(*) as count FROM users', (err, row) => {
|
||||
if (err) {
|
||||
console.error('检查用户数据失败:', err.message);
|
||||
} else {
|
||||
console.log(`当前用户数量: ${row.count}`);
|
||||
}
|
||||
db.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user