* 创建默认菜单项
()
| 376 | * 创建默认菜单项 |
| 377 | */ |
| 378 | async createDefaultMenuItems() { |
| 379 | try { |
| 380 | const menuCount = await this.get('SELECT COUNT(*) as count FROM menu_items'); |
| 381 | |
| 382 | if (menuCount.count === 0) { |
| 383 | const defaultMenuItems = [ |
| 384 | { text: '控制台', link: '/admin', new_tab: 0, sort_order: 1 }, |
| 385 | { text: '镜像搜索', link: '/', new_tab: 0, sort_order: 2 }, |
| 386 | { text: '文档', link: '/docs', new_tab: 0, sort_order: 3 }, |
| 387 | { text: 'GitHub', link: 'https://github.com/dqzboy/hubcmdui', new_tab: 1, sort_order: 4 } |
| 388 | ]; |
| 389 | |
| 390 | for (const item of defaultMenuItems) { |
| 391 | await this.run( |
| 392 | 'INSERT INTO menu_items (text, link, new_tab, sort_order, enabled, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)', |
| 393 | [item.text, item.link, item.new_tab, item.sort_order, 1, new Date().toISOString(), new Date().toISOString()] |
| 394 | ); |
| 395 | } |
| 396 | } |
| 397 | } catch (error) { |
| 398 | logger.error('创建默认菜单项失败:', error); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // 创建数据库实例 |
no test coverage detected