fix: tree & guide
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Database\Seeders;
|
||||
|
||||
use App\Models\Guide;
|
||||
use App\Models\GuidePage;
|
||||
use App\Models\GuidePageEdge;
|
||||
use App\Models\Station;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
@@ -41,6 +42,7 @@ class GuideSeeder extends Seeder
|
||||
$this->command->info('操作指引数据创建完成!');
|
||||
$this->command->info(' - 指引数量: ' . Guide::count());
|
||||
$this->command->info(' - 指引页面数量: ' . GuidePage::count());
|
||||
$this->command->info(' - 指引边数量: ' . GuidePageEdge::count());
|
||||
$this->command->info(' - 关联线站数量: ' . $stations->count());
|
||||
}
|
||||
|
||||
@@ -60,77 +62,110 @@ class GuideSeeder extends Seeder
|
||||
|
||||
$baseUrl = self::BASE_URL . '/how-to-use-beam';
|
||||
|
||||
// 步骤1: 打开光子光闸 PS1(根节点)
|
||||
$step1 = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 1,
|
||||
'title' => '打开光子光闸 PS1',
|
||||
'html_url' => "{$baseUrl}/step-1.html",
|
||||
'parent_id' => -1,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
|
||||
// 步骤2: 搜索光学棚屋(带选项:前门12 / 后门)
|
||||
$step2 = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 2,
|
||||
'title' => '搜索光学棚屋',
|
||||
'html_url' => "{$baseUrl}/step-2.html",
|
||||
'parent_id' => $step1->id,
|
||||
'sort_order' => 1,
|
||||
'options' => ['前门12', '后门'],
|
||||
]);
|
||||
|
||||
// 步骤3a: 前门12路径 - 检查设备状态
|
||||
$step3a = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 3,
|
||||
'title' => '前门12路径 - 检查设备状态',
|
||||
'html_url' => "{$baseUrl}/step-3a.html",
|
||||
'parent_id' => $step2->id,
|
||||
'sort_order' => 0,
|
||||
'branch_option' => '前门12',
|
||||
]);
|
||||
|
||||
// 步骤3b: 后门路径 - 安全确认
|
||||
$step3b = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 3,
|
||||
'title' => '后门路径 - 安全确认',
|
||||
'html_url' => "{$baseUrl}/step-3b.html",
|
||||
'parent_id' => $step2->id,
|
||||
'sort_order' => 1,
|
||||
'branch_option' => '后门',
|
||||
]);
|
||||
|
||||
// 步骤4a: 前门12路径 - 打开实验站光闸
|
||||
GuidePage::create([
|
||||
$step4a = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 4,
|
||||
'title' => '前门12路径 - 打开实验站光闸',
|
||||
'html_url' => "{$baseUrl}/step-4a.html",
|
||||
'parent_id' => $step3a->id,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
|
||||
// 步骤4b: 后门路径 - 设备检查
|
||||
GuidePage::create([
|
||||
$step4b = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 4,
|
||||
'title' => '后门路径 - 设备检查',
|
||||
'html_url' => "{$baseUrl}/step-4b.html",
|
||||
'parent_id' => $step3b->id,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
|
||||
// 步骤5: 完成(根节点,最终汇合)
|
||||
GuidePage::create([
|
||||
$step5 = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => 5,
|
||||
'title' => '完成',
|
||||
'html_url' => "{$baseUrl}/step-5.html",
|
||||
'parent_id' => -1,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
// step1 → step2 (sequential)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step1->id,
|
||||
'to_page_id' => $step2->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
// step2 → step3a (branching option: 前门12)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step2->id,
|
||||
'to_page_id' => $step3a->id,
|
||||
'label' => '前门12',
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
// step2 → step3b (branching option: 后门)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step2->id,
|
||||
'to_page_id' => $step3b->id,
|
||||
'label' => '后门',
|
||||
'sort' => 1,
|
||||
]);
|
||||
|
||||
// step3a → step4a (sequential)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step3a->id,
|
||||
'to_page_id' => $step4a->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
// step3b → step4b (sequential)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step3b->id,
|
||||
'to_page_id' => $step4b->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
// step4a → step5 (convergence)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step4a->id,
|
||||
'to_page_id' => $step5->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
// step4b → step5 (convergence)
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $step4b->id,
|
||||
'to_page_id' => $step5->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
|
||||
return $guide;
|
||||
@@ -159,17 +194,24 @@ class GuideSeeder extends Seeder
|
||||
['title' => '联系维护人员', 'file' => 'step-5.html'],
|
||||
];
|
||||
|
||||
$parentId = -1;
|
||||
$pages = [];
|
||||
foreach ($steps as $i => $step) {
|
||||
$page = GuidePage::create([
|
||||
$pages[] = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => $i + 1,
|
||||
'title' => $step['title'],
|
||||
'html_url' => "{$baseUrl}/{$step['file']}",
|
||||
'parent_id' => $parentId,
|
||||
'sort_order' => $parentId === -1 ? $i : 0,
|
||||
]);
|
||||
$parentId = $page->id;
|
||||
}
|
||||
|
||||
// Sequential edges: A→B→C→D→E
|
||||
for ($i = 0; $i < count($pages) - 1; $i++) {
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $pages[$i]->id,
|
||||
'to_page_id' => $pages[$i + 1]->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
return $guide;
|
||||
@@ -198,17 +240,24 @@ class GuideSeeder extends Seeder
|
||||
['title' => '完成', 'file' => 'step-5.html'],
|
||||
];
|
||||
|
||||
$parentId = -1;
|
||||
$pages = [];
|
||||
foreach ($steps as $i => $step) {
|
||||
$page = GuidePage::create([
|
||||
$pages[] = GuidePage::create([
|
||||
'guide_id' => $guide->id,
|
||||
'page_number' => $i + 1,
|
||||
'title' => $step['title'],
|
||||
'html_url' => "{$baseUrl}/{$step['file']}",
|
||||
'parent_id' => $parentId,
|
||||
'sort_order' => $parentId === -1 ? $i : 0,
|
||||
]);
|
||||
$parentId = $page->id;
|
||||
}
|
||||
|
||||
// Sequential edges: A→B→C→D→E
|
||||
for ($i = 0; $i < count($pages) - 1; $i++) {
|
||||
GuidePageEdge::create([
|
||||
'guide_id' => $guide->id,
|
||||
'from_page_id' => $pages[$i]->id,
|
||||
'to_page_id' => $pages[$i + 1]->id,
|
||||
'label' => null,
|
||||
'sort' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
return $guide;
|
||||
|
||||
Reference in New Issue
Block a user