fix: - 引导流程改为从左至右显示 - 添加复制指引功能 - 流程图节点去掉 URL 显示,缩小节点尺寸 - 连线添加箭头方向指示,缩短节点间距 - 重构 graphUpdated 事件监听,修复添加/编辑页面后不实时更新的问题 - 预览页面隐藏图片附件文件名
This commit is contained in:
@@ -193,6 +193,43 @@ class GuideResource extends Resource
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make()->label('编辑'),
|
||||
Tables\Actions\Action::make('duplicate')
|
||||
->label('复制')
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->color('info')
|
||||
->requiresConfirmation()
|
||||
->action(function (Guide $record) {
|
||||
$newGuide = $record->replicate(['pages_count', 'stations_count']);
|
||||
$newGuide->name = $record->name . ' (副本)';
|
||||
$newGuide->created_by = auth()->id();
|
||||
$newGuide->published_at = null;
|
||||
$newGuide->save();
|
||||
|
||||
// 复制关联的线站
|
||||
if ($record->stations()->count() > 0) {
|
||||
$newGuide->stations()->sync($record->stations()->pluck('stations.id'));
|
||||
}
|
||||
|
||||
// 复制页面
|
||||
$pageIdMap = [];
|
||||
foreach ($record->pages as $page) {
|
||||
$newPage = $page->replicate();
|
||||
$newPage->guide_id = $newGuide->id;
|
||||
$newPage->save();
|
||||
$pageIdMap[$page->id] = $newPage->id;
|
||||
}
|
||||
|
||||
// 复制边(edges),并更新页面 ID 映射
|
||||
foreach ($record->edges as $edge) {
|
||||
$newEdge = $edge->replicate();
|
||||
$newEdge->guide_id = $newGuide->id;
|
||||
$newEdge->from_page_id = $pageIdMap[$edge->from_page_id] ?? $edge->from_page_id;
|
||||
$newEdge->to_page_id = $pageIdMap[$edge->to_page_id] ?? $edge->to_page_id;
|
||||
$newEdge->save();
|
||||
}
|
||||
|
||||
return redirect()->to(route('filament.admin.resources.guides.edit', ['record' => $newGuide]));
|
||||
}),
|
||||
Tables\Actions\DeleteAction::make()->label('删除'),
|
||||
])
|
||||
->bulkActions([
|
||||
|
||||
@@ -91,20 +91,21 @@ class ManageGuidePages extends Page
|
||||
}
|
||||
ksort($levelGroups);
|
||||
|
||||
// Compute positions: center each level horizontally, stack vertically
|
||||
$nodeWidth = 240;
|
||||
$gapX = 40;
|
||||
$gapY = 150;
|
||||
// Compute positions: center each level vertically, stack horizontally (left-to-right)
|
||||
$nodeWidth = 180; // matches CSS max-width
|
||||
$nodeHeight = 80; // compact node height
|
||||
$gapX = 110; // horizontal gap between levels
|
||||
$gapY = 30; // vertical gap within same level
|
||||
$positions = [];
|
||||
|
||||
foreach ($levelGroups as $level => $ids) {
|
||||
$count = count($ids);
|
||||
$totalWidth = $count * $nodeWidth + ($count - 1) * $gapX;
|
||||
$startX = max(20, (800 - $totalWidth) / 2);
|
||||
$totalHeight = $count * $nodeHeight + ($count - 1) * $gapY;
|
||||
$startY = max(20, (600 - $totalHeight) / 2);
|
||||
foreach ($ids as $i => $id) {
|
||||
$positions[$id] = [
|
||||
'x' => (int) ($startX + $i * ($nodeWidth + $gapX)),
|
||||
'y' => 40 + $level * $gapY,
|
||||
'x' => 40 + $level * ($nodeWidth + $gapX),
|
||||
'y' => (int) ($startY + $i * ($nodeHeight + $gapY)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -129,6 +130,11 @@ class ManageGuidePages extends Page
|
||||
|
||||
// -- Livewire methods called by Drawflow events --
|
||||
|
||||
private function dispatchGraphUpdated(): void
|
||||
{
|
||||
$this->dispatch('graphUpdated', nodes: $this->nodes, edges: $this->edges);
|
||||
}
|
||||
|
||||
public function addEdge(int $fromPageId, int $toPageId, string $outputClass = 'output_1'): void
|
||||
{
|
||||
$guide = $this->getRecord();
|
||||
@@ -170,7 +176,7 @@ class ManageGuidePages extends Page
|
||||
]);
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
}
|
||||
|
||||
public function removeEdge(int $fromPageId, int $toPageId): void
|
||||
@@ -181,7 +187,7 @@ class ManageGuidePages extends Page
|
||||
->delete();
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
}
|
||||
|
||||
// -- Filament Actions --
|
||||
@@ -196,7 +202,7 @@ class ManageGuidePages extends Page
|
||||
$this->getRecord()->pages()->create($data);
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,7 +225,7 @@ class ManageGuidePages extends Page
|
||||
$page->update($data);
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -235,7 +241,7 @@ class ManageGuidePages extends Page
|
||||
$page->delete();
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -251,7 +257,7 @@ class ManageGuidePages extends Page
|
||||
$edge->delete();
|
||||
|
||||
$this->loadGraph();
|
||||
$this->dispatch('graphUpdated');
|
||||
$this->dispatchGraphUpdated();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user